diff --git a/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt b/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt index 5c1e311f8..409a2bcae 100644 --- a/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt +++ b/multisrc/overrides/mangaraw/manga9co/src/MangaRaw.kt @@ -21,6 +21,7 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { override val supportsLatest = true override val baseUrl: String private val selectors: Selectors + private val needUrlSanitize: Boolean init { val mirrors = MIRRORS @@ -28,6 +29,7 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { .getString(MIRROR_PREF, "0")!!.toInt().coerceAtMost(mirrors.size - 1) baseUrl = "https://" + mirrors[mirrorIndex] selectors = getSelectors(mirrorIndex) + needUrlSanitize = needUrlSanitize(mirrorIndex) } override fun String.sanitizeTitle() = substringBeforeLast('(').trimEnd() @@ -36,6 +38,10 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { override fun popularMangaSelector() = selectors.listMangaSelector override fun popularMangaNextPageSelector() = ".nextpostslink" + override fun popularMangaFromElement(element: Element) = super.popularMangaFromElement(element).apply { + if (needUrlSanitize) url = mangaSlugRegex.replaceFirst(url, "/") + } + override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = GET("$baseUrl/?s=$query&page=$page", headers) @@ -55,7 +61,9 @@ class MangaRaw : MangaRawTheme("MangaRaw", ""), ConfigurableSource { ListPreference(screen.context).apply { key = MIRROR_PREF title = "Mirror" - summary = "Requires app restart to take effect\nSelected: %s" + summary = "%s\n" + + "Requires app restart to take effect\n" + + "Note: 'mangaraw.to' might fail to load images because of Cloudflare protection" 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 36d50dc96..166a8d125 100644 --- a/multisrc/overrides/mangaraw/manga9co/src/MangaRawConstants.kt +++ b/multisrc/overrides/mangaraw/manga9co/src/MangaRawConstants.kt @@ -1,7 +1,11 @@ package eu.kanade.tachiyomi.extension.ja.manga9co +/** + * https://syosetu.me/ is not added because of different HTML structure + */ + internal const val MIRROR_PREF = "MIRROR" -internal val MIRRORS get() = arrayOf("manga9.co", "mangaraw.co", "mangaraw.lol", "mangarawjp.com") +internal val MIRRORS get() = arrayOf("manga9.co", "mangaraw.to", "mangaraw.io", "mangarawjp.io") internal fun getSelectors(mirrorIndex: Int) = when (mirrorIndex) { 0, 1, 2 -> Selectors( @@ -16,6 +20,10 @@ internal fun getSelectors(mirrorIndex: Int) = when (mirrorIndex) { ) } +internal fun needUrlSanitize(mirrorIndex: Int) = mirrorIndex == 2 + +internal val mangaSlugRegex = Regex("""^/mz[a-z]{4}-""") + internal class Selectors( val listMangaSelector: String, val detailsSelector: String, diff --git a/multisrc/overrides/mangaraw/syosetu/src/SyoSetu.kt b/multisrc/overrides/mangaraw/syosetu/src/SyoSetu.kt index d6e9f11be..7f5299e35 100644 --- a/multisrc/overrides/mangaraw/syosetu/src/SyoSetu.kt +++ b/multisrc/overrides/mangaraw/syosetu/src/SyoSetu.kt @@ -14,9 +14,12 @@ class SyoSetu : MangaRawTheme("SyoSetu", "https://syosetu.top") { override val supportsLatest = false - override fun String.sanitizeTitle() = - substring(0, lastIndexOf("RAW", ignoreCase = true)) + override fun String.sanitizeTitle(): String { + val index = lastIndexOf("RAW", ignoreCase = true) + if (index == -1) return this + return substring(0, index) .trimEnd('(', ' ', ',') + } override fun popularMangaSelector() = "article" override fun popularMangaNextPageSelector() = ".next.page-numbers" 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 422e13b48..1a2e1506b 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 @@ -8,11 +8,11 @@ class MangaRawGenerator : ThemeSourceGenerator { override val themePkg = "mangaraw" - override val baseVersionCode = 2 + override val baseVersionCode = 4 override val sources = listOf( - SingleLang("SyoSetu", "https://syosetu.top", "ja", overrideVersionCode = 1), - SingleLang("MangaRaw", "https://manga9.co", "ja", pkgName = "manga9co", overrideVersionCode = 1), + SingleLang("SyoSetu", "https://syosetu.top", "ja"), + SingleLang("MangaRaw", "https://manga9.co", "ja", pkgName = "manga9co"), ) companion object { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawTheme.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawTheme.kt index 272ad2b2d..66129cf4a 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawTheme.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangaraw/MangaRawTheme.kt @@ -15,12 +15,14 @@ abstract class MangaRawTheme( override val lang: String = "ja" ) : ParsedHttpSource() { - override fun headersBuilder() = super.headersBuilder().add("Referer", baseUrl) + override fun headersBuilder() = super.headersBuilder().add("Referer", "$baseUrl/") + + override val client = network.cloudflareClient protected abstract fun String.sanitizeTitle(): String override fun popularMangaFromElement(element: Element) = SManga.create().apply { - url = element.selectFirst(Evaluator.Tag("a")).attr("href").removePrefix(baseUrl) + setUrlWithoutDomain(element.selectFirst(Evaluator.Tag("a")).attr("href")) title = element.selectFirst(Evaluator.Tag("h3")).text().sanitizeTitle() thumbnail_url = element.selectFirst(Evaluator.Tag("img"))?.absUrl("data-src") } @@ -58,7 +60,7 @@ abstract class MangaRawTheme( protected abstract fun String.sanitizeChapter(): String override fun chapterFromElement(element: Element) = SChapter.create().apply { - url = element.attr("href").removePrefix(baseUrl) + setUrlWithoutDomain(element.attr("href")) name = element.text().sanitizeChapter() }