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:
parent
50859e76aa
commit
8869d56b6f
|
@ -6,7 +6,7 @@ ext {
|
|||
extName = 'MANGA Plus by SHUEISHA'
|
||||
pkgNameSuffix = 'all.mangaplus'
|
||||
extClass = '.MangaPlusFactory'
|
||||
extVersionCode = 15
|
||||
extVersionCode = 16
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -76,6 +76,25 @@ abstract class MangaPlus(
|
|||
|
||||
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 {
|
||||
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()
|
||||
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue