From 6b73e1dfecf756f96614325868e25e3004827e21 Mon Sep 17 00:00:00 2001 From: Chopper <156493704+choppeh@users.noreply.github.com> Date: Mon, 11 Nov 2024 05:42:15 -0300 Subject: [PATCH] Roumanwu: Fix pages (#5986) Fix pages --- src/zh/roumanwu/build.gradle | 2 +- .../extension/zh/roumanwu/Roumanwu.kt | 50 +++---------------- 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/zh/roumanwu/build.gradle b/src/zh/roumanwu/build.gradle index 4fb360371..f6e39ad9e 100644 --- a/src/zh/roumanwu/build.gradle +++ b/src/zh/roumanwu/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Roumanwu' extClass = '.Roumanwu' - extVersionCode = 11 + extVersionCode = 12 isNsfw = true } diff --git a/src/zh/roumanwu/src/eu/kanade/tachiyomi/extension/zh/roumanwu/Roumanwu.kt b/src/zh/roumanwu/src/eu/kanade/tachiyomi/extension/zh/roumanwu/Roumanwu.kt index 082940521..368d9b9bd 100644 --- a/src/zh/roumanwu/src/eu/kanade/tachiyomi/extension/zh/roumanwu/Roumanwu.kt +++ b/src/zh/roumanwu/src/eu/kanade/tachiyomi/extension/zh/roumanwu/Roumanwu.kt @@ -13,18 +13,11 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.contentOrNull -import kotlinx.serialization.json.intOrNull -import kotlinx.serialization.json.jsonArray -import kotlinx.serialization.json.jsonObject -import kotlinx.serialization.json.jsonPrimitive import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -import uy.kohesive.injekt.injectLazy import kotlin.math.max class Roumanwu : ParsedHttpSource(), ConfigurableSource { @@ -41,9 +34,7 @@ class Roumanwu : ParsedHttpSource(), ConfigurableSource { override val client = network.client.newBuilder().addInterceptor(ScrambledImageInterceptor).build() - private val json: Json by injectLazy() - - private val imageUrlRegex = """(?<=\[1,").*(?="\])""".toRegex() + private val imageUrlRegex = """\\"imageUrl\\":\\"(?[^\\]+)""".toRegex() override fun popularMangaRequest(page: Int) = GET("$baseUrl/home", headers) override fun popularMangaNextPageSelector(): String? = null @@ -116,41 +107,16 @@ class Roumanwu : ParsedHttpSource(), ConfigurableSource { } override fun pageListParse(document: Document): List { - val jsonString = document.selectFirst("script:containsData(imageUrl)")?.data() + val images = document.selectFirst("script:containsData(imageUrl)")?.data() ?.let { content -> imageUrlRegex - .find(content) - ?.value - ?.substring(2) - ?.dropLast(2) - ?.replace("\\\"", "\"") - } + .findAll(content).map { it.groups["imageUrl"]?.value } + .toList() + } ?: return emptyList() - return jsonString?.let { str -> - val jo = json.parseToJsonElement(str) - val pagesJson = jo.jsonArray - .getOrNull(3)?.jsonObject - ?.get("children")?.jsonArray - ?.getOrNull(6)?.jsonArray - ?.getOrNull(3)?.jsonObject - ?.get("children")?.jsonArray - - pagesJson?.mapNotNull { pageElement -> - val pageData = pageElement.jsonArray - .getOrNull(3)?.jsonObject - ?.get("children")?.jsonArray - ?.getOrNull(3)?.jsonObject - - val index = pageData?.get("ind")?.jsonPrimitive?.intOrNull - val imageUrl = pageData?.get("imageUrl")?.jsonPrimitive?.contentOrNull - - if (index != null && imageUrl != null) { - Page(index, imageUrl = imageUrl) - } else { - null - } - } ?: emptyList() - } ?: emptyList() + return images.mapIndexed { index, imageUrl -> + Page(index, imageUrl = imageUrl) + } } override fun imageUrlParse(document: Document) = throw UnsupportedOperationException()