Manhua SY: Fix chapter pages and latest/popular manhua (#16376)

* Manhua SY: Fix chapter pages and latest/popular manhua

* reformat
This commit is contained in:
Slowlife 2023-05-10 20:44:20 +07:00 committed by GitHub
parent 54417b98ca
commit 18aed05f89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 1 deletions

View File

@ -0,0 +1,3 @@
dependencies {
implementation(project(':lib-cryptoaes'))
}

View File

@ -0,0 +1,53 @@
package eu.kanade.tachiyomi.extension.en.manhuasy
import android.util.Base64
import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES
import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.source.model.Page
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.jsoup.nodes.Document
class ManhuaSY : Madara("Manhua SY", "https://www.manhuasy.com", "en") {
override val mangaSubString = "manhua"
override fun pageListParse(document: Document): List<Page> {
val chapterProtector = document.getElementById("chapter-protector-data")?.html()
?: return super.pageListParse(document)
val password = chapterProtector
.substringAfter("wpmangaprotectornonce='")
.substringBefore("';")
val chapterData = json.parseToJsonElement(
chapterProtector
.substringAfter("chapter_data='")
.substringBefore("';")
.replace("\\/", "/"),
).jsonObject
val unsaltedCiphertext = Base64.decode(chapterData["ct"]!!.jsonPrimitive.content, Base64.DEFAULT)
val salt = chapterData["s"]!!.jsonPrimitive.content.decodeHex()
val ciphertext = SALTED + salt + unsaltedCiphertext
val rawImgArray = CryptoAES.decrypt(Base64.encodeToString(ciphertext, Base64.DEFAULT), password)
val imgArrayString = json.parseToJsonElement(rawImgArray).jsonPrimitive.content
val imgArray = json.parseToJsonElement(imgArrayString).jsonArray
return imgArray.mapIndexed { idx, it ->
Page(idx, document.location(), it.jsonPrimitive.content)
}
}
// https://stackoverflow.com/a/66614516
private fun String.decodeHex(): ByteArray {
check(length % 2 == 0) { "Must have an even length" }
return chunked(2)
.map { it.toInt(16).toByte() }
.toByteArray()
}
companion object {
val SALTED = "Salted__".toByteArray(Charsets.UTF_8)
}
}

View File

@ -273,7 +273,7 @@ class MadaraGenerator : ThemeSourceGenerator {
SingleLang("Manhua ES", "https://manhuaes.com", "en", overrideVersionCode = 6),
SingleLang("Manhua Kiss", "https://manhuakiss.com", "en", isNsfw = true, overrideVersionCode = 1),
SingleLang("Manhua Plus", "https://manhuaplus.com", "en", overrideVersionCode = 6),
SingleLang("Manhua SY", "https://www.manhuasy.com", "en", overrideVersionCode = 1),
SingleLang("Manhua SY", "https://www.manhuasy.com", "en", overrideVersionCode = 2),
SingleLang("ManhuaBox", "https://manhuabox.net", "en", overrideVersionCode = 2),
SingleLang("ManhuaChill", "https://manhuachill.com", "en"),
SingleLang("ManhuaFast", "https://manhuafast.com", "en", overrideVersionCode = 2),