From dcd3bc015de60fd1047bc2755981deed3ae6e911 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Thu, 27 Jun 2024 03:22:07 -0500 Subject: [PATCH] LectorTMO: Fix only 1 page showing occasionally (#3761) * Test * Lint * what * Fixes --- lib-multisrc/lectortmo/build.gradle.kts | 2 +- .../tachiyomi/multisrc/lectortmo/LectorTmo.kt | 43 ++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib-multisrc/lectortmo/build.gradle.kts b/lib-multisrc/lectortmo/build.gradle.kts index b45873b53..ede652be5 100644 --- a/lib-multisrc/lectortmo/build.gradle.kts +++ b/lib-multisrc/lectortmo/build.gradle.kts @@ -2,4 +2,4 @@ plugins { id("lib-multisrc") } -baseVersionCode = 5 +baseVersionCode = 6 diff --git a/lib-multisrc/lectortmo/src/eu/kanade/tachiyomi/multisrc/lectortmo/LectorTmo.kt b/lib-multisrc/lectortmo/src/eu/kanade/tachiyomi/multisrc/lectortmo/LectorTmo.kt index 41d3f2641..5410c9c42 100644 --- a/lib-multisrc/lectortmo/src/eu/kanade/tachiyomi/multisrc/lectortmo/LectorTmo.kt +++ b/lib-multisrc/lectortmo/src/eu/kanade/tachiyomi/multisrc/lectortmo/LectorTmo.kt @@ -319,7 +319,7 @@ abstract class LectorTmo( return GET(chapter.url, tmoHeaders) } - override fun pageListParse(document: Document): List = mutableListOf().apply { + override fun pageListParse(document: Document): List { 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"