From 95fcbd44fd2086d9dea4d631c66a472445192b36 Mon Sep 17 00:00:00 2001 From: Draken Date: Mon, 5 May 2025 14:22:59 +0000 Subject: [PATCH] [Kiutaku] Debug attempt 1 --- .github/summary.yaml | 2 +- .../parsers/site/gallery/all/Kiutaku.kt | 45 +++++++++++++++---- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/.github/summary.yaml b/.github/summary.yaml index 9aaea001..2179c1ad 100644 --- a/.github/summary.yaml +++ b/.github/summary.yaml @@ -1 +1 @@ -total: 1220 +total: 1220 \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/gallery/all/Kiutaku.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/gallery/all/Kiutaku.kt index c1d5e32e..2e49ebee 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/gallery/all/Kiutaku.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/gallery/all/Kiutaku.kt @@ -1,15 +1,42 @@ package org.koitharu.kotatsu.parsers.site.gallery.all -import org.koitharu.kotatsu.parsers.MangaLoaderContext -import org.koitharu.kotatsu.parsers.MangaSourceParser -import org.koitharu.kotatsu.parsers.model.MangaParserSource -import org.koitharu.kotatsu.parsers.config.ConfigKey -import org.koitharu.kotatsu.parsers.model.ContentType -import org.koitharu.kotatsu.parsers.model.MangaListFilterOptions +import okhttp3.Interceptor +import okhttp3.Request +import okhttp3.Response +import kotlinx.coroutines.* +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock +import org.koitharu.kotatsu.parsers.* +import org.koitharu.kotatsu.parsers.model.* import org.koitharu.kotatsu.parsers.site.gallery.GalleryParser -import org.koitharu.kotatsu.parsers.Broken -@Broken("Blocked by Cloudflare") @MangaSourceParser("KIUTAKU", "Kiutaku", type = ContentType.OTHER) internal class Kiutaku(context: MangaLoaderContext) : - GalleryParser(context, MangaParserSource.KIUTAKU, "kiutaku.com") + GalleryParser(context, MangaParserSource.KIUTAKU, "kiutaku.com") { + + companion object { + private val mutex = Mutex() + private var lastImageRequestTime = 0L + private val IMAGE_EXTENSIONS = listOf(".jpg", ".jpeg", ".png", ".webp") + } + + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + val url = request.url.toString() + + if (IMAGE_EXTENSIONS.any { url.endsWith(it, ignoreCase = true) }) { + runBlocking { + mutex.withLock { + val now = System.currentTimeMillis() + val wait = 500L - (now - lastImageRequestTime) + if (wait > 0) { + delay(wait) + } + lastImageRequestTime = System.currentTimeMillis() + } + } + } + + return chain.proceed(request) + } +}