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 { ext {
extName = 'Roumanwu' extName = 'Roumanwu'
extClass = '.Roumanwu' extClass = '.Roumanwu'
extVersionCode = 11 extVersionCode = 12
isNsfw = true 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.model.SManga
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup 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 okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import kotlin.math.max import kotlin.math.max
class Roumanwu : ParsedHttpSource(), ConfigurableSource { class Roumanwu : ParsedHttpSource(), ConfigurableSource {
@ -41,9 +34,7 @@ class Roumanwu : ParsedHttpSource(), ConfigurableSource {
override val client = network.client.newBuilder().addInterceptor(ScrambledImageInterceptor).build() override val client = network.client.newBuilder().addInterceptor(ScrambledImageInterceptor).build()
private val json: Json by injectLazy() private val imageUrlRegex = """\\"imageUrl\\":\\"(?<imageUrl>[^\\]+)""".toRegex()
private val imageUrlRegex = """(?<=\[1,").*(?="\])""".toRegex()
override fun popularMangaRequest(page: Int) = GET("$baseUrl/home", headers) override fun popularMangaRequest(page: Int) = GET("$baseUrl/home", headers)
override fun popularMangaNextPageSelector(): String? = null override fun popularMangaNextPageSelector(): String? = null
@ -116,41 +107,16 @@ class Roumanwu : ParsedHttpSource(), ConfigurableSource {
} }
override fun pageListParse(document: Document): List<Page> { 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 -> ?.let { content ->
imageUrlRegex imageUrlRegex
.find(content) .findAll(content).map { it.groups["imageUrl"]?.value }
?.value .toList()
?.substring(2) } ?: return emptyList()
?.dropLast(2)
?.replace("\\\"", "\"")
}
return jsonString?.let { str -> return images.mapIndexed { index, imageUrl ->
val jo = json.parseToJsonElement(str) Page(index, imageUrl = imageUrl)
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()
} }
override fun imageUrlParse(document: Document) = throw UnsupportedOperationException() override fun imageUrlParse(document: Document) = throw UnsupportedOperationException()