From 2830a0a1a98ae2445269a99f4afb180b3d65e3a3 Mon Sep 17 00:00:00 2001 From: Chopper <156493704+choppeh@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:11:05 -0300 Subject: [PATCH] Madara: Improve thumbnail (#5762) * Improve thumbnail * Bump version --- lib-multisrc/madara/build.gradle.kts | 2 +- .../eu/kanade/tachiyomi/multisrc/madara/Madara.kt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib-multisrc/madara/build.gradle.kts b/lib-multisrc/madara/build.gradle.kts index 49385183a..5ee898f4c 100644 --- a/lib-multisrc/madara/build.gradle.kts +++ b/lib-multisrc/madara/build.gradle.kts @@ -2,7 +2,7 @@ plugins { id("lib-multisrc") } -baseVersionCode = 36 +baseVersionCode = 37 dependencies { api(project(":lib:cryptoaes")) diff --git a/lib-multisrc/madara/src/eu/kanade/tachiyomi/multisrc/madara/Madara.kt b/lib-multisrc/madara/src/eu/kanade/tachiyomi/multisrc/madara/Madara.kt index 137c709f4..7bb5e2f7e 100644 --- a/lib-multisrc/madara/src/eu/kanade/tachiyomi/multisrc/madara/Madara.kt +++ b/lib-multisrc/madara/src/eu/kanade/tachiyomi/multisrc/madara/Madara.kt @@ -767,12 +767,21 @@ abstract class Madara( return when { element.hasAttr("data-src") -> element.attr("abs:data-src") element.hasAttr("data-lazy-src") -> element.attr("abs:data-lazy-src") - element.hasAttr("srcset") -> element.attr("abs:srcset").substringBefore(" ") + element.hasAttr("srcset") -> element.attr("abs:srcset").getSrcSetImage() element.hasAttr("data-cfsrc") -> element.attr("abs:data-cfsrc") else -> element.attr("abs:src") } } + /** + * Get the best image quality available from srcset + */ + private fun String.getSrcSetImage(): String? { + return this.split(" ") + .filter(URL_REGEX::matches) + .maxOfOrNull(String::toString) + } + /** * Set it to true if the source uses the new AJAX endpoint to * fetch the manga chapters instead of the old admin-ajax.php one. @@ -1106,6 +1115,7 @@ abstract class Madara( companion object { const val URL_SEARCH_PREFIX = "slug:" + val URL_REGEX = """^(https?://[^\s/$.?#].[^\s]*)${'$'}""".toRegex() } }