Koushoku: bypass block (#12913)
This commit is contained in:
parent
16529bc29d
commit
a022f69c89
|
@ -5,7 +5,7 @@ ext {
|
|||
extName = 'Koushoku'
|
||||
pkgNameSuffix = 'en.koushoku'
|
||||
extClass = '.Koushoku'
|
||||
extVersionCode = 13
|
||||
extVersionCode = 14
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package eu.kanade.tachiyomi.extension.en.koushoku
|
||||
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
class GoogleTranslateInterceptor : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
|
||||
return if (request.url.host == "koushoku.org") {
|
||||
val newUrl = googlify(request.url)
|
||||
val newRequest = request.newBuilder()
|
||||
.url(newUrl)
|
||||
.build()
|
||||
|
||||
chain.proceed(newRequest)
|
||||
} else {
|
||||
chain.proceed(request)
|
||||
}
|
||||
}
|
||||
|
||||
private fun googlify(url: HttpUrl): HttpUrl {
|
||||
val newHost = url.host
|
||||
.replace("-", "--")
|
||||
.replace('.', '-')
|
||||
.plus(".translate.goog")
|
||||
|
||||
return url.newBuilder()
|
||||
.host(newHost)
|
||||
// `_x_tr_sl` and `_x_tr_tl` must be different
|
||||
.addQueryParameter("_x_tr_sl", "en")
|
||||
.addQueryParameter("_x_tr_tl", "jp")
|
||||
.addQueryParameter("_x_tr_hl", "en")
|
||||
.build()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package eu.kanade.tachiyomi.extension.en.koushoku
|
||||
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
class GoogleTranslateNetworkInterceptor : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
|
||||
if (
|
||||
response.request.url.host == "koushoku-org.translate.goog" &&
|
||||
response.request.url.pathSegments.getOrNull(0) == "d" &&
|
||||
response.code in 300..399
|
||||
) {
|
||||
val newUrl = degooglify(response.headers["Location"]!!.toHttpUrl())
|
||||
|
||||
return response.newBuilder()
|
||||
.header("Location", newUrl.toString())
|
||||
.build()
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
private fun degooglify(url: HttpUrl): HttpUrl {
|
||||
val newHost = url.host
|
||||
.substringBeforeLast(".translate.goog")
|
||||
.replace('-', '.')
|
||||
.replace("..", "-")
|
||||
|
||||
return url.newBuilder()
|
||||
.host(newHost)
|
||||
.removeAllQueryParameters("_x_tr_sl")
|
||||
.removeAllQueryParameters("_x_tr_tl")
|
||||
.removeAllQueryParameters("_x_tr_hl")
|
||||
.build()
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.extension.en.koushoku
|
|||
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
|
@ -38,8 +38,9 @@ class Koushoku : ParsedHttpSource() {
|
|||
override val supportsLatest = true
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
||||
.addInterceptor(KoushokuWebViewInterceptor())
|
||||
.rateLimit(1, 4)
|
||||
.addInterceptor(GoogleTranslateInterceptor())
|
||||
.addNetworkInterceptor(GoogleTranslateNetworkInterceptor())
|
||||
.rateLimitHost("https://ksk-h7glm2.xyz".toHttpUrl(), 1)
|
||||
.build()
|
||||
|
||||
override fun headersBuilder(): Headers.Builder = super.headersBuilder()
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
package eu.kanade.tachiyomi.extension.en.koushoku
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
class KoushokuWebViewInterceptor : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
val response = chain.proceed(request)
|
||||
|
||||
if (response.headers("Content-Type").any { it.contains("text/html") }) {
|
||||
val responseBody = response.peekBody(1 * 1024 * 1024).string()
|
||||
if (response.code == 403) {
|
||||
val document = Jsoup.parse(responseBody)
|
||||
if (document.selectFirst("h1")?.text()?.contains(Regex("banned$")) == true) {
|
||||
throw IOException("You have been banned. Check WebView for details.")
|
||||
}
|
||||
}
|
||||
|
||||
if (response.networkResponse != null) {
|
||||
try {
|
||||
proceedWithWebView(response, responseBody)
|
||||
} catch (e: Exception) {
|
||||
throw IOException(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
private fun proceedWithWebView(response: Response, responseBody: String) {
|
||||
val latch = CountDownLatch(1)
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
handler.post {
|
||||
val webView = WebView(Injekt.get<Application>())
|
||||
with(webView.settings) {
|
||||
loadsImagesAutomatically = false
|
||||
userAgentString = response.request.header("User-Agent")
|
||||
}
|
||||
|
||||
webView.webViewClient = object : WebViewClient() {
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
webView.stopLoading()
|
||||
webView.destroy()
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
|
||||
webView.loadDataWithBaseURL(
|
||||
response.request.url.toString(),
|
||||
responseBody,
|
||||
"text/html",
|
||||
"utf-8",
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
latch.await()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue