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.text.SimpleDateFormat
import java.util.*
import kotlin.concurrent.thread
import kotlin.collections.ArrayList
class TenshiProvider : MainAPI() {
companion object {
@ -101,16 +101,12 @@ class TenshiProvider : MainAPI() {
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")
if (items.isEmpty()) return ArrayList()
val returnValue = ArrayList<SearchResponse>()
for (i in items) {
val href = fixUrl(i.attr("href"))
val img = fixUrl(i.selectFirst("img").attr("src"))
val title = i.attr("title")
returnValue.add(
return items.map {
val href = fixUrl(it.attr("href"))
val img = fixUrl(it.selectFirst("img").attr("src"))
val title = it.attr("title")
if (getIsMovie(href, true)) {
MovieSearchResponse(
title, href, this.name, TvType.Movie, img, null
@ -126,9 +122,7 @@ class TenshiProvider : MainAPI() {
EnumSet.of(DubStatus.Subbed),
)
}
)
}
return returnValue
}
@SuppressLint("SimpleDateFormat")
@ -207,7 +201,7 @@ class TenshiProvider : MainAPI() {
interceptor = ddosGuardKiller
).document
val returnValue = parseSearchPage(document)
val returnValue = parseSearchPage(document).toMutableList()
while (!document.select("""a.page-link[rel="next"]""").isEmpty()) {
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 {
@ -233,12 +227,7 @@ class TenshiProvider : MainAPI() {
interceptor = ddosGuardKiller
).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 episodeNodes = document.select("li[class*=\"episode\"] > a").toMutableList()
val totalEpisodePages = if (document.select(".pagination").size > 0)
document.select(".pagination .page-item a.page-link:not([rel])").last().text()
@ -266,38 +255,39 @@ class TenshiProvider : MainAPI() {
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
"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 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 ->
savedCookiesMap[request.url.host] = cookies
}
}
} + request.cookies
val headers = getHeaders(request.headers.toMap(), null, cookies)
return app.baseClient.newCall(

View file

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