From 7bbd88cfa83fe54ae81f72e4994de4dae771ab2b Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Tue, 12 Oct 2021 17:32:06 +0700 Subject: [PATCH] Fix CatManga broken chapters (#9437) --- src/en/catmanga/build.gradle | 2 +- .../extension/en/catmanga/CatManga.kt | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/en/catmanga/build.gradle b/src/en/catmanga/build.gradle index 926a7d204..ca6f77fd8 100644 --- a/src/en/catmanga/build.gradle +++ b/src/en/catmanga/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'CatManga' pkgNameSuffix = "en.catmanga" extClass = '.CatManga' - extVersionCode = 5 + extVersionCode = 6 } apply from: "$rootDir/common.gradle" diff --git a/src/en/catmanga/src/eu/kanade/tachiyomi/extension/en/catmanga/CatManga.kt b/src/en/catmanga/src/eu/kanade/tachiyomi/extension/en/catmanga/CatManga.kt index 9308f4057..0991957c4 100644 --- a/src/en/catmanga/src/eu/kanade/tachiyomi/extension/en/catmanga/CatManga.kt +++ b/src/en/catmanga/src/eu/kanade/tachiyomi/extension/en/catmanga/CatManga.kt @@ -13,8 +13,10 @@ import eu.kanade.tachiyomi.util.asJsoup import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json +import kotlinx.serialization.json.boolean import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.jsonObject +import kotlinx.serialization.json.jsonPrimitive import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -118,12 +120,22 @@ class CatManga : HttpSource() { return MangasPage(mangas, false) } - override fun pageListParse(response: Response): List { - val jsonElement = response.asJsoup() - .getDataJsonObject()["props"]!! - .jsonObject["pageProps"]!! - .jsonObject["pages"]!! - return json.decodeFromJsonElement>(jsonElement).mapIndexed { index, s -> Page(index, "", s) } + override fun fetchPageList(chapter: SChapter): Observable> { + return client.newCall(pageListRequest(chapter)) + .asObservableSuccess() + .map { + val doc = it.asJsoup().getDataJsonObject() + val pages = if (doc["isFallback"]!!.jsonPrimitive.boolean) { + val buildId = doc["buildId"]!!.jsonPrimitive.content + val directRequest = GET("$baseUrl/_next/data/$buildId/${chapter.url}.json") + val directResponse = client.newCall(directRequest).execute() + json.parseToJsonElement(directResponse.body!!.string()) + } else { + doc["props"]!! + }.jsonObject["pageProps"]!!.jsonObject["pages"]!! + json.decodeFromJsonElement>(pages) + .mapIndexed { index, s -> Page(index, "", s) } + } } /** @@ -138,6 +150,10 @@ class CatManga : HttpSource() { return if (toInt().toFloat() == this) toInt().toString() else toString() } + override fun pageListParse(response: Response): List { + throw UnsupportedOperationException("Not used.") + } + override fun latestUpdatesRequest(page: Int): Request { throw UnsupportedOperationException("Not used.") }