From 18f3f9412fff10d41878e975141a34b9643e9451 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sat, 7 Aug 2021 12:56:03 -0300 Subject: [PATCH] Add another code to the blocking ones in TM. (#8443) --- src/pt/tsukimangas/build.gradle | 6 +++++- .../extension/pt/tsukimangas/TsukiMangas.kt | 16 +++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/pt/tsukimangas/build.gradle b/src/pt/tsukimangas/build.gradle index d9ebf8f7c..6d18fb0bd 100644 --- a/src/pt/tsukimangas/build.gradle +++ b/src/pt/tsukimangas/build.gradle @@ -6,10 +6,14 @@ ext { extName = 'Tsuki Mangás' pkgNameSuffix = 'pt.tsukimangas' extClass = '.TsukiMangas' - extVersionCode = 25 + extVersionCode = 26 libVersion = '1.2' containsNsfw = true } +dependencies { + implementation project(':lib-ratelimit') +} + apply from: "$rootDir/common.gradle" diff --git a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt index 4604ee051..c2f549525 100644 --- a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt +++ b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.extension.pt.tsukimangas import eu.kanade.tachiyomi.annotations.Nsfw +import eu.kanade.tachiyomi.lib.ratelimit.SpecificHostRateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.source.model.Filter @@ -26,6 +27,7 @@ import java.io.IOException import java.text.ParseException import java.text.SimpleDateFormat import java.util.Locale +import java.util.concurrent.TimeUnit @Nsfw class TsukiMangas : HttpSource() { @@ -40,6 +42,7 @@ class TsukiMangas : HttpSource() { override val client: OkHttpClient = network.cloudflareClient.newBuilder() .addInterceptor(::tsukiAuthIntercept) + .addInterceptor(SpecificHostRateLimitInterceptor(baseUrl.toHttpUrl(), 1, 1, TimeUnit.SECONDS)) .build() private val json: Json by injectLazy() @@ -47,6 +50,7 @@ class TsukiMangas : HttpSource() { override fun headersBuilder(): Headers.Builder = Headers.Builder() .add("Accept", ACCEPT) .add("Accept-Language", ACCEPT_LANGUAGE) + .add("Component", "157") .add("Referer", baseUrl) override fun popularMangaRequest(page: Int): Request { @@ -294,8 +298,8 @@ class TsukiMangas : HttpSource() { private fun tsukiAuthIntercept(chain: Interceptor.Chain): Response { val response = chain.proceed(chain.request()) - // API returns 403 or 1020 when User-Agent permission is disabled. - if (response.code == 403 || response.code == 1020) { + // API returns 403, 429 or 1020 when the extension is getting blocked. + if (BLOCKING_CODES.contains(response.code)) { response.close() throw IOException(UA_DISABLED_MESSAGE) } @@ -453,10 +457,12 @@ class TsukiMangas : HttpSource() { private const val ACCEPT_IMAGE = "image/avif,image/webp,image/apng,image/*,*/*;q=0.8" private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,gl;q=0.5" // By request of site owner. Detailed at Issue #4912 (in Portuguese). - private val USER_AGENT = "Tachiyomi " + System.getProperty("http.agent")!! + // private val USER_AGENT = "Tachiyomi " + System.getProperty("http.agent")!! - private val CDN_1_URL = "https://cdn1.tsukimangas.com".toHttpUrl() - private val CDN_2_URL = "https://cdn2.tsukimangas.com".toHttpUrl() + // private val CDN_1_URL = "https://cdn1.tsukimangas.com".toHttpUrl() + // private val CDN_2_URL = "https://cdn2.tsukimangas.com".toHttpUrl() + + private val BLOCKING_CODES = arrayOf(403, 429, 1020) private const val UA_DISABLED_MESSAGE = "O site está bloqueando o Tachiyomi. " + "Aguarde com que eles parem de bloquear ou migre para outras fontes."