From 8869d56b6f05b5e198bdb8bdbc367613d8f711e9 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Mon, 12 Apr 2021 11:24:12 -0300 Subject: [PATCH] Add initial support to more languages at MangaPlus (#6505) * Add initial support to Portuguese at MangaPlus. * Add Thai language to MangaPlus. --- src/all/mangaplus/build.gradle | 2 +- .../extension/all/mangaplus/MangaPlus.kt | 34 +++++++++++++++++-- .../extension/all/mangaplus/MangaPlusApi.kt | 13 ++++++- .../all/mangaplus/MangaPlusFactory.kt | 14 +++++--- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/all/mangaplus/build.gradle b/src/all/mangaplus/build.gradle index 55a59482e..b35174d9b 100644 --- a/src/all/mangaplus/build.gradle +++ b/src/all/mangaplus/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'MANGA Plus by SHUEISHA' pkgNameSuffix = 'all.mangaplus' extClass = '.MangaPlusFactory' - extVersionCode = 15 + extVersionCode = 16 libVersion = '1.2' } diff --git a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt index 15a3540b8..5ecbe83bd 100644 --- a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt +++ b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlus.kt @@ -76,6 +76,25 @@ abstract class MangaPlus( private var titleList: List? = null + /** + * MANGA Plus recently started supporting other languages, but + * they are not defined by the API. This is a temporary fix + * to properly filter the titles while their API doesn't get an update. + */ + private val titlesToFix: Map<Int, Language> = mapOf( + // Thai + 100079 to Language.THAI, + 100080 to Language.THAI, + 100082 to Language.THAI, + 100120 to Language.THAI, + 100121 to Language.THAI, + + // Brazilian Portuguese + 100149 to Language.PORTUGUESE_BR, + 100150 to Language.PORTUGUESE_BR, + 100151 to Language.PORTUGUESE_BR + ) + override fun popularMangaRequest(page: Int): Request { val newHeaders = headersBuilder() .set("Referer", "$baseUrl/manga_list/hot") @@ -91,6 +110,7 @@ abstract class MangaPlus( throw Exception(result.error!!.langPopup.body) titleList = result.success.titleRankingView!!.titles + .fixWrongLanguages() .filter { it.language == langCode } val mangas = titleList!!.map { @@ -123,12 +143,14 @@ abstract class MangaPlus( if (popularResponse.success != null) { titleList = popularResponse.success.titleRankingView!!.titles + .fixWrongLanguages() .filter { it.language == langCode } } val mangas = result.success.webHomeView!!.groups .flatMap { it.titles } .mapNotNull { it.title } + .fixWrongLanguages() .filter { it.language == langCode } .map { SManga.create().apply { @@ -162,6 +184,7 @@ abstract class MangaPlus( throw Exception(result.error!!.langPopup.body) titleList = result.success.allTitlesView!!.titles + .fixWrongLanguages() .filter { it.language == langCode } val mangas = titleList!!.map { @@ -421,9 +444,14 @@ abstract class MangaPlus( return response } + private fun List<Title>.fixWrongLanguages(): List<Title> = map { title -> + val correctLanguage = titlesToFix[title.titleId] + if (correctLanguage != null) title.copy(language = correctLanguage) else title + } + private val ErrorResult.langPopup: Popup - get() = when (lang) { - "es" -> spanishPopup + get() = when (internalLang) { + "esp" -> spanishPopup else -> englishPopup } @@ -452,7 +480,7 @@ abstract class MangaPlus( companion object { private const val API_URL = "https://jumpg-webapi.tokyo-cdn.com/api" private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + - "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36" + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" private val HEX_GROUP = "(.{1,2})".toRegex() diff --git a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusApi.kt b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusApi.kt index a166950ad..1586ea828 100644 --- a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusApi.kt +++ b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusApi.kt @@ -88,7 +88,16 @@ enum class Language(val id: Int) { @ProtoNumber(1) @SerializedName("1") - SPANISH(1) + SPANISH(1), + + // Temporary add the languages that are not present on the API yet. + // @ProtoNumber(2) + // @SerializedName("2") + THAI(2), + + // @ProtoNumber(3) + // @SerializedName("3") + PORTUGUESE_BR(3) } @Serializable @@ -216,6 +225,8 @@ const val DECODE_SCRIPT: String = var Language = new Enum("Language") .add("ENGLISH", 0) .add("SPANISH", 1); + // .add("THAI", 2) + // .add("PORTUGUESE_BR", 3); var UpdatedTitleGroup = new Type("UpdatedTitleGroup") .add(new Field("groupName", 1, "string")) diff --git a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusFactory.kt b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusFactory.kt index 788147640..927900192 100644 --- a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusFactory.kt +++ b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusFactory.kt @@ -4,13 +4,17 @@ import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceFactory class MangaPlusFactory : SourceFactory { - override fun createSources(): List<Source> = getAllMangaPlus() + override fun createSources(): List<Source> = listOf( + MangaPlusEnglish(), + MangaPlusSpanish(), + MangaPlusThai(), + MangaPlusPortuguese() + ) } class MangaPlusEnglish : MangaPlus("en", "eng", Language.ENGLISH) class MangaPlusSpanish : MangaPlus("es", "esp", Language.SPANISH) +class MangaPlusThai : MangaPlus("th", "eng", Language.THAI) -fun getAllMangaPlus(): List<Source> = listOf( - MangaPlusEnglish(), - MangaPlusSpanish() -) +// The titles have the Portugal flag in the thumbnail, but the text of the translations is Brazilian. +class MangaPlusPortuguese : MangaPlus("pt-BR", "eng", Language.PORTUGUESE_BR)