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,34 +101,28 @@ 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")) if (getIsMovie(href, true)) {
val title = i.attr("title") MovieSearchResponse(
title, href, this.name, TvType.Movie, img, null
returnValue.add( )
if (getIsMovie(href, true)) { } else {
MovieSearchResponse( AnimeSearchResponse(
title, href, this.name, TvType.Movie, img, null title,
) href,
} else { this.name,
AnimeSearchResponse( TvType.Anime,
title, img,
href, null,
this.name, EnumSet.of(DubStatus.Subbed),
TvType.Anime, )
img, }
null,
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()) {
"Ongoing" -> ShowStatus.Ongoing
"Completed" -> ShowStatus.Completed
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 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 ?: "")) { return newAnimeLoadResponse(canonicalTitle, url, getType(type ?: "")) {
engName = englishTitle posterUrl = document.selectFirst("img.cover-image")?.attr("src")
japName = japaneseTitle plot = document.selectFirst(".entry-description > .card-body")?.text()?.trim()
tags =
document.select("li.genre.meta-data > span.value")
.map { it?.text()?.trim().toString() }
posterUrl = poster synonyms =
this.year = year.toIntOrNull() 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) addEpisodes(DubStatus.Subbed, episodes)
showStatus = status
tags = genre showStatus = when (document.selectFirst("li.status > .value")?.text()?.trim()) {
this.synonyms = synonyms "Ongoing" -> ShowStatus.Ongoing
plot = synopsis "Completed" -> ShowStatus.Completed
else -> null
}
} }
} }

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,15 +59,25 @@ val Response.url: String
return this.request.url.toString() return this.request.url.toString()
} }
fun Headers.getCookies(cookieKey: String): Map<String, String> {
val cookieList =
this.filter { it.first.equals(cookieKey, ignoreCase = true) }
.getOrNull(0)?.second?.split(";")
return cookieList?.associate {
val split = it.split("=")
(split.getOrNull(0)?.trim() ?: "") to (split.getOrNull(1)?.trim() ?: "")
}?.filter { it.key.isNotBlank() && it.value.isNotBlank() } ?: mapOf()
}
val Response.cookies: Map<String, String> val Response.cookies: Map<String, String>
get() { get() {
val cookieList = return this.headers.getCookies("set-cookie")
this.headers.filter { it.first.lowercase(Locale.ROOT) == "set-cookie" } }
.getOrNull(0)?.second?.split(";")
return cookieList?.associate { val Request.cookies: Map<String, String>
val split = it.split("=") get() {
(split.getOrNull(0)?.trim() ?: "") to (split.getOrNull(1)?.trim() ?: "") return this.headers.getCookies("Cookie")
}?.filter { it.key.isNotBlank() && it.value.isNotBlank() } ?: mapOf()
} }
class AppResponse( class AppResponse(
@ -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)