Roumanwu: Fix pages (#5986)

Fix pages
This commit is contained in:
Chopper 2024-11-11 05:42:15 -03:00 committed by Draff
parent 0c3a9dc8aa
commit 6b73e1dfec
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 9 additions and 43 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Roumanwu'
extClass = '.Roumanwu'
extVersionCode = 11
extVersionCode = 12
isNsfw = true
}

View File

@ -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\\":\\"(?<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<Page> {
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()