Madtheme: fix chapters fetching (#7270)
* add chapters fetch preferences * bump * remove fetching preferences and call both enpoints * remove const * fix
This commit is contained in:
parent
936a7f1fde
commit
3f86aa1c40
|
@ -2,4 +2,4 @@ plugins {
|
||||||
id("lib-multisrc")
|
id("lib-multisrc")
|
||||||
}
|
}
|
||||||
|
|
||||||
baseVersionCode = 15
|
baseVersionCode = 16
|
||||||
|
|
|
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
|
import okhttp3.HttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
@ -183,18 +184,19 @@ abstract class MadTheme(
|
||||||
val bookId = script.data().substringAfter("bookId = ").substringBefore(";")
|
val bookId = script.data().substringAfter("bookId = ").substringBefore(";")
|
||||||
val bookSlug = script.data().substringAfter("bookSlug = \"").substringBefore("\";")
|
val bookSlug = script.data().substringAfter("bookSlug = \"").substringBefore("\";")
|
||||||
|
|
||||||
// Find by bookId, if no result then try with slug
|
// At this moment we can not decide which endpoint has the chapters, so we call both.
|
||||||
var chapterRequest =
|
val idRequest = client.newCall(GET(buildChapterUrl(bookId), headers)).execute()
|
||||||
client.newCall(GET("$baseUrl/api/manga/$bookId/chapters?source=detail", headers))
|
val slugRequest = client.newCall(GET(buildChapterUrl(bookSlug), headers)).execute()
|
||||||
.execute()
|
|
||||||
|
|
||||||
if (chapterRequest.code !in 200..299) {
|
// By default the id request will be the final, due to some extension don't even has slug fetch.
|
||||||
chapterRequest =
|
var finalDocument = idRequest.asJsoup().select(chapterListSelector())
|
||||||
client.newCall(GET("$baseUrl/api/manga/$bookSlug/chapters?source=detail", headers))
|
val slugDocument = slugRequest.asJsoup().select(chapterListSelector())
|
||||||
.execute()
|
|
||||||
|
if (finalDocument.size < slugDocument.size) {
|
||||||
|
finalDocument = slugDocument
|
||||||
}
|
}
|
||||||
|
|
||||||
return chapterRequest.asJsoup().select("#chapter-list > li").map {
|
return finalDocument.map {
|
||||||
SChapter.create().apply {
|
SChapter.create().apply {
|
||||||
url = it.selectFirst("a")!!.absUrl("href").removePrefix(baseUrl)
|
url = it.selectFirst("a")!!.absUrl("href").removePrefix(baseUrl)
|
||||||
name = it.selectFirst(".chapter-title")!!.text()
|
name = it.selectFirst(".chapter-title")!!.text()
|
||||||
|
@ -203,6 +205,16 @@ abstract class MadTheme(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildChapterUrl(fetchByParam: String): HttpUrl {
|
||||||
|
return baseUrl.toHttpUrl().newBuilder().apply {
|
||||||
|
addPathSegment("api")
|
||||||
|
addPathSegment("manga")
|
||||||
|
addPathSegment(fetchByParam)
|
||||||
|
addPathSegment("chapters")
|
||||||
|
addQueryParameter("source", "detail")
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
|
||||||
override fun chapterListRequest(manga: SManga): Request =
|
override fun chapterListRequest(manga: SManga): Request =
|
||||||
MANGA_ID_REGEX.find(manga.url)?.groupValues?.get(1)?.let { mangaId ->
|
MANGA_ID_REGEX.find(manga.url)?.groupValues?.get(1)?.let { mangaId ->
|
||||||
val url = "$baseUrl/service/backend/chaplist/".toHttpUrl().newBuilder()
|
val url = "$baseUrl/service/backend/chaplist/".toHttpUrl().newBuilder()
|
||||||
|
|
Loading…
Reference in New Issue