From 3317191ba7a5c7ab49c7a59400661981496a2569 Mon Sep 17 00:00:00 2001 From: stevenyomi <95685115+stevenyomi@users.noreply.github.com> Date: Fri, 16 Dec 2022 09:37:35 +0800 Subject: [PATCH] MangaRaw: fix page list, update URL, random mirror (#14561) * MangaRaw: fix page list, update URL, random mirror * update baseUrl in generator --- .../mangaraw/manga9co/src/MangaRaw.kt | 31 +++++++++++++++++-- .../manga9co/src/MangaRawConstants.kt | 11 ++++++- .../multisrc/mangaraw/MangaRawGenerator.kt | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt b/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt index 409a2bcae..8fd2f0e93 100644 --- a/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt +++ b/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt @@ -1,17 +1,21 @@ package eu.kanade.tachiyomi.extension.ja.manga9co import android.app.Application +import android.util.Base64 import androidx.preference.ListPreference import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.multisrc.mangaraw.MangaRawTheme import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.ConfigurableSource import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.Page +import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import org.jsoup.select.Evaluator import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get +import kotlin.random.Random class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { // See https://github.com/tachiyomiorg/tachiyomi-extensions/commits/master/src/ja/mangaraw @@ -22,14 +26,22 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { override val baseUrl: String private val selectors: Selectors private val needUrlSanitize: Boolean + private val isPagesShuffled: Boolean init { val mirrors = MIRRORS - val mirrorIndex = Injekt.get().getSharedPreferences("source_$id", 0x0000) - .getString(MIRROR_PREF, "0")!!.toInt().coerceAtMost(mirrors.size - 1) + val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) + var mirrorIndex = preferences.getString(MIRROR_PREF, "-1")!!.toInt() + + if (mirrorIndex !in mirrors.indices) { + mirrorIndex = Random.nextInt(RANDOM_MIRROR_FROM, RANDOM_MIRROR_UNTIL) + preferences.edit().putString(MIRROR_PREF, mirrorIndex.toString()).apply() + } + baseUrl = "https://" + mirrors[mirrorIndex] selectors = getSelectors(mirrorIndex) needUrlSanitize = needUrlSanitize(mirrorIndex) + isPagesShuffled = isPagesShuffled(mirrorIndex) } override fun String.sanitizeTitle() = substringBeforeLast('(').trimEnd() @@ -57,13 +69,26 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { override fun pageSelector() = Evaluator.Class("card-wrap") + override fun pageListParse(response: Response): List { + if (!isPagesShuffled) return super.pageListParse(response) + val html = response.body!!.string() + val startText = "let ads = '" + val startIndex = html.indexOf(startText) + startText.length + val endIndex = html.indexOf('\'', startIndex) + val base64 = html.substring(startIndex, endIndex) + val decoded = String(Base64.decode(base64, Base64.DEFAULT)) + return decoded.split(",").mapIndexed { index, imageUrl -> + Page(index, imageUrl = imageUrl) + } + } + override fun setupPreferenceScreen(screen: PreferenceScreen) { ListPreference(screen.context).apply { key = MIRROR_PREF title = "Mirror" summary = "%s\n" + "Requires app restart to take effect\n" + - "Note: 'mangaraw.to' might fail to load images because of Cloudflare protection" + PROMPT entries = MIRRORS entryValues = MIRRORS.indices.map { it.toString() }.toTypedArray() setDefaultValue("0") diff --git a/multisrc/overrides/mangaraw/manga9co/src/MangaRawConstants.kt b/multisrc/overrides/mangaraw/manga9co/src/MangaRawConstants.kt index 166a8d125..5c0f08694 100644 --- a/multisrc/overrides/mangaraw/manga9co/src/MangaRawConstants.kt +++ b/multisrc/overrides/mangaraw/manga9co/src/MangaRawConstants.kt @@ -5,7 +5,11 @@ package eu.kanade.tachiyomi.extension.ja.manga9co */ internal const val MIRROR_PREF = "MIRROR" -internal val MIRRORS get() = arrayOf("manga9.co", "mangaraw.to", "mangaraw.io", "mangarawjp.io") +internal val MIRRORS get() = arrayOf("manga1001.in", "mangaraw.to", "mangaraw.io", "mangarawjp.io") +internal val PROMPT get() = "Note: 'manga1001.in' is not recommended because it might contain shuffled/unordered pages." + +internal const val RANDOM_MIRROR_FROM = 1 +internal const val RANDOM_MIRROR_UNTIL = 4 internal fun getSelectors(mirrorIndex: Int) = when (mirrorIndex) { 0, 1, 2 -> Selectors( @@ -22,6 +26,11 @@ internal fun getSelectors(mirrorIndex: Int) = when (mirrorIndex) { internal fun needUrlSanitize(mirrorIndex: Int) = mirrorIndex == 2 +internal fun isPagesShuffled(mirrorIndex: Int) = when (mirrorIndex) { + 1, 3 -> true + else -> false +} + internal val mangaSlugRegex = Regex("""^/mz[a-z]{4}-""") internal class Selectors( 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 1a2e1506b..902b32ade 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 @@ -12,7 +12,7 @@ class MangaRawGenerator : ThemeSourceGenerator { override val sources = listOf( SingleLang("SyoSetu", "https://syosetu.top", "ja"), - SingleLang("MangaRaw", "https://manga9.co", "ja", pkgName = "manga9co"), + SingleLang("MangaRaw", "https://manga1001.in", "ja", pkgName = "manga9co", overrideVersionCode = 1), ) companion object {