From 49e35d522391ed0d98955fa1e29c858fec2ac480 Mon Sep 17 00:00:00 2001 From: Chopper <156493704+choppeh@users.noreply.github.com> Date: Mon, 11 Nov 2024 05:37:46 -0300 Subject: [PATCH] MangaReader: Add support for Portuguese and Spanish (#5972) Add support for Portuguese and Spanish --- src/all/mangareaderto/build.gradle | 2 +- .../extension/all/mangareaderto/MangaReader.kt | 13 ++++++++----- .../all/mangareaderto/MangaReaderFactory.kt | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/all/mangareaderto/build.gradle b/src/all/mangareaderto/build.gradle index fe63d1062..1048b2e9e 100644 --- a/src/all/mangareaderto/build.gradle +++ b/src/all/mangareaderto/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.MangaReaderFactory' themePkg = 'mangareader' baseUrl = 'https://mangareader.to' - overrideVersionCode = 3 + overrideVersionCode = 4 isNsfw = true } diff --git a/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReader.kt b/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReader.kt index 16842a8d5..88fe0fddf 100644 --- a/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReader.kt +++ b/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReader.kt @@ -22,8 +22,11 @@ import org.jsoup.select.Evaluator import rx.Observable open class MangaReader( - override val lang: String, + val language: Language, ) : MangaReader() { + + override val lang = language.code + override val name = "MangaReader" override val baseUrl = "https://mangareader.to" @@ -33,10 +36,10 @@ open class MangaReader( .build() override fun latestUpdatesRequest(page: Int) = - GET("$baseUrl/filter?sort=latest-updated&language=$lang&page=$page", headers) + GET("$baseUrl/filter?sort=latest-updated&language=${language.infix}&page=$page", headers) override fun popularMangaRequest(page: Int) = - GET("$baseUrl/filter?sort=most-viewed&language=$lang&page=$page", headers) + GET("$baseUrl/filter?sort=most-viewed&language=${language.infix}&page=$page", headers) override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val urlBuilder = baseUrl.toHttpUrl().newBuilder() @@ -47,7 +50,7 @@ open class MangaReader( } } else { urlBuilder.addPathSegment("filter").apply { - addQueryParameter("language", lang) + addQueryParameter("language", language.infix) addQueryParameter("page", page.toString()) filters.ifEmpty(::getFilterList).forEach { filter -> when (filter) { @@ -142,7 +145,7 @@ open class MangaReader( override fun parseChapterElements(response: Response, isVolume: Boolean): List { val container = response.parseHtmlProperty().run { val type = if (isVolume) "volumes" else "chapters" - selectFirst(Evaluator.Id("$lang-$type")) ?: return emptyList() + selectFirst(Evaluator.Id("${language.chapterInfix}-$type")) ?: return emptyList() } return container.children() } diff --git a/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReaderFactory.kt b/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReaderFactory.kt index 8cb12aba9..e7c060495 100644 --- a/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReaderFactory.kt +++ b/src/all/mangareaderto/src/eu/kanade/tachiyomi/extension/all/mangareaderto/MangaReaderFactory.kt @@ -4,5 +4,19 @@ import eu.kanade.tachiyomi.source.SourceFactory class MangaReaderFactory : SourceFactory { override fun createSources() = - arrayOf("en", "fr", "ja", "ko", "zh").map(::MangaReader) + arrayOf( + Language("en"), + Language("es", chapterInfix = "es-mx"), + Language("fr"), + Language("ja"), + Language("ko"), + Language("pt-BR", infix = "pt"), + Language("zh"), + ).map(::MangaReader) } + +data class Language( + val code: String, + val infix: String = code, + val chapterInfix: String = code.lowercase(), +)