LectorTMO: Fix only 1 page showing occasionally (#3761)

* Test

* Lint

* what

* Fixes
This commit is contained in:
bapeey 2024-06-27 03:22:07 -05:00 committed by Draff
parent 592645fa9d
commit dcd3bc015d
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 29 additions and 16 deletions

View File

@ -2,4 +2,4 @@ plugins {
id("lib-multisrc") id("lib-multisrc")
} }
baseVersionCode = 5 baseVersionCode = 6

View File

@ -319,7 +319,7 @@ abstract class LectorTmo(
return GET(chapter.url, tmoHeaders) return GET(chapter.url, tmoHeaders)
} }
override fun pageListParse(document: Document): List<Page> = mutableListOf<Page>().apply { override fun pageListParse(document: Document): List<Page> {
var doc = redirectToReadPage(document) var doc = redirectToReadPage(document)
val currentUrl = doc.location() val currentUrl = doc.location()
@ -336,21 +336,24 @@ abstract class LectorTmo(
.build() .build()
doc = client.newCall(GET(newUrl, redirectHeaders)).execute().asJsoup() doc = client.newCall(GET(newUrl, redirectHeaders)).execute().asJsoup()
} }
val imagesScript = doc.selectFirst("script:containsData(var dirPath):containsData(var images)")
doc.select("div.viewer-container img:not(noscript img)").forEach { imagesScript?.data()?.let {
add( val dirPath = DIRPATH_REGEX.find(imagesScript.data())?.groupValues?.get(1)
Page( val images = IMAGES_REGEX.find(imagesScript.data())?.groupValues?.get(1)?.split(",")?.map { img ->
size, img.trim().removeSurrounding("\"")
doc.location(), }
it.let { if (dirPath != null && images != null) {
if (it.hasAttr("data-src")) { return images.mapIndexed { i, img ->
it.attr("abs:data-src") Page(i, doc.location(), "$dirPath$img")
} else { }
it.attr("abs:src") }
} }
},
), doc.select("div.viewer-container img:not(noscript img)").let {
) return it.mapIndexed { i, img ->
Page(i, doc.location(), img.imgAttr())
}
} }
} }
@ -420,6 +423,13 @@ abstract class LectorTmo(
return document return document
} }
private fun Element.imgAttr(): String {
return when {
this.hasAttr("data-src") -> this.attr("abs:data-src")
else -> this.attr("abs:src")
}
}
private fun String.unescapeUrl(): String { private fun String.unescapeUrl(): String {
return if (this.startsWith("http:\\/\\/") || this.startsWith("https:\\/\\/")) { return if (this.startsWith("http:\\/\\/") || this.startsWith("https:\\/\\/")) {
this.replace("\\/", "/") this.replace("\\/", "/")
@ -605,6 +615,9 @@ abstract class LectorTmo(
} }
companion object { companion object {
val DIRPATH_REGEX = """var\s+dirPath\s*=\s*'(.*?)'\s*;""".toRegex()
val IMAGES_REGEX = """var\s+images\s*=.*\[(.*?)\]\s*'\s*\)\s*;""".toRegex()
private const val SCANLATOR_PREF = "scanlatorPref" private const val SCANLATOR_PREF = "scanlatorPref"
private const val SCANLATOR_PREF_TITLE = "Mostrar todos los scanlator" private const val SCANLATOR_PREF_TITLE = "Mostrar todos los scanlator"
private const val SCANLATOR_PREF_SUMMARY = "Se mostraran capítulos repetidos pero con diferentes Scanlators" private const val SCANLATOR_PREF_SUMMARY = "Se mostraran capítulos repetidos pero con diferentes Scanlators"