From df7ec63ad7d37953e9364378d13b5a638c4e254d Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Fri, 30 Sep 2022 19:47:42 -0300 Subject: [PATCH] Make MS into a multilang extension. (#13658) --- .../mangathemesia/miauscan/src/MiauScan.kt | 12 ---- .../miauscan/src/MiauScanFactory.kt | 71 +++++++++++++++++++ .../multisrc/mangathemesia/MangaThemesia.kt | 7 +- .../mangathemesia/MangaThemesiaGenerator.kt | 2 +- 4 files changed, 78 insertions(+), 14 deletions(-) delete mode 100644 multisrc/overrides/mangathemesia/miauscan/src/MiauScan.kt create mode 100644 multisrc/overrides/mangathemesia/miauscan/src/MiauScanFactory.kt diff --git a/multisrc/overrides/mangathemesia/miauscan/src/MiauScan.kt b/multisrc/overrides/mangathemesia/miauscan/src/MiauScan.kt deleted file mode 100644 index 466ca04d0..000000000 --- a/multisrc/overrides/mangathemesia/miauscan/src/MiauScan.kt +++ /dev/null @@ -1,12 +0,0 @@ -package eu.kanade.tachiyomi.extension.es.miauscan - -import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia -import java.text.SimpleDateFormat -import java.util.Locale - -class MiauScan : MangaThemesia( - "Miau Scan", - "https://miauscan.com", - "es", - dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")) -) diff --git a/multisrc/overrides/mangathemesia/miauscan/src/MiauScanFactory.kt b/multisrc/overrides/mangathemesia/miauscan/src/MiauScanFactory.kt new file mode 100644 index 000000000..a2e5bfa76 --- /dev/null +++ b/multisrc/overrides/mangathemesia/miauscan/src/MiauScanFactory.kt @@ -0,0 +1,71 @@ +package eu.kanade.tachiyomi.extension.all.miauscan + +import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia +import eu.kanade.tachiyomi.source.SourceFactory +import eu.kanade.tachiyomi.source.model.Filter +import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.SManga +import okhttp3.Request +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import java.text.SimpleDateFormat +import java.util.Locale + +class MiauScanFactory : SourceFactory { + override fun createSources() = listOf( + MiauScan("es", Filter.TriState.STATE_EXCLUDE), + MiauScan("pt-BR", Filter.TriState.STATE_INCLUDE) + ) +} + +open class MiauScan(lang: String, private val portugueseMode: Int) : MangaThemesia( + name = "Miau Scan", + baseUrl = "https://miauscan.com", + lang = lang, + dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")) +) { + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val genreFilterIndex = filters.indexOfFirst { it is GenreListFilter } + val genreFilter = filters.getOrNull(genreFilterIndex) as? GenreListFilter + ?: GenreListFilter(emptyList()) + + val overloadedGenreFilter = GenreListFilter( + genres = genreFilter.state + listOf( + Genre("", PORTUGUESE_GENRE, portugueseMode) + ) + ) + + val overloadedFilters = filters.toMutableList().apply { + if (genreFilterIndex != -1) { + removeAt(genreFilterIndex) + } + + add(overloadedGenreFilter) + } + + return super.searchMangaRequest(page, query, FilterList(overloadedFilters)) + } + + override fun searchMangaFromElement(element: Element): SManga { + return super.searchMangaFromElement(element).apply { + title = title.replace(PORTUGUESE_SUFFIX, "") + } + } + + override fun mangaDetailsParse(document: Document): SManga { + return super.mangaDetailsParse(document).apply { + title = title.replace(PORTUGUESE_SUFFIX, "") + } + } + + override fun getGenreList(): List { + return super.getGenreList().filter { it.value != PORTUGUESE_GENRE } + } + + companion object { + const val PORTUGUESE_GENRE = "307" + + val PORTUGUESE_SUFFIX = "^\\(\\s*Portugu[ĂȘe]s\\s*\\)\\s*".toRegex(RegexOption.IGNORE_CASE) + } +} diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt index d3fc4bf64..95ee48d69 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt @@ -363,7 +363,12 @@ abstract class MangaThemesia( ) ) - protected class Genre(name: String, val value: String) : Filter.TriState(name) + protected class Genre( + name: String, + val value: String, + state: Int = STATE_IGNORE + ) : Filter.TriState(name, state) + protected class GenreListFilter(genres: List) : Filter.Group("Genre", genres) private var genrelist: List? = null diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt index cde00d6a2..926081ab7 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt @@ -17,6 +17,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator { MultiLang("Asura Scans", "https://www.asurascans.com", listOf("en", "tr"), className = "AsuraScansFactory", pkgName = "asurascans", overrideVersionCode = 16), MultiLang("Flame Scans", "https://flamescans.org", listOf("ar", "en"), className = "FlameScansFactory", pkgName = "flamescans", overrideVersionCode = 1), MultiLang("Komik Lab", "https://komiklab.com", listOf("en", "id"), className = "KomikLabFactory", pkgName = "komiklab", overrideVersionCode = 1), + MultiLang("Miau Scan", "https://miauscan.com", listOf("es", "pt-BR")), SingleLang("Ace Scans", "https://acescans.xyz", "en", isNsfw = true, overrideVersionCode = 2), SingleLang("Alpha Scans", "https://alpha-scans.org", "en", overrideVersionCode = 1), SingleLang("Animated Glitched Scans", "https://anigliscans.com", "en"), @@ -73,7 +74,6 @@ class MangaThemesiaGenerator : ThemeSourceGenerator { SingleLang("Martial Manga", "https://martialmanga.com", "es"), SingleLang("MasterKomik", "https://masterkomik.com", "id", overrideVersionCode = 1), SingleLang("MELOKOMIK", "https://melokomik.xyz", "id"), - SingleLang("Miau Scan", "https://miauscan.com", "es"), SingleLang("Mihentai", "https://mihentai.com", "all", isNsfw = true, overrideVersionCode = 1), SingleLang("Mode Scanlator", "https://modescanlator.com", "pt-BR", overrideVersionCode = 8), SingleLang("Nekomik", "https://nekomik.com", "id"),