parent
21726a05ab
commit
f8c6f9f350
@ -5,7 +5,7 @@ ext {
|
||||
extName = 'Manhwas.net'
|
||||
pkgNameSuffix = 'es.manhwasnet'
|
||||
extClass = '.ManhwasNet'
|
||||
extVersionCode = 8
|
||||
extVersionCode = 9
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package eu.kanade.tachiyomi.extension.es.manhwasnet
|
||||
|
||||
import android.webkit.CookieManager
|
||||
import app.cash.quickjs.QuickJs
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
@ -11,14 +10,15 @@ import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import okhttp3.Cookie
|
||||
import okhttp3.CookieJar
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import java.io.IOException
|
||||
import java.util.Calendar
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class ManhwasNet : ParsedHttpSource() {
|
||||
|
||||
@ -27,47 +27,45 @@ class ManhwasNet : ParsedHttpSource() {
|
||||
override val name: String = "Manhwas.net"
|
||||
override val supportsLatest: Boolean = true
|
||||
|
||||
private val cookieManager by lazy { CookieManager.getInstance() }
|
||||
|
||||
override val client = network.client.newBuilder()
|
||||
.addInterceptor { chain ->
|
||||
val request = chain.request()
|
||||
val url = request.url.toString()
|
||||
val response = chain.proceed(request)
|
||||
if (response.headers["x-sucuri-cache"].isNullOrEmpty() && url.startsWith(baseUrl) && response.headers["x-sucuri-id"] != null) {
|
||||
val script = response.asJsoup().selectFirst("script")?.data()
|
||||
if (script != null) {
|
||||
val a = script.split("(r)")[0].dropLast(1) + "r=r.replace('document.cookie','cookie');"
|
||||
QuickJs.create().use {
|
||||
val b = it.evaluate(a) as String
|
||||
val sucuriCookie = it.evaluate(b.replace("location.", "").replace("reload();", "")) as String
|
||||
val cookieName = sucuriCookie.split("=")[0]
|
||||
val cookieValue = sucuriCookie.split("=")[1].replace(";path", "")
|
||||
cookieManager.setCookie(url, "$cookieName=$cookieValue")
|
||||
}
|
||||
val newResponse = chain.proceed(request)
|
||||
if (!newResponse.headers["x-sucuri-cache"].isNullOrEmpty()) return@addInterceptor newResponse
|
||||
}
|
||||
throw IOException("Sitio protegido - Abra en WebView para intentar desbloquear.")
|
||||
}
|
||||
return@addInterceptor response
|
||||
}
|
||||
.cookieJar(
|
||||
object : CookieJar {
|
||||
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) =
|
||||
cookies.filter { it.matches(url) }.forEach {
|
||||
cookieManager.setCookie(url.toString(), it.toString())
|
||||
}
|
||||
|
||||
override fun loadForRequest(url: HttpUrl) =
|
||||
cookieManager.getCookie(url.toString())?.split("; ")
|
||||
?.mapNotNull { Cookie.parse(url, it) } ?: emptyList()
|
||||
},
|
||||
)
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.addInterceptor { sucuriInterceptor(it) }
|
||||
.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.asJsoup().selectFirst("script")?.data()
|
||||
if (script != null) {
|
||||
val a = script.split("(r)")[0].dropLast(1) + "r=r.replace('document.cookie','cookie');"
|
||||
QuickJs.create().use {
|
||||
val b = it.evaluate(a) as String
|
||||
val sucuriCookie = it.evaluate(b.replace("location.", "").replace("reload();", "")) as String
|
||||
val cookieName = sucuriCookie.split("=")[0]
|
||||
val cookieValue = sucuriCookie.split("=")[1].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()
|
||||
.add("Referer", "$baseUrl/")
|
||||
.set("Referer", "$baseUrl/")
|
||||
|
||||
override fun popularMangaRequest(page: Int): Request {
|
||||
val url = "$baseUrl/biblioteca".toHttpUrlOrNull()!!.newBuilder()
|
||||
|
Loading…
x
Reference in New Issue
Block a user