Add initial support to more languages at MangaPlus (#6505)

* Add initial support to Portuguese at MangaPlus.

* Add Thai language to MangaPlus.
This commit is contained in:
Alessandro Jean 2021-04-12 11:24:12 -03:00 committed by GitHub
parent 50859e76aa
commit 8869d56b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 10 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'MANGA Plus by SHUEISHA' extName = 'MANGA Plus by SHUEISHA'
pkgNameSuffix = 'all.mangaplus' pkgNameSuffix = 'all.mangaplus'
extClass = '.MangaPlusFactory' extClass = '.MangaPlusFactory'
extVersionCode = 15 extVersionCode = 16
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -76,6 +76,25 @@ abstract class MangaPlus(
private var titleList: List<Title>? = null private var titleList: List<Title>? = 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 { override fun popularMangaRequest(page: Int): Request {
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
.set("Referer", "$baseUrl/manga_list/hot") .set("Referer", "$baseUrl/manga_list/hot")
@ -91,6 +110,7 @@ abstract class MangaPlus(
throw Exception(result.error!!.langPopup.body) throw Exception(result.error!!.langPopup.body)
titleList = result.success.titleRankingView!!.titles titleList = result.success.titleRankingView!!.titles
.fixWrongLanguages()
.filter { it.language == langCode } .filter { it.language == langCode }
val mangas = titleList!!.map { val mangas = titleList!!.map {
@ -123,12 +143,14 @@ abstract class MangaPlus(
if (popularResponse.success != null) { if (popularResponse.success != null) {
titleList = popularResponse.success.titleRankingView!!.titles titleList = popularResponse.success.titleRankingView!!.titles
.fixWrongLanguages()
.filter { it.language == langCode } .filter { it.language == langCode }
} }
val mangas = result.success.webHomeView!!.groups val mangas = result.success.webHomeView!!.groups
.flatMap { it.titles } .flatMap { it.titles }
.mapNotNull { it.title } .mapNotNull { it.title }
.fixWrongLanguages()
.filter { it.language == langCode } .filter { it.language == langCode }
.map { .map {
SManga.create().apply { SManga.create().apply {
@ -162,6 +184,7 @@ abstract class MangaPlus(
throw Exception(result.error!!.langPopup.body) throw Exception(result.error!!.langPopup.body)
titleList = result.success.allTitlesView!!.titles titleList = result.success.allTitlesView!!.titles
.fixWrongLanguages()
.filter { it.language == langCode } .filter { it.language == langCode }
val mangas = titleList!!.map { val mangas = titleList!!.map {
@ -421,9 +444,14 @@ abstract class MangaPlus(
return response 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 private val ErrorResult.langPopup: Popup
get() = when (lang) { get() = when (internalLang) {
"es" -> spanishPopup "esp" -> spanishPopup
else -> englishPopup else -> englishPopup
} }
@ -452,7 +480,7 @@ abstract class MangaPlus(
companion object { companion object {
private const val API_URL = "https://jumpg-webapi.tokyo-cdn.com/api" 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) " + 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() private val HEX_GROUP = "(.{1,2})".toRegex()

View File

@ -88,7 +88,16 @@ enum class Language(val id: Int) {
@ProtoNumber(1) @ProtoNumber(1)
@SerializedName("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 @Serializable
@ -216,6 +225,8 @@ const val DECODE_SCRIPT: String =
var Language = new Enum("Language") var Language = new Enum("Language")
.add("ENGLISH", 0) .add("ENGLISH", 0)
.add("SPANISH", 1); .add("SPANISH", 1);
// .add("THAI", 2)
// .add("PORTUGUESE_BR", 3);
var UpdatedTitleGroup = new Type("UpdatedTitleGroup") var UpdatedTitleGroup = new Type("UpdatedTitleGroup")
.add(new Field("groupName", 1, "string")) .add(new Field("groupName", 1, "string"))

View File

@ -4,13 +4,17 @@ import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceFactory import eu.kanade.tachiyomi.source.SourceFactory
class MangaPlusFactory : 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 MangaPlusEnglish : MangaPlus("en", "eng", Language.ENGLISH)
class MangaPlusSpanish : MangaPlus("es", "esp", Language.SPANISH) class MangaPlusSpanish : MangaPlus("es", "esp", Language.SPANISH)
class MangaPlusThai : MangaPlus("th", "eng", Language.THAI)
fun getAllMangaPlus(): List<Source> = listOf( // The titles have the Portugal flag in the thumbnail, but the text of the translations is Brazilian.
MangaPlusEnglish(), class MangaPlusPortuguese : MangaPlus("pt-BR", "eng", Language.PORTUGUESE_BR)
MangaPlusSpanish()
)