MangaRaw: fix page list, update URL, random mirror (#14561)
* MangaRaw: fix page list, update URL, random mirror * update baseUrl in generator
This commit is contained in:
parent
792468f338
commit
3317191ba7
|
@ -1,17 +1,21 @@
|
||||||
package eu.kanade.tachiyomi.extension.ja.manga9co
|
package eu.kanade.tachiyomi.extension.ja.manga9co
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.util.Base64
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.multisrc.mangaraw.MangaRawTheme
|
import eu.kanade.tachiyomi.multisrc.mangaraw.MangaRawTheme
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.source.ConfigurableSource
|
import eu.kanade.tachiyomi.source.ConfigurableSource
|
||||||
import eu.kanade.tachiyomi.source.model.FilterList
|
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.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import org.jsoup.select.Evaluator
|
import org.jsoup.select.Evaluator
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource {
|
class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource {
|
||||||
// See https://github.com/tachiyomiorg/tachiyomi-extensions/commits/master/src/ja/mangaraw
|
// 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
|
override val baseUrl: String
|
||||||
private val selectors: Selectors
|
private val selectors: Selectors
|
||||||
private val needUrlSanitize: Boolean
|
private val needUrlSanitize: Boolean
|
||||||
|
private val isPagesShuffled: Boolean
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val mirrors = MIRRORS
|
val mirrors = MIRRORS
|
||||||
val mirrorIndex = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
val preferences = Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
.getString(MIRROR_PREF, "0")!!.toInt().coerceAtMost(mirrors.size - 1)
|
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]
|
baseUrl = "https://" + mirrors[mirrorIndex]
|
||||||
selectors = getSelectors(mirrorIndex)
|
selectors = getSelectors(mirrorIndex)
|
||||||
needUrlSanitize = needUrlSanitize(mirrorIndex)
|
needUrlSanitize = needUrlSanitize(mirrorIndex)
|
||||||
|
isPagesShuffled = isPagesShuffled(mirrorIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun String.sanitizeTitle() = substringBeforeLast('(').trimEnd()
|
override fun String.sanitizeTitle() = substringBeforeLast('(').trimEnd()
|
||||||
|
@ -57,13 +69,26 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource {
|
||||||
|
|
||||||
override fun pageSelector() = Evaluator.Class("card-wrap")
|
override fun pageSelector() = Evaluator.Class("card-wrap")
|
||||||
|
|
||||||
|
override fun pageListParse(response: Response): List<Page> {
|
||||||
|
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) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
ListPreference(screen.context).apply {
|
ListPreference(screen.context).apply {
|
||||||
key = MIRROR_PREF
|
key = MIRROR_PREF
|
||||||
title = "Mirror"
|
title = "Mirror"
|
||||||
summary = "%s\n" +
|
summary = "%s\n" +
|
||||||
"Requires app restart to take effect\n" +
|
"Requires app restart to take effect\n" +
|
||||||
"Note: 'mangaraw.to' might fail to load images because of Cloudflare protection"
|
PROMPT
|
||||||
entries = MIRRORS
|
entries = MIRRORS
|
||||||
entryValues = MIRRORS.indices.map { it.toString() }.toTypedArray()
|
entryValues = MIRRORS.indices.map { it.toString() }.toTypedArray()
|
||||||
setDefaultValue("0")
|
setDefaultValue("0")
|
||||||
|
|
|
@ -5,7 +5,11 @@ package eu.kanade.tachiyomi.extension.ja.manga9co
|
||||||
*/
|
*/
|
||||||
|
|
||||||
internal const val MIRROR_PREF = "MIRROR"
|
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) {
|
internal fun getSelectors(mirrorIndex: Int) = when (mirrorIndex) {
|
||||||
0, 1, 2 -> Selectors(
|
0, 1, 2 -> Selectors(
|
||||||
|
@ -22,6 +26,11 @@ internal fun getSelectors(mirrorIndex: Int) = when (mirrorIndex) {
|
||||||
|
|
||||||
internal fun needUrlSanitize(mirrorIndex: Int) = mirrorIndex == 2
|
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 val mangaSlugRegex = Regex("""^/mz[a-z]{4}-""")
|
||||||
|
|
||||||
internal class Selectors(
|
internal class Selectors(
|
||||||
|
|
|
@ -12,7 +12,7 @@ class MangaRawGenerator : ThemeSourceGenerator {
|
||||||
|
|
||||||
override val sources = listOf(
|
override val sources = listOf(
|
||||||
SingleLang("SyoSetu", "https://syosetu.top", "ja"),
|
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 {
|
companion object {
|
||||||
|
|
Loading…
Reference in New Issue