added new episode path id resolution

This commit is contained in:
Josef František Straka 2024-08-03 15:56:31 +02:00
parent 27217d4ef0
commit 62071cc84b

View file

@ -123,15 +123,18 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
// =========================== Anime Details ============================ // =========================== Anime Details ============================
override fun animeDetailsParse(document: Document): SAnime = SAnime.create().apply { override fun animeDetailsParse(document: Document): SAnime {
title = document.select("h1.title").text() val anime = SAnime.create()
genre = document.select("div:contains(Genre) > span > a").joinToString { it.text() } val newDocument = resolveSearchAnime(anime, document)
description = document.select("div.synopsis > div.shorting > div.content").text() anime.apply {
author = document.select("div:contains(Studio) > span > a").text() title = newDocument.select("h1.title").text()
status = parseStatus(document.select("div:contains(Status) > span").text()) genre = newDocument.select("div:contains(Genre) > span > a").joinToString { it.text() }
description = newDocument.select("div.synopsis > div.shorting > div.content").text()
author = newDocument.select("div:contains(Studio) > span > a").text()
status = parseStatus(newDocument.select("div:contains(Status) > span").text())
val altName = "Other name(s): " val altName = "Other name(s): "
document.select("h1.title").attr("data-jp").let { newDocument.select("h1.title").attr("data-jp").let {
if (it.isNotBlank()) { if (it.isNotBlank()) {
description = when { description = when {
description.isNullOrBlank() -> altName + it description.isNullOrBlank() -> altName + it
@ -140,31 +143,17 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
} }
} }
} }
return anime
}
// ============================== Episodes ============================== // ============================== Episodes ==============================
override fun episodeListRequest(anime: SAnime): Request { override fun episodeListRequest(anime: SAnime): Request {
Log.i(name, "episodeListRequest") Log.i(name, "episodeListRequest")
var document: Document? = null
try {
val response = client.newCall(GET(baseUrl + anime.url)).execute() val response = client.newCall(GET(baseUrl + anime.url)).execute()
document = response.asJsoup() var document = response.asJsoup()
} catch (e: Exception) { document = resolveSearchAnime(anime, document)
Log.e(name, e.toString()) val id = document.selectFirst("div[data-id]")?.attr("data-id") ?: throw Exception("ID not found")
throw e
}
var id = ""
if (document.location().startsWith("$baseUrl/filter?keyword=")) { // redirected to search
val tip = document.selectFirst("div.tip[data-tip]")?.attr("data-tip") ?: throw Exception("data-tip not found")
val tipParts = tip.split("?")
if (tipParts.count() == 2) {
id = tipParts[0]
} else {
throw Exception("data-tip malformed")
}
} else {
id = document.selectFirst("div[data-id]")?.attr("data-id") ?: throw Exception("ID not found")
}
val vrf = utils.vrfEncrypt(ENCRYPTION_KEY, id) val vrf = utils.vrfEncrypt(ENCRYPTION_KEY, id)
@ -335,6 +324,16 @@ class Aniwave : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
} }
} }
private fun resolveSearchAnime(anime: SAnime, document: Document): Document {
if (document.location().startsWith("$baseUrl/filter?keyword=")) { // redirected to search
val element = document.selectFirst(searchAnimeSelector())
val foundAnimePath = element?.selectFirst("a[href]")?.attr("href") ?: throw Exception("Search element not found (resolveSearch)")
anime.url = foundAnimePath //probably doesn't work as intended
return client.newCall(GET(baseUrl + foundAnimePath)).execute().asJsoup()
}
return document
}
private fun getHosters(): Set<String> { private fun getHosters(): Set<String> {
val hosterSelection = preferences.getStringSet(PREF_HOSTER_KEY, PREF_HOSTER_DEFAULT)!! val hosterSelection = preferences.getStringSet(PREF_HOSTER_KEY, PREF_HOSTER_DEFAULT)!!
var invalidRecord = false var invalidRecord = false