MangaRaw: fix URL issues (#13742)

* MangaRaw: fix URL issues

* use replaceFirst
This commit is contained in:
stevenyomi 2022-10-07 21:33:09 +08:00 committed by GitHub
parent 119e8819be
commit a3e92088c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 10 deletions

View File

@ -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")

View File

@ -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,

View File

@ -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"

View File

@ -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 {

View File

@ -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()
}