parent
3eb426c197
commit
e91a347360
|
@ -1,7 +1,7 @@
|
||||||
ext {
|
ext {
|
||||||
extName = 'Manhwas.net'
|
extName = 'Manhwas.net'
|
||||||
extClass = '.ManhwasNet'
|
extClass = '.ManhwasNet'
|
||||||
extVersionCode = 11
|
extVersionCode = 12
|
||||||
isNsfw = true
|
isNsfw = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
package eu.kanade.tachiyomi.extension.es.manhwasnet
|
package eu.kanade.tachiyomi.extension.es.manhwasnet
|
||||||
|
|
||||||
import app.cash.quickjs.QuickJs
|
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||||
import eu.kanade.tachiyomi.source.model.Filter
|
import eu.kanade.tachiyomi.source.model.Filter
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
import eu.kanade.tachiyomi.source.model.FilterList
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||||
import eu.kanade.tachiyomi.util.asJsoup
|
|
||||||
import okhttp3.Cookie
|
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.Interceptor
|
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import java.io.IOException
|
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
@ -27,45 +22,10 @@ class ManhwasNet : ParsedHttpSource() {
|
||||||
override val name: String = "Manhwas.net"
|
override val name: String = "Manhwas.net"
|
||||||
override val supportsLatest: Boolean = true
|
override val supportsLatest: Boolean = true
|
||||||
|
|
||||||
override val client = network.client.newBuilder()
|
override val client = network.cloudflareClient.newBuilder()
|
||||||
.connectTimeout(60, TimeUnit.SECONDS)
|
.rateLimitHost(baseUrl.toHttpUrl(), 3, 1, TimeUnit.SECONDS)
|
||||||
.writeTimeout(60, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(60, TimeUnit.SECONDS)
|
|
||||||
.addInterceptor { sucuriInterceptor(it) }
|
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
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("Sitio protegido - Abra en WebView para intentar desbloquear.")
|
|
||||||
}
|
|
||||||
return response
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun headersBuilder() = super.headersBuilder()
|
override fun headersBuilder() = super.headersBuilder()
|
||||||
.set("Referer", "$baseUrl/")
|
.set("Referer", "$baseUrl/")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue