komiktap/id: added sucuriInterceptor (#454)
* komiktap/id: added sucuriInterceptor * fix --------- Co-authored-by: ghost <ghost@gmail.com>
This commit is contained in:
parent
53dd6255f2
commit
eb4c7f00be
|
@ -1,11 +1,47 @@
|
||||||
package eu.kanade.tachiyomi.extension.id.komiktap
|
package eu.kanade.tachiyomi.extension.id.komiktap
|
||||||
|
|
||||||
|
import app.cash.quickjs.QuickJs
|
||||||
import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia
|
import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia
|
||||||
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.Cookie
|
||||||
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Response
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class Komiktap : MangaThemesia("Komiktap", "https://komiktap.me", "id") {
|
class Komiktap : MangaThemesia("Komiktap", "https://komiktap.me", "id") {
|
||||||
override val client: OkHttpClient = super.client.newBuilder()
|
override val client = super.client.newBuilder().addInterceptor(::sucuriInterceptor).build()
|
||||||
.rateLimit(4)
|
|
||||||
.build()
|
// Taken from es/ManhwasNet
|
||||||
|
private fun sucuriInterceptor(chain: Interceptor.Chain): Response {
|
||||||
|
val request = chain.request()
|
||||||
|
val url = request.url
|
||||||
|
val response = try {
|
||||||
|
chain.proceed(request)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// Try to clear cookies and retry
|
||||||
|
client.cookieJar.saveFromResponse(url, emptyList())
|
||||||
|
val clearHeaders = request.headers.newBuilder().removeAll("Cookie").build()
|
||||||
|
chain.proceed(request.newBuilder().headers(clearHeaders).build())
|
||||||
|
}
|
||||||
|
if (response.headers["x-sucuri-cache"].isNullOrEmpty() && response.headers["x-sucuri-id"] != null && url.toString().startsWith(baseUrl)) {
|
||||||
|
val script = response.use { it.asJsoup() }.selectFirst("script")?.data()
|
||||||
|
|
||||||
|
if (script != null) {
|
||||||
|
val patchedScript = script.split("(r)")[0].dropLast(1) + "r=r.replace('document.cookie','cookie');"
|
||||||
|
QuickJs.create().use {
|
||||||
|
val result = (it.evaluate(patchedScript) as String)
|
||||||
|
.replace("location.", "")
|
||||||
|
.replace("reload();", "")
|
||||||
|
val sucuriCookie = (it.evaluate(result) as String).split("=", limit = 2)
|
||||||
|
val cookieName = sucuriCookie.first()
|
||||||
|
val cookieValue = sucuriCookie.last().replace(";path", "")
|
||||||
|
client.cookieJar.saveFromResponse(url, listOf(Cookie.parse(url, "$cookieName=$cookieValue")!!))
|
||||||
|
}
|
||||||
|
val newResponse = chain.proceed(request)
|
||||||
|
if (!newResponse.headers["x-sucuri-cache"].isNullOrEmpty()) return newResponse
|
||||||
|
}
|
||||||
|
throw IOException("Situs yang dilindungi - Buka di WebView untuk mencoba membuka blokir.")
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator {
|
||||||
SingleLang("KomikMama", "https://komikmama.co", "id", overrideVersionCode = 1),
|
SingleLang("KomikMama", "https://komikmama.co", "id", overrideVersionCode = 1),
|
||||||
SingleLang("KomikManhwa", "https://komikmanhwa.me", "id", isNsfw = true),
|
SingleLang("KomikManhwa", "https://komikmanhwa.me", "id", isNsfw = true),
|
||||||
SingleLang("Komiksan", "https://komiksan.link", "id", overrideVersionCode = 2),
|
SingleLang("Komiksan", "https://komiksan.link", "id", overrideVersionCode = 2),
|
||||||
SingleLang("Komiktap", "https://komiktap.me", "id", isNsfw = true),
|
SingleLang("Komiktap", "https://komiktap.me", "id", isNsfw = true, overrideVersionCode = 1),
|
||||||
SingleLang("Komiku.com", "https://komiku.com", "id", className = "KomikuCom"),
|
SingleLang("Komiku.com", "https://komiku.com", "id", className = "KomikuCom"),
|
||||||
SingleLang("Kuma Scans (Kuma Translation)", "https://kumascans.com", "en", className = "KumaScans", overrideVersionCode = 1),
|
SingleLang("Kuma Scans (Kuma Translation)", "https://kumascans.com", "en", className = "KumaScans", overrideVersionCode = 1),
|
||||||
SingleLang("KumaPoi", "https://kumapoi.info", "id", isNsfw = true, overrideVersionCode = 3),
|
SingleLang("KumaPoi", "https://kumapoi.info", "id", isNsfw = true, overrideVersionCode = 3),
|
||||||
|
|
Loading…
Reference in New Issue