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
This commit is contained in:
sinkableShip 2024-04-25 22:56:16 +07:00 committed by GitHub
parent f54f289eac
commit ba0f132422
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 7 deletions

View File

@ -16,11 +16,11 @@ open class MCCMSConfig(
hasCategoryPage: Boolean = true, hasCategoryPage: Boolean = true,
val textSearchOnlyPageOne: Boolean = false, val textSearchOnlyPageOne: Boolean = false,
val useMobilePageList: Boolean = false, val useMobilePageList: Boolean = false,
private val lazyLoadImageAttr: String = "data-original", protected val lazyLoadImageAttr: String = "data-original",
) { ) {
val genreData = GenreData(hasCategoryPage) val genreData = GenreData(hasCategoryPage)
fun pageListParse(response: Response): List<Page> { open fun pageListParse(response: Response): List<Page> {
val document = response.asJsoup() val document = response.asJsoup()
return if (useMobilePageList) { return if (useMobilePageList) {

View File

@ -3,7 +3,7 @@ ext {
extClass = '.Miaoshang' extClass = '.Miaoshang'
themePkg = 'mccms' themePkg = 'mccms'
baseUrl = 'https://www.miaoshangmanhua.com' baseUrl = 'https://www.miaoshangmanhua.com'
overrideVersionCode = 0 overrideVersionCode = 1
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -3,18 +3,43 @@ package eu.kanade.tachiyomi.extension.zh.miaoshang
import eu.kanade.tachiyomi.multisrc.mccms.MCCMS import eu.kanade.tachiyomi.multisrc.mccms.MCCMS
import eu.kanade.tachiyomi.multisrc.mccms.MCCMSConfig import eu.kanade.tachiyomi.multisrc.mccms.MCCMSConfig
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost 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.HttpUrl.Companion.toHttpUrl
import okhttp3.Response
import org.jsoup.Jsoup
class Miaoshang : MCCMS( class Miaoshang : MCCMS(
"喵上漫画", "喵上漫画",
"https://www.miaoshangmanhua.com", "https://www.miaoshangmanhua.com",
"zh", "zh",
MCCMSConfig( MiaoshangMCCMSConfig(),
textSearchOnlyPageOne = true,
lazyLoadImageAttr = "data-src",
),
) { ) {
override val client = network.cloudflareClient.newBuilder() override val client = network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 2) .rateLimitHost(baseUrl.toHttpUrl(), 2)
.build() .build()
private class MiaoshangMCCMSConfig : MCCMSConfig(
textSearchOnlyPageOne = true,
lazyLoadImageAttr = "data-src",
) {
override fun pageListParse(response: Response): List<Page> {
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))
}
}
}
}
} }