From 7c7553dec1e99ad755c8a295ecc7bac7aa5d2018 Mon Sep 17 00:00:00 2001 From: Vetle Ledaal Date: Sat, 1 Feb 2025 13:47:44 +0100 Subject: [PATCH] Hitomi: refresh expiring page URLs (#7440) --- src/all/hitomi/build.gradle | 2 +- .../tachiyomi/extension/all/hitomi/Hitomi.kt | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/all/hitomi/build.gradle b/src/all/hitomi/build.gradle index aeb76e8df..1b1252bc3 100644 --- a/src/all/hitomi/build.gradle +++ b/src/all/hitomi/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Hitomi' extClass = '.HitomiFactory' - extVersionCode = 35 + extVersionCode = 36 isNsfw = true } diff --git a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt index 3d838a28d..b76e34c85 100644 --- a/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt +++ b/src/all/hitomi/src/eu/kanade/tachiyomi/extension/all/hitomi/Hitomi.kt @@ -64,8 +64,11 @@ class Hitomi( private val json: Json by injectLazy() + private val REGEX_IMAGE_URL = """https://.*?a\.$domain/(jxl|avif|webp)/\d+?/\d+/([0-9a-f]{64})\.\1""".toRegex() + override val client = network.cloudflareClient.newBuilder() .addInterceptor(::jxlContentTypeInterceptor) + .addInterceptor(::updateImageUrlInterceptor) .apply { interceptors().add(0, ::streamResetRetry) } @@ -748,6 +751,25 @@ class Hitomi( } } + private fun updateImageUrlInterceptor(chain: Interceptor.Chain): Response { + val request = chain.request() + + val cleanUrl = request.url.run { "$scheme://$host$encodedPath" } + REGEX_IMAGE_URL.matchEntire(cleanUrl)?.let { match -> + val (ext, hash) = match.destructured + + val commonId = runBlocking { commonImageId() } + val imageId = imageIdFromHash(hash) + val subDomain = 'a' + runBlocking { subdomainOffset(imageId) } + + val newUrl = "https://${subDomain}a.$domain/$ext/$commonId$imageId/$hash.$ext" + val newRequest = request.newBuilder().url(newUrl).build() + return chain.proceed(newRequest) + } + + return chain.proceed(request) + } + override fun popularMangaParse(response: Response) = throw UnsupportedOperationException() override fun popularMangaRequest(page: Int) = throw UnsupportedOperationException() override fun latestUpdatesRequest(page: Int) = throw UnsupportedOperationException()