From 2ce3cb64833e9a3b81bf2be7ff49c8731924564e Mon Sep 17 00:00:00 2001 From: seew3l <90949336+seew3l@users.noreply.github.com> Date: Sat, 6 May 2023 09:17:30 -0500 Subject: [PATCH] BokugenTranslation: Fix unable to connect and add ratelimit (#16322) * Fix * Change ratelimit * Lint --- .../src/BokugenTranslation.kt | 51 +++++++++++++++++++ .../multisrc/madara/MadaraGenerator.kt | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt b/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt index af2ea7f96..f45bd0d4b 100644 --- a/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt +++ b/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt @@ -1,8 +1,20 @@ package eu.kanade.tachiyomi.extension.es.bokugentranslation +import android.app.Application +import android.os.Handler +import android.os.Looper +import android.view.View +import android.webkit.WebChromeClient +import android.webkit.WebView import eu.kanade.tachiyomi.multisrc.madara.Madara +import eu.kanade.tachiyomi.network.interceptor.rateLimit +import okhttp3.OkHttpClient +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.Locale +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit class BokugenTranslation : Madara( "BokugenTranslation", @@ -10,5 +22,44 @@ class BokugenTranslation : Madara( "es", dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")), ) { + private var loadWebView = true + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .addInterceptor(uaIntercept) + .addInterceptor { chain -> + val request = chain.request() + val url = request.url.toString() + if (loadWebView) { + val handler = Handler(Looper.getMainLooper()) + val latch = CountDownLatch(1) + var webView: WebView? = null + handler.post { + val webview = WebView(Injekt.get()) + webView = webview + webview.settings.domStorageEnabled = true + webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null) + webview.settings.useWideViewPort = false + webview.settings.loadWithOverviewMode = false + + webview.webChromeClient = object : WebChromeClient() { + override fun onProgressChanged(view: WebView?, newProgress: Int) { + if (newProgress == 100) { + latch.countDown() + } + } + } + webview.loadUrl(url) + } + + latch.await() + loadWebView = false + handler.post { webView?.destroy() } + } + chain.proceed(request) + } + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .rateLimit(1, 1) + .build() + override val useNewChapterEndpoint = true } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt index b5ce64586..495be4480 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt @@ -55,7 +55,7 @@ class MadaraGenerator : ThemeSourceGenerator { SingleLang("Bichen Traduções", "https://bichentraducoes.com", "pt-BR", isNsfw = true, className = "BichenTraducoes"), SingleLang("BL Manhwa Club", "https://blmanhwa.club", "pt-BR", isNsfw = true, className = "BlManhwaClub", overrideVersionCode = 2), SingleLang("BlogManga", "https://blogmanga.net", "en"), - SingleLang("BokugenTranslation", "https://bokugents.com", "es"), + SingleLang("BokugenTranslation", "https://bokugents.com", "es", overrideVersionCode = 1), SingleLang("Boruto Explorer", "https://leitor.borutoexplorer.com.br", "pt-BR", overrideVersionCode = 1), SingleLang("BoysLove", "https://boyslove.me", "en", isNsfw = true, overrideVersionCode = 3), SingleLang("Café com Yaoi", "http://cafecomyaoi.com.br", "pt-BR", pkgName = "cafecomyaoi", className = "CafeComYaoi", isNsfw = true, overrideVersionCode = 1),