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")
}
baseVersionCode = 5
baseVersionCode = 6

View File

@ -319,7 +319,7 @@ abstract class LectorTmo(
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)
val currentUrl = doc.location()
@ -336,21 +336,24 @@ abstract class LectorTmo(
.build()
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 {
add(
Page(
size,
doc.location(),
it.let {
if (it.hasAttr("data-src")) {
it.attr("abs:data-src")
} else {
it.attr("abs:src")
imagesScript?.data()?.let {
val dirPath = DIRPATH_REGEX.find(imagesScript.data())?.groupValues?.get(1)
val images = IMAGES_REGEX.find(imagesScript.data())?.groupValues?.get(1)?.split(",")?.map { img ->
img.trim().removeSurrounding("\"")
}
if (dirPath != null && images != null) {
return images.mapIndexed { i, img ->
Page(i, doc.location(), "$dirPath$img")
}
}
}
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
}
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 {
return if (this.startsWith("http:\\/\\/") || this.startsWith("https:\\/\\/")) {
this.replace("\\/", "/")
@ -605,6 +615,9 @@ abstract class LectorTmo(
}
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_TITLE = "Mostrar todos los scanlator"
private const val SCANLATOR_PREF_SUMMARY = "Se mostraran capítulos repetidos pero con diferentes Scanlators"