fixed tenshi searching

This commit is contained in:
Blatzar 2021-12-19 14:26:42 +01:00
parent 607c9e9af5
commit e118938a41
3 changed files with 68 additions and 68 deletions

View file

@ -12,7 +12,7 @@ import org.jsoup.nodes.Document
import java.net.URI import java.net.URI
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import kotlin.concurrent.thread import kotlin.collections.ArrayList
class TenshiProvider : MainAPI() { class TenshiProvider : MainAPI() {
companion object { companion object {
@ -101,16 +101,12 @@ class TenshiProvider : MainAPI() {
return movies.contains(aniId) return movies.contains(aniId)
} }
private fun parseSearchPage(soup: Document): ArrayList<SearchResponse> { private fun parseSearchPage(soup: Document): List<SearchResponse> {
val items = soup.select("ul.thumb > li > a") val items = soup.select("ul.thumb > li > a")
if (items.isEmpty()) return ArrayList() return items.map {
val returnValue = ArrayList<SearchResponse>() val href = fixUrl(it.attr("href"))
for (i in items) { val img = fixUrl(it.selectFirst("img").attr("src"))
val href = fixUrl(i.attr("href")) val title = it.attr("title")
val img = fixUrl(i.selectFirst("img").attr("src"))
val title = i.attr("title")
returnValue.add(
if (getIsMovie(href, true)) { if (getIsMovie(href, true)) {
MovieSearchResponse( MovieSearchResponse(
title, href, this.name, TvType.Movie, img, null title, href, this.name, TvType.Movie, img, null
@ -126,9 +122,7 @@ class TenshiProvider : MainAPI() {
EnumSet.of(DubStatus.Subbed), EnumSet.of(DubStatus.Subbed),
) )
} }
)
} }
return returnValue
} }
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
@ -207,7 +201,7 @@ class TenshiProvider : MainAPI() {
interceptor = ddosGuardKiller interceptor = ddosGuardKiller
).document ).document
val returnValue = parseSearchPage(document) val returnValue = parseSearchPage(document).toMutableList()
while (!document.select("""a.page-link[rel="next"]""").isEmpty()) { while (!document.select("""a.page-link[rel="next"]""").isEmpty()) {
val link = document.select("""a.page-link[rel="next"]""") val link = document.select("""a.page-link[rel="next"]""")
@ -223,7 +217,7 @@ class TenshiProvider : MainAPI() {
} }
} }
return returnValue return ArrayList(returnValue)
} }
override fun load(url: String): LoadResponse { override fun load(url: String): LoadResponse {
@ -233,12 +227,7 @@ class TenshiProvider : MainAPI() {
interceptor = ddosGuardKiller interceptor = ddosGuardKiller
).document ).document
val englishTitle =
document.selectFirst("span.value > span[title=\"English\"]")?.parent()?.text()?.trim()
val japaneseTitle =
document.selectFirst("span.value > span[title=\"Japanese\"]")?.parent()?.text()?.trim()
val canonicalTitle = document.selectFirst("header.entry-header > h1.mb-3").text().trim() val canonicalTitle = document.selectFirst("header.entry-header > h1.mb-3").text().trim()
val episodeNodes = document.select("li[class*=\"episode\"] > a").toMutableList() val episodeNodes = document.select("li[class*=\"episode\"] > a").toMutableList()
val totalEpisodePages = if (document.select(".pagination").size > 0) val totalEpisodePages = if (document.select(".pagination").size > 0)
document.select(".pagination .page-item a.page-link:not([rel])").last().text() document.select(".pagination .page-item a.page-link:not([rel])").last().text()
@ -266,38 +255,39 @@ class TenshiProvider : MainAPI() {
it.attr("data-content").trim(), it.attr("data-content").trim(),
) )
}) })
val status = when (document.selectFirst("li.status > .value")?.text()?.trim()) {
val type = document.selectFirst("a[href*=\"$mainUrl/type/\"]")?.text()?.trim()
return newAnimeLoadResponse(canonicalTitle, url, getType(type ?: "")) {
posterUrl = document.selectFirst("img.cover-image")?.attr("src")
plot = document.selectFirst(".entry-description > .card-body")?.text()?.trim()
tags =
document.select("li.genre.meta-data > span.value")
.map { it?.text()?.trim().toString() }
synonyms =
document.select("li.synonym.meta-data > div.info-box > span.value")
.map { it?.text()?.trim().toString() }
engName =
document.selectFirst("span.value > span[title=\"English\"]")?.parent()?.text()
?.trim()
japName =
document.selectFirst("span.value > span[title=\"Japanese\"]")?.parent()?.text()
?.trim()
val pattern = "(\\d{4})".toRegex()
val yearText = document.selectFirst("li.release-date .value").text()
year = pattern.find(yearText)?.groupValues?.get(1)?.toIntOrNull()
addEpisodes(DubStatus.Subbed, episodes)
showStatus = when (document.selectFirst("li.status > .value")?.text()?.trim()) {
"Ongoing" -> ShowStatus.Ongoing "Ongoing" -> ShowStatus.Ongoing
"Completed" -> ShowStatus.Completed "Completed" -> ShowStatus.Completed
else -> null else -> null
} }
val yearText = document.selectFirst("li.release-date .value").text()
val pattern = "(\\d{4})".toRegex()
val (year) = pattern.find(yearText)!!.destructured
val poster = document.selectFirst("img.cover-image")?.attr("src")
val type = document.selectFirst("a[href*=\"$mainUrl/type/\"]")?.text()?.trim()
val synopsis = document.selectFirst(".entry-description > .card-body")?.text()?.trim()
val genre =
document.select("li.genre.meta-data > span.value").map { it?.text()?.trim().toString() }
val synonyms =
document.select("li.synonym.meta-data > div.info-box > span.value")
.map { it?.text()?.trim().toString() }
return newAnimeLoadResponse(canonicalTitle, url, getType(type ?: "")) {
engName = englishTitle
japName = japaneseTitle
posterUrl = poster
this.year = year.toIntOrNull()
addEpisodes(DubStatus.Subbed, episodes)
showStatus = status
tags = genre
this.synonyms = synonyms
plot = synopsis
} }
} }

View file

@ -42,7 +42,7 @@ class DdosGuardKiller(private val alwaysBypass: Boolean) : Interceptor {
app.get(it, cacheTime = 0).cookies.also { cookies -> app.get(it, cacheTime = 0).cookies.also { cookies ->
savedCookiesMap[request.url.host] = cookies savedCookiesMap[request.url.host] = cookies
} }
} } + request.cookies
val headers = getHeaders(request.headers.toMap(), null, cookies) val headers = getHeaders(request.headers.toMap(), null, cookies)
return app.baseClient.newCall( return app.baseClient.newCall(

View file

@ -59,10 +59,10 @@ val Response.url: String
return this.request.url.toString() return this.request.url.toString()
} }
val Response.cookies: Map<String, String>
get() { fun Headers.getCookies(cookieKey: String): Map<String, String> {
val cookieList = val cookieList =
this.headers.filter { it.first.lowercase(Locale.ROOT) == "set-cookie" } this.filter { it.first.equals(cookieKey, ignoreCase = true) }
.getOrNull(0)?.second?.split(";") .getOrNull(0)?.second?.split(";")
return cookieList?.associate { return cookieList?.associate {
val split = it.split("=") val split = it.split("=")
@ -70,6 +70,16 @@ val Response.cookies: Map<String, String>
}?.filter { it.key.isNotBlank() && it.value.isNotBlank() } ?: mapOf() }?.filter { it.key.isNotBlank() && it.value.isNotBlank() } ?: mapOf()
} }
val Response.cookies: Map<String, String>
get() {
return this.headers.getCookies("set-cookie")
}
val Request.cookies: Map<String, String>
get() {
return this.headers.getCookies("Cookie")
}
class AppResponse( class AppResponse(
val response: Response val response: Response
) { ) {
@ -137,7 +147,7 @@ fun getHeaders(
val cookieHeaders = (DEFAULT_COOKIES + cookie) val cookieHeaders = (DEFAULT_COOKIES + cookie)
val cookieMap = val cookieMap =
if (cookieHeaders.isNotEmpty()) mapOf( if (cookieHeaders.isNotEmpty()) mapOf(
"Cookie" to cookieHeaders.entries.joinToString() { "Cookie" to cookieHeaders.entries.joinToString("") {
"${it.key}=${it.value};" "${it.key}=${it.value};"
}) else mapOf() }) else mapOf()
val tempHeaders = (DEFAULT_HEADERS + headers + cookieMap + refererMap) val tempHeaders = (DEFAULT_HEADERS + headers + cookieMap + refererMap)