From ba0f13242271b83d79288981bab6245be9681c0c Mon Sep 17 00:00:00 2001 From: sinkableShip <89952969+sinkableShip@users.noreply.github.com> Date: Thu, 25 Apr 2024 22:56:16 +0700 Subject: [PATCH] Miaoshang: Fix page parsing (#2556) * Fix page parsing * Add default function to fall back if the website get back to normal calling super.pageListParse(response) will cause java.lang.IllegalStateException: closed since response.asJsoup() will be called twice, so resolve to copying the code --- .../tachiyomi/multisrc/mccms/MCCMSConfig.kt | 4 +-- src/zh/miaoshang/build.gradle | 2 +- .../extension/zh/miaoshang/Miaoshang.kt | 33 ++++++++++++++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/lib-multisrc/mccms/src/eu/kanade/tachiyomi/multisrc/mccms/MCCMSConfig.kt b/lib-multisrc/mccms/src/eu/kanade/tachiyomi/multisrc/mccms/MCCMSConfig.kt index e0036b985..a8941bad3 100644 --- a/lib-multisrc/mccms/src/eu/kanade/tachiyomi/multisrc/mccms/MCCMSConfig.kt +++ b/lib-multisrc/mccms/src/eu/kanade/tachiyomi/multisrc/mccms/MCCMSConfig.kt @@ -16,11 +16,11 @@ open class MCCMSConfig( hasCategoryPage: Boolean = true, val textSearchOnlyPageOne: Boolean = false, val useMobilePageList: Boolean = false, - private val lazyLoadImageAttr: String = "data-original", + protected val lazyLoadImageAttr: String = "data-original", ) { val genreData = GenreData(hasCategoryPage) - fun pageListParse(response: Response): List { + open fun pageListParse(response: Response): List { val document = response.asJsoup() return if (useMobilePageList) { diff --git a/src/zh/miaoshang/build.gradle b/src/zh/miaoshang/build.gradle index 9813b68b7..414f87746 100644 --- a/src/zh/miaoshang/build.gradle +++ b/src/zh/miaoshang/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.Miaoshang' themePkg = 'mccms' baseUrl = 'https://www.miaoshangmanhua.com' - overrideVersionCode = 0 + overrideVersionCode = 1 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/miaoshang/src/eu/kanade/tachiyomi/extension/zh/miaoshang/Miaoshang.kt b/src/zh/miaoshang/src/eu/kanade/tachiyomi/extension/zh/miaoshang/Miaoshang.kt index 6a4503e50..b9d32d6bb 100644 --- a/src/zh/miaoshang/src/eu/kanade/tachiyomi/extension/zh/miaoshang/Miaoshang.kt +++ b/src/zh/miaoshang/src/eu/kanade/tachiyomi/extension/zh/miaoshang/Miaoshang.kt @@ -3,18 +3,43 @@ package eu.kanade.tachiyomi.extension.zh.miaoshang import eu.kanade.tachiyomi.multisrc.mccms.MCCMS import eu.kanade.tachiyomi.multisrc.mccms.MCCMSConfig import eu.kanade.tachiyomi.network.interceptor.rateLimitHost +import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.util.asJsoup import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Response +import org.jsoup.Jsoup class Miaoshang : MCCMS( "喵上漫画", "https://www.miaoshangmanhua.com", "zh", - MCCMSConfig( - textSearchOnlyPageOne = true, - lazyLoadImageAttr = "data-src", - ), + MiaoshangMCCMSConfig(), ) { override val client = network.cloudflareClient.newBuilder() .rateLimitHost(baseUrl.toHttpUrl(), 2) .build() + + private class MiaoshangMCCMSConfig : MCCMSConfig( + textSearchOnlyPageOne = true, + lazyLoadImageAttr = "data-src", + ) { + override fun pageListParse(response: Response): List { + val document = response.asJsoup() + val container = document.select(".rd-article-wr") + val comments = container.comments() + + return comments.filter { comment -> + comment.data.contains(lazyLoadImageAttr) + }.mapIndexed { i, comment -> + Jsoup.parse(comment.data) + .selectFirst("img[$lazyLoadImageAttr]")?.attr(lazyLoadImageAttr).let { imageUrl -> + Page(i, imageUrl = imageUrl) + } + }.ifEmpty { + document.select("img[$lazyLoadImageAttr]").mapIndexed { i, img -> + Page(i, imageUrl = img.attr(lazyLoadImageAttr)) + } + } + } + } }