Fix CatManga broken chapters (#9437)

This commit is contained in:
Ivan Iskandar 2021-10-12 17:32:06 +07:00 committed by GitHub
parent ececeb7d93
commit 7bbd88cfa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'CatManga'
pkgNameSuffix = "en.catmanga"
extClass = '.CatManga'
extVersionCode = 5
extVersionCode = 6
}
apply from: "$rootDir/common.gradle"

View File

@ -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<Page> {
val jsonElement = response.asJsoup()
.getDataJsonObject()["props"]!!
.jsonObject["pageProps"]!!
.jsonObject["pages"]!!
return json.decodeFromJsonElement<List<String>>(jsonElement).mapIndexed { index, s -> Page(index, "", s) }
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
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<List<String>>(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<Page> {
throw UnsupportedOperationException("Not used.")
}
override fun latestUpdatesRequest(page: Int): Request {
throw UnsupportedOperationException("Not used.")
}