From 1883e7a8891ec67c8d059a0f6faa743f00fe70c2 Mon Sep 17 00:00:00 2001 From: AlphaBoom <30779939+AlphaBoom@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:15:43 +0800 Subject: [PATCH] Sixmanhua: Fix page parsing (#4989) --- src/zh/sixmh/build.gradle | 2 +- .../tachiyomi/extension/zh/sixmh/Crypto.kt | 18 ++++++++++++++++++ .../tachiyomi/extension/zh/sixmh/Image.kt | 6 ++++++ .../tachiyomi/extension/zh/sixmh/SixMH.kt | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Crypto.kt create mode 100644 src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Image.kt diff --git a/src/zh/sixmh/build.gradle b/src/zh/sixmh/build.gradle index 7576c816e..50a55f97c 100644 --- a/src/zh/sixmh/build.gradle +++ b/src/zh/sixmh/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.SixMH' themePkg = 'mccms' baseUrl = 'https://www.liumanhua.com' - overrideVersionCode = 4 + overrideVersionCode = 5 } apply from: "$rootDir/common.gradle" diff --git a/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Crypto.kt b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Crypto.kt new file mode 100644 index 000000000..9f9a1092a --- /dev/null +++ b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Crypto.kt @@ -0,0 +1,18 @@ +package eu.kanade.tachiyomi.extension.zh.sixmh + +import android.util.Base64 +import kotlin.experimental.xor + +private val keys = arrayOf("Ni1iWGQ5aU4=", "Ni1SWHlqcnk=", "Ni1vWXZ3Vnk=", "Ni00Wlk1N1U=", "Ni1tYkpwVTc=", "Ni02TU0yRWk=", "Ni01NFRpUXI=", "Ni1QaDV4eDk=", "Ni1iWWdlUFI=", "Ni1aOUEzYlc=") + +internal fun decodeData(encodedData: String, cid: Int): String { + val key = Base64.decode(keys[cid % keys.size], Base64.DEFAULT) + val keyLength = key.size + val decodedData = Base64.decode(encodedData, Base64.DEFAULT) + val decryptedData = StringBuilder() + for (i in decodedData.indices) { + val decryptedCharCode = decodedData[i] xor key[i % keyLength] + decryptedData.appendCodePoint(decryptedCharCode.toInt()) + } + return Base64.decode(decryptedData.toString(), Base64.DEFAULT).decodeToString() +} diff --git a/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Image.kt b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Image.kt new file mode 100644 index 000000000..967d8ebe7 --- /dev/null +++ b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/Image.kt @@ -0,0 +1,6 @@ +package eu.kanade.tachiyomi.extension.zh.sixmh + +import kotlinx.serialization.Serializable + +@Serializable +data class Image(val id: String, val url: String) diff --git a/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt index 836eb1858..70b669ae5 100644 --- a/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt +++ b/src/zh/sixmh/src/eu/kanade/tachiyomi/extension/zh/sixmh/SixMH.kt @@ -3,13 +3,19 @@ package eu.kanade.tachiyomi.extension.zh.sixmh import android.app.Application import android.os.Build import eu.kanade.tachiyomi.multisrc.mccms.MCCMS +import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import okhttp3.Response import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import uy.kohesive.injekt.injectLazy class SixMH : MCCMS("六漫画", "https://www.liumanhua.com") { - + private val dataRegex = Regex("var DATA = '([A-Za-z0-9+/=]+)'") + private val json by injectLazy() override val versionId get() = 2 init { @@ -21,4 +27,12 @@ class SixMH : MCCMS("六漫画", "https://www.liumanhua.com") { override fun getMangaUrl(manga: SManga) = "https://m.liumanhua.com" + manga.url override fun getChapterUrl(chapter: SChapter) = "https://m.liumanhua.com" + chapter.url + + override fun pageListParse(response: Response): List { + val encodedData = dataRegex.find(response.body.string())?.groupValues?.get(1) ?: "" + val cid = response.request.url.pathSegments.last().removeSuffix(".html").toIntOrNull() ?: 0 + val decodedData = decodeData(encodedData, cid) + val images = json.decodeFromString>(decodedData) + return images.mapIndexed { index, image -> Page(index, imageUrl = image.url) } + } }