BokugenTranslation: Fix unable to connect and add ratelimit (#16322)

* Fix

* Change ratelimit

* Lint
This commit is contained in:
seew3l 2023-05-06 09:17:30 -05:00 committed by GitHub
parent 9c64f03b27
commit 2ce3cb6483
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -1,8 +1,20 @@
package eu.kanade.tachiyomi.extension.es.bokugentranslation 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.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.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
class BokugenTranslation : Madara( class BokugenTranslation : Madara(
"BokugenTranslation", "BokugenTranslation",
@ -10,5 +22,44 @@ class BokugenTranslation : Madara(
"es", "es",
dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("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<Application>())
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 override val useNewChapterEndpoint = true
} }

View File

@ -55,7 +55,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("Bichen Traduções", "https://bichentraducoes.com", "pt-BR", isNsfw = true, className = "BichenTraducoes"), 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("BL Manhwa Club", "https://blmanhwa.club", "pt-BR", isNsfw = true, className = "BlManhwaClub", overrideVersionCode = 2),
SingleLang("BlogManga", "https://blogmanga.net", "en"), 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("Boruto Explorer", "https://leitor.borutoexplorer.com.br", "pt-BR", overrideVersionCode = 1),
SingleLang("BoysLove", "https://boyslove.me", "en", isNsfw = true, overrideVersionCode = 3), 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), SingleLang("Café com Yaoi", "http://cafecomyaoi.com.br", "pt-BR", pkgName = "cafecomyaoi", className = "CafeComYaoi", isNsfw = true, overrideVersionCode = 1),