From 1280a1f40613c0e33eb4f5ad0da5967efc718491 Mon Sep 17 00:00:00 2001 From: mao09 <71811256+mao09@users.noreply.github.com> Date: Sat, 7 Jan 2023 00:17:28 +0900 Subject: [PATCH] MangaRawRU: fix page order (#14790) * fix page order * fix when imageList is empty. --- .../mangarawru/src/ImageListParser.kt | 128 ++++++++++++++++++ .../mangaraw/mangarawru/src/MangaRawRU.kt | 11 ++ .../multisrc/mangaraw/MangaRawGenerator.kt | 2 +- 3 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 multisrc/overrides/mangaraw/mangarawru/src/ImageListParser.kt diff --git a/multisrc/overrides/mangaraw/mangarawru/src/ImageListParser.kt b/multisrc/overrides/mangaraw/mangarawru/src/ImageListParser.kt new file mode 100644 index 000000000..57f943b56 --- /dev/null +++ b/multisrc/overrides/mangaraw/mangarawru/src/ImageListParser.kt @@ -0,0 +1,128 @@ +package eu.kanade.tachiyomi.extension.ja.mangarawru + +import kotlin.math.pow + +class ImageListParser( + html: String, + private val position: Int, + private val keys: String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", + private val pattern: String = """'BYFxAcGcC4.*?'""" +) { + + private val code: String + init { + code = getCode(html) + } + + fun getImageList(): List? { + val charMap = mutableMapOf() + for (j in 0..2) { + charMap[j] = j.toString() + } + + val data = Data(getValue(0), position, 1) + charMap[3] = when (getCharCode(data, position, 4)) { + 0 -> charCodeToString(getCharCode(data, position, 256)) + 1 -> charCodeToString(getCharCode(data, position, 65536)) + 2 -> return null + else -> null + } + + val imageCharList = mutableListOf(charMap[3]) + + var counter = 4 + var charaIndexCounter = 4 + var n = 3.0 + var cash = charMap[3] + while (data.index <= code.length) { + val max = 2.0.pow(n).toInt() + + val charIndex = when (val charCode = getCharCode(data, position, max)) { + 0 -> { + charMap[charaIndexCounter] = charCodeToString(getCharCode(data, position, 256)) + counter-- + charaIndexCounter++ + } + 1 -> { + charMap[charaIndexCounter] = charCodeToString(getCharCode(data, position, 65536)) + counter-- + charaIndexCounter++ + } + 2 -> { + return imageCharList.joinToString("").split(",") + } + else -> { + charCode + } + } + + val char = if (!charMap[charIndex].isNullOrEmpty()) { + charMap[charIndex]!! + } else if (charIndex != charaIndexCounter) { + return null + } else { + cash + cash?.charAt(0) + } + + if (counter == 0) { + counter = 2.0.pow(n++).toInt() + } + + imageCharList.add(char) + + charMap[charaIndexCounter++] = cash + char.charAt(0) + counter-- + cash = char + if (counter == 0) { + counter = 2.0.pow(n++).toInt() + } + } + + return null + } + + private data class Data(var value: Int, var position: Int, var index: Int) + + private fun getCharCode(data: Data, position: Int, max: Int): Int { + var charIndex = 0 + + var i = 1 + while (i != max) { + val tmp = data.value and data.position + data.position = data.position shr 1 + if (data.position == 0) { + data.position = position + data.value = getValue(data.index++) + } + + charIndex = charIndex or ((if (tmp > 0) 1 else 0) * i) + i = i shl 1 + } + + return charIndex + } + + fun getValue(index: Int): Int { + return getValueByChar(code.charAt(index)) + } + + private fun getCode(html: String): String { + val regex = Regex(pattern) + return regex.find(html)!!.value.replace("'", "").replace("\\", "").replace("u002b", "+") + } + + private fun getValueByChar(char: String): Int { + return keys.indexOf(char) + } + + companion object { + + private fun String.charAt(index: Int): String { + return substring(index, index + 1) + } + + private fun charCodeToString(charCode: Int): String { + return charCode.toChar().toString() + } + } +} diff --git a/multisrc/overrides/mangaraw/mangarawru/src/MangaRawRU.kt b/multisrc/overrides/mangaraw/mangarawru/src/MangaRawRU.kt index ddf998671..8646493c0 100644 --- a/multisrc/overrides/mangaraw/mangarawru/src/MangaRawRU.kt +++ b/multisrc/overrides/mangaraw/mangarawru/src/MangaRawRU.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.extension.ja.mangarawru import eu.kanade.tachiyomi.multisrc.mangaraw.MangaRawTheme import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SManga import okhttp3.Request import org.jsoup.nodes.Document @@ -59,4 +60,14 @@ class MangaRawRU : MangaRawTheme("MangaRawRU", "https://mangaraw.ru") { override fun pageSelector(): Evaluator { return Evaluator.Tag("img") } + + override fun pageListParse(document: Document): List { + + val position = 32 + val parser = ImageListParser(document.html(), position) + + return parser.getImageList().orEmpty().mapIndexed { i, imageUrl -> + Page(i, imageUrl = imageUrl) + } + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawGenerator.kt index 1a45c00cf..10377dffb 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawGenerator.kt @@ -13,7 +13,7 @@ class MangaRawGenerator : ThemeSourceGenerator { override val sources = listOf( SingleLang("SyoSetu", "https://syosetu.top", "ja"), SingleLang("MangaRaw", "https://manga1001.in", "ja", pkgName = "manga9co", overrideVersionCode = 1), - SingleLang("MangaRawRU", "https://mangaraw.ru", "ja"), + SingleLang("MangaRawRU", "https://mangaraw.ru", "ja", overrideVersionCode = 1), ) companion object {