From 3785fe1c02860ab7e8a6a7e3d1a6c8b5d693304e Mon Sep 17 00:00:00 2001 From: Kazora Date: Sat, 19 Aug 2023 21:56:05 +0700 Subject: [PATCH] Kemono: Add option to load low resolution image in settings (#17556) * Kemono: Add option to load low resolution image * Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt * Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt * Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> * Fix trailing space * Update multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> --------- Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com> --- .../tachiyomi/multisrc/kemono/Kemono.kt | 21 +++++++++++++++++++ .../multisrc/kemono/KemonoGenerator.kt | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt index 31eba715f..a64a8ac7a 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/Kemono.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.multisrc.kemono import android.app.Application import androidx.preference.ListPreference import androidx.preference.PreferenceScreen +import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.source.ConfigurableSource @@ -185,6 +186,18 @@ open class Kemono( return post[0].images.mapIndexed { i, path -> Page(i, imageUrl = baseUrl + path) } } + override fun imageRequest(page: Page): Request { + val imageUrl = page.imageUrl!! + if (!preferences.getBoolean(USE_LOW_RES_IMG, false)) return GET(imageUrl, headers) + val index = imageUrl.indexOf('/', startIndex = 8) // https:// + val url = buildString { + append(imageUrl, 0, index) + append("/thumbnail") + append(imageUrl, index, imageUrl.length) + } + return GET(url, headers) + } + override fun imageUrlParse(response: Response) = throw UnsupportedOperationException() private inline fun Response.parseAs(): T = use { @@ -211,6 +224,13 @@ open class Kemono( entryValues = mirrorUrls setDefaultValue(defaultUrl) }.let(screen::addPreference) + + SwitchPreferenceCompat(screen.context).apply { + key = USE_LOW_RES_IMG + title = "Use low resolution images" + summary = "Reduce load time significantly. When turning off, clear chapter cache to remove cached low resolution images." + setDefaultValue(false) + }.let(screen::addPreference) } companion object { @@ -225,5 +245,6 @@ open class Kemono( private fun List.filterUnsupported() = filterNot { it.author == "Discord" } private const val BASE_URL_PREF = "BASE_URL" + private const val USE_LOW_RES_IMG = "USE_LOW_RES_IMG" } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt index 5084ff25d..2043a0e90 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/kemono/KemonoGenerator.kt @@ -9,7 +9,7 @@ class KemonoGenerator : ThemeSourceGenerator { override val themePkg = "kemono" - override val baseVersionCode = 6 + override val baseVersionCode = 7 override val sources = listOf( SingleLang("Kemono", "https://kemono.party", "all", isNsfw = true),