From 21b63c1d77b6a4588d3d0eb6ef90b9a95c640467 Mon Sep 17 00:00:00 2001 From: dragonx943 Date: Tue, 2 Sep 2025 21:27:10 +0700 Subject: [PATCH] TruyenQQ: Add delay to avoid rate limit --- .../kotatsu/parsers/site/vi/TruyenQQ.kt | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/TruyenQQ.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/TruyenQQ.kt index e412b8b8..af28f457 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/TruyenQQ.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/TruyenQQ.kt @@ -1,5 +1,8 @@ package org.koitharu.kotatsu.parsers.site.vi +import kotlinx.coroutines.delay +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import org.koitharu.kotatsu.parsers.MangaLoaderContext import org.koitharu.kotatsu.parsers.MangaSourceParser import org.koitharu.kotatsu.parsers.config.ConfigKey @@ -10,7 +13,8 @@ import java.text.SimpleDateFormat import java.util.* @MangaSourceParser("TRUYENQQ", "TruyenQQ", "vi") -internal class TruyenQQ(context: MangaLoaderContext) : PagedMangaParser(context, MangaParserSource.TRUYENQQ, 42) { +internal class TruyenQQ(context: MangaLoaderContext): + PagedMangaParser(context, MangaParserSource.TRUYENQQ, 42) { override val configKeyDomain = ConfigKey.Domain("truyenqqgo.com") @@ -189,6 +193,15 @@ internal class TruyenQQ(context: MangaLoaderContext) : PagedMangaParser(context, } override suspend fun getPages(chapter: MangaChapter): List { + // Apply rate limiting specifically for fetching pages + pagesRequestMutex.withLock { + val currentTime = System.currentTimeMillis() + val timeSinceLastRequest = currentTime - lastPagesRequestTime + if (timeSinceLastRequest < PAGES_REQUEST_DELAY_MS) { + delay(PAGES_REQUEST_DELAY_MS - timeSinceLastRequest) + } + lastPagesRequestTime = System.currentTimeMillis() + } val fullUrl = chapter.url.toAbsoluteUrl(domain) val doc = webClient.httpGet(fullUrl).parseHtml() val root = doc.body().selectFirstOrThrow(".chapter_content") @@ -203,4 +216,10 @@ internal class TruyenQQ(context: MangaLoaderContext) : PagedMangaParser(context, ) } } + + companion object { + private const val PAGES_REQUEST_DELAY_MS = 5000L + private val pagesRequestMutex = Mutex() + private var lastPagesRequestTime = 0L + } }