From 74283f6346304137a27dd3f4558d792d59e46dd9 Mon Sep 17 00:00:00 2001 From: IMXEren <96839938+IMXEren@users.noreply.github.com> Date: Fri, 10 Jul 2026 23:28:42 +0530 Subject: [PATCH 1/2] fix(madara): properly parse srcset with image descriptors (w/x suffixes) Refactored getSrcSetImage() to correctly handle comma-separated srcset entries with width (w) and pixel-density (x) descriptors. Previously the method used to compare URLs lexicographically, which breaks on srcset="link-34x68.jpg 34w, link-330x700.jpg 330w" and chooses link-34x68.jpg. Adds IMAGE_DESCRIPTOR_REGEX companion constant and prefers highest-resolution images by descriptor value, falling back to lexicographical URL comparison when no descriptors are present. --- lib-multisrc/madara/build.gradle.kts | 2 +- .../tachiyomi/multisrc/madara/Madara.kt | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib-multisrc/madara/build.gradle.kts b/lib-multisrc/madara/build.gradle.kts index 0c0cec9ae88..9236723d98f 100644 --- a/lib-multisrc/madara/build.gradle.kts +++ b/lib-multisrc/madara/build.gradle.kts @@ -8,7 +8,7 @@ dependencies { } keiyoushi { - baseVersionCode = 51 + baseVersionCode = 52 libVersion = "1.4" deeplink { 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 991a9791dba..b6d0453d8ee 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 @@ -824,9 +824,27 @@ abstract class Madara : HttpSource() { /** * Get the best image quality available from srcset */ - protected open fun String.getSrcSetImage(): String? = this.split(" ") - .filter(URL_REGEX::matches) - .maxOfOrNull(String::toString) + protected open fun String.getSrcSetImage(): String? { + val images = this.split(",") + .map { it.trim().split("\\s+".toRegex()) } + .filter { it.isNotEmpty() && URL_REGEX.matches(it[0]) } + + val imagesWithDescriptor = images + .filter { it.size == 2 } + .mapNotNull { candidate -> + IMAGE_DESCRIPTOR_REGEX.find(candidate[1])?.let { match -> + Pair(candidate[0], match.groupValues[1].toFloat()) + } + } + + // Prefer images with descriptors as to get the highest resolution + if (imagesWithDescriptor.isNotEmpty()) { + return imagesWithDescriptor.maxByOrNull { it.second }?.first + } + + // Fallback to lexicographical comparison of image URLs + return images.maxOfOrNull { it.first() } + } /** * Apply any additional processing to the thumbnail URL if needed. @@ -1170,6 +1188,7 @@ abstract class Madara : HttpSource() { companion object { const val URL_SEARCH_PREFIX = "slug:" val URL_REGEX = """^(https?://[^\s/$.?#].[^\s]*)${'$'}""".toRegex() + val IMAGE_DESCRIPTOR_REGEX = """^(\d+|\d+\.\d+)([wx])$""".toRegex() } } From b9bcd8e41b4b54000de1c480c0778bc9b289000c Mon Sep 17 00:00:00 2001 From: IMXEren <96839938+IMXEren@users.noreply.github.com> Date: Sat, 18 Jul 2026 21:25:15 +0530 Subject: [PATCH 2/2] refactor(madara): avoid recompiling whitespace regex and split by limit - Move the invariant regex to companion object - A source in srcset can either be URL or (URL, DESCRIPTOR; pair), so there's no need to split into no. of substrings more than 2. --- .../madara/src/eu/kanade/tachiyomi/multisrc/madara/Madara.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 b6d0453d8ee..19b7f7b1d90 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 @@ -826,7 +826,7 @@ abstract class Madara : HttpSource() { */ protected open fun String.getSrcSetImage(): String? { val images = this.split(",") - .map { it.trim().split("\\s+".toRegex()) } + .map { it.trim().split(WHITESPACE_REGEX, limit = 2) } .filter { it.isNotEmpty() && URL_REGEX.matches(it[0]) } val imagesWithDescriptor = images @@ -1188,6 +1188,7 @@ abstract class Madara : HttpSource() { companion object { const val URL_SEARCH_PREFIX = "slug:" val URL_REGEX = """^(https?://[^\s/$.?#].[^\s]*)${'$'}""".toRegex() + val WHITESPACE_REGEX = """\s+""".toRegex() val IMAGE_DESCRIPTOR_REGEX = """^(\d+|\d+\.\d+)([wx])$""".toRegex() } }