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 c1d5e32e8..2e49ebee3 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) + } +}