fix nhentai cdn script selection (#9857)

* fix nhentai cdn script selection

* apply suggestions
This commit is contained in:
MediocreLegion 2025-07-31 10:58:42 -03:00 committed by Draff
parent e18a2f732c
commit a8fad4b5c2
Signed by: Draff
GPG Key ID: E8A89F3211677653
2 changed files with 9 additions and 7 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'NHentai'
extClass = '.NHFactory'
extVersionCode = 51
extVersionCode = 52
isNsfw = true
}

View File

@ -255,18 +255,20 @@ open class NHentai(
override fun chapterListSelector() = throw UnsupportedOperationException()
override fun pageListParse(document: Document): List<Page> {
val script = document.selectFirst("script:containsData(media_server)")!!.data()
val script2 = document.selectFirst(hentaiSelector)!!.data()
override fun pageListParse(document: Document) = throw UnsupportedOperationException()
val mediaServer = Regex("""media_server\s*:\s*(\d+)""").find(script)?.groupValues!![1]
val json = dataRegex.find(script2)?.groupValues!![1]
override fun pageListParse(response: Response): List<Page> {
val html = response.body.string()
val json = dataRegex.find(html)?.groupValues!![1]
val data = json.parseAs<Hentai>()
val cdnJson = Regex("""image_cdn_urls:\s*(\[.*])""").find(html)?.groupValues!![1]
val cdnList = cdnJson.parseAs<List<String>>()
return data.images.pages.mapIndexed { i, image ->
Page(
i,
imageUrl = "${baseUrl.replace("https://", "https://i$mediaServer.")}/galleries/${data.media_id}/${i + 1}" +
imageUrl = "https://${cdnList.random()}/galleries/${data.media_id}/${i + 1}" +
when (image.t) {
"w" -> ".webp"
"p" -> ".png"