LeerCapitulo: Fix script not found (#4627)

* hope is not a catandmouse game

* unused import

* no rebuild

Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com>

* cache url

* change to reorder

* lel i added the script to the last

---------

Co-authored-by: Vetle Ledaal <vetle.ledaal@gmail.com>
This commit is contained in:
bapeey 2024-08-14 23:18:06 -05:00 committed by Draff
parent 4fe3fbd9c3
commit 94829063c1
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 32 additions and 11 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'LeerCapitulo'
extClass = '.LeerCapitulo'
extVersionCode = 9
extVersionCode = 10
}
apply from: "$rootDir/common.gradle"

View File

@ -33,10 +33,12 @@ class LeerCapitulo : ParsedHttpSource() {
override val baseUrl = "https://www.leercapitulo.co"
override val client = super.client.newBuilder()
override val client = network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 1, 3)
.build()
private val notRateLimitClient = network.cloudflareClient
override fun headersBuilder() = super.headersBuilder()
.add("Referer", "$baseUrl/")
@ -168,28 +170,41 @@ class LeerCapitulo : ParsedHttpSource() {
}
}
private var cachedScriptUrl: String? = null
override fun pageListParse(document: Document): List<Page> {
val orderList = document.selectFirst("meta[property=ad:check]")?.attr("content")
?.replace("[^\\d]+".toRegex(), "-")
?.replace(ORDER_LIST_REGEX, "-")
?.split("-")
val useReversedString = orderList?.any { it == "01" }
val arrayData = document.selectFirst("#array_data")!!.text()
val scriptUrl = document.selectFirst("section.bodycontainer > script[src$=.js]")?.attr("abs:src")
?: throw Exception("Script not found")
val scripts = document.select("head > script[src^=/assets/][src$=.js]").map { it.attr("abs:src") }.reversed().toMutableList()
val scriptData = client.newCall(GET(scriptUrl, headers)).execute().body.string()
var dataScript: String? = null
cachedScriptUrl?.let {
if (scripts.remove(it)) {
scripts.add(0, it)
}
}
for (scriptUrl in scripts) {
val scriptData = notRateLimitClient.newCall(GET(scriptUrl, headers)).execute().body.string()
val deobfuscatedScript = Deobfuscator.deobfuscateScript(scriptData)
?: throw Exception("Unable to deobfuscate script")
if (deobfuscatedScript != null && deobfuscatedScript.contains("#array_data")) {
dataScript = deobfuscatedScript
cachedScriptUrl = scriptUrl
break
}
}
val keyRegex = """'([A-Z0-9]{62})'""".toRegex(RegexOption.IGNORE_CASE)
if (dataScript == null) throw Exception("Unable to find the script")
val (key1, key2) = keyRegex.findAll(deobfuscatedScript).map { it.groupValues[1] }.toList()
val (key1, key2) = KEY_REGEX.findAll(dataScript).map { it.groupValues[1] }.toList()
val encodedUrls = arrayData.replace(Regex("[A-Z0-9]", RegexOption.IGNORE_CASE)) {
val encodedUrls = arrayData.replace(DECODE_REGEX) {
val index = key2.indexOf(it.value)
key1[index].toString()
}
@ -228,4 +243,10 @@ class LeerCapitulo : ParsedHttpSource() {
val link: String,
val thumbnail: String,
)
companion object {
private val ORDER_LIST_REGEX = "[^\\d]+".toRegex()
private val KEY_REGEX = """'([A-Z0-9]{62})'""".toRegex(RegexOption.IGNORE_CASE)
private val DECODE_REGEX = Regex("[A-Z0-9]", RegexOption.IGNORE_CASE)
}
}