Update MangaPlus API endpoints. (#8421)

This commit is contained in:
Alessandro Jean 2021-08-06 15:17:21 -03:00 committed by GitHub
parent 5f5a285278
commit 97b59f6623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 81 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 = 20 extVersionCode = 21
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -74,33 +74,6 @@ 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,
100158 to Language.THAI,
// Brazilian Portuguese
100149 to Language.PORTUGUESE_BR,
100150 to Language.PORTUGUESE_BR,
100151 to Language.PORTUGUESE_BR,
100163 to Language.PORTUGUESE_BR,
// Indonesian
100140 to Language.INDONESIAN,
100142 to Language.INDONESIAN,
100143 to Language.INDONESIAN,
100162 to Language.INDONESIAN
)
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")
@ -116,7 +89,6 @@ 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 {
@ -135,7 +107,7 @@ abstract class MangaPlus(
.set("Referer", "$baseUrl/updates") .set("Referer", "$baseUrl/updates")
.build() .build()
return GET("$API_URL/web/web_home?lang=$internalLang", newHeaders) return GET("$API_URL/web/web_homeV3?lang=$internalLang", newHeaders)
} }
override fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
@ -149,14 +121,13 @@ 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.webHomeViewV3!!.groups
.flatMap { it.titleGroups }
.flatMap { it.titles } .flatMap { it.titles }
.mapNotNull { it.title } .map { it.title }
.fixWrongLanguages()
.filter { it.language == langCode } .filter { it.language == langCode }
.map { .map {
SManga.create().apply { SManga.create().apply {
@ -191,7 +162,7 @@ abstract class MangaPlus(
.set("Referer", "$baseUrl/manga_list/all") .set("Referer", "$baseUrl/manga_list/all")
.build() .build()
return GET("$API_URL/title_list/all", newHeaders) return GET("$API_URL/title_list/allV2", newHeaders)
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
@ -201,10 +172,7 @@ abstract class MangaPlus(
throw Exception(result.error!!.langPopup.body) throw Exception(result.error!!.langPopup.body)
if (result.success.titleDetailView != null) { if (result.success.titleDetailView != null) {
val mangaPlusTitle = result.success.titleDetailView.title.let { val mangaPlusTitle = result.success.titleDetailView.title
val correctLanguage = titlesToFix[it.titleId]
if (correctLanguage != null) it.copy(language = correctLanguage) else it
}
if (mangaPlusTitle.language == langCode) { if (mangaPlusTitle.language == langCode) {
val manga = SManga.create().apply { val manga = SManga.create().apply {
@ -219,8 +187,8 @@ abstract class MangaPlus(
return MangasPage(emptyList(), hasNextPage = false) return MangasPage(emptyList(), hasNextPage = false)
} }
titleList = result.success.allTitlesView!!.titles titleList = result.success.allTitlesViewV2!!.allTitlesGroup
.fixWrongLanguages() .flatMap { it.titles }
.filter { it.language == langCode } .filter { it.language == langCode }
val mangas = titleList!!.map { val mangas = titleList!!.map {
@ -448,11 +416,6 @@ 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 (internalLang) { get() = when (internalLang) {
"esp" -> spanishPopup "esp" -> spanishPopup

View File

@ -28,21 +28,29 @@ data class Popup(
@Serializable @Serializable
data class SuccessResult( data class SuccessResult(
@ProtoNumber(1) val isFeaturedUpdated: Boolean? = false, @ProtoNumber(1) val isFeaturedUpdated: Boolean? = false,
@ProtoNumber(5) val allTitlesView: AllTitlesView? = null,
@ProtoNumber(6) val titleRankingView: TitleRankingView? = null, @ProtoNumber(6) val titleRankingView: TitleRankingView? = null,
@ProtoNumber(8) val titleDetailView: TitleDetailView? = null, @ProtoNumber(8) val titleDetailView: TitleDetailView? = null,
@ProtoNumber(10) val mangaViewer: MangaViewer? = null, @ProtoNumber(10) val mangaViewer: MangaViewer? = null,
@ProtoNumber(11) val webHomeView: WebHomeView? = null @ProtoNumber(25) val allTitlesViewV2: AllTitlesViewV2? = null,
@ProtoNumber(31) val webHomeViewV3: WebHomeViewV3? = null
) )
@Serializable @Serializable
data class TitleRankingView(@ProtoNumber(1) val titles: List<Title> = emptyList()) data class TitleRankingView(@ProtoNumber(1) val titles: List<Title> = emptyList())
@Serializable @Serializable
data class AllTitlesView(@ProtoNumber(1) val titles: List<Title> = emptyList()) data class AllTitlesViewV2(
@ProtoNumber(1) val allTitlesGroup: List<AllTitlesGroup> = emptyList()
)
@Serializable @Serializable
data class WebHomeView(@ProtoNumber(2) val groups: List<UpdatedTitleGroup> = emptyList()) data class AllTitlesGroup(
@ProtoNumber(1) val theTitle: String,
@ProtoNumber(2) val titles: List<Title> = emptyList()
)
@Serializable
data class WebHomeViewV3(@ProtoNumber(2) val groups: List<UpdatedTitleV2Group> = emptyList())
@Serializable @Serializable
data class TitleDetailView( data class TitleDetailView(
@ -86,31 +94,42 @@ enum class Language(val id: Int) {
@SerializedName("1") @SerializedName("1")
SPANISH(1), SPANISH(1),
// Temporary add the languages that are not present on the API yet. @ProtoNumber(2)
// @ProtoNumber(2) @SerializedName("2")
// @SerializedName("2") FRENCH(2),
THAI(2),
// @ProtoNumber(3) @ProtoNumber(3)
// @SerializedName("3") @SerializedName("3")
PORTUGUESE_BR(3), INDONESIAN(4),
// @ProtoNumber(4) @ProtoNumber(4)
// @SerializedName("4") @SerializedName("4")
INDONESIAN(4) PORTUGUESE_BR(4),
@ProtoNumber(5)
@SerializedName("5")
RUSSIAN(5),
@ProtoNumber(6)
@SerializedName("6")
THAI(6)
} }
@Serializable @Serializable
data class UpdatedTitleGroup( data class UpdatedTitleV2Group(
@ProtoNumber(1) val groupName: String, @ProtoNumber(1) val groupName: String,
@ProtoNumber(2) val titles: List<UpdatedTitle> = emptyList() @ProtoNumber(2) val titleGroups: List<OriginalTitleGroup> = emptyList()
) )
@Serializable @Serializable
data class UpdatedTitle( data class OriginalTitleGroup(
@ProtoNumber(1) val title: Title? = null @ProtoNumber(1) val theTitle: String,
@ProtoNumber(3) val titles: List<UpdatedTitle> = emptyList()
) )
@Serializable
data class UpdatedTitle(@ProtoNumber(1) val title: Title)
@Serializable @Serializable
data class Chapter( data class Chapter(
@ProtoNumber(1) val titleId: Int, @ProtoNumber(1) val titleId: Int,
@ -169,21 +188,25 @@ const val DECODE_SCRIPT: String =
.add(new Field("isFeaturedUpdated", 1, "bool")) .add(new Field("isFeaturedUpdated", 1, "bool"))
.add( .add(
new OneOf("data") new OneOf("data")
.add(new Field("allTitlesView", 5, "AllTitlesView"))
.add(new Field("titleRankingView", 6, "TitleRankingView")) .add(new Field("titleRankingView", 6, "TitleRankingView"))
.add(new Field("titleDetailView", 8, "TitleDetailView")) .add(new Field("titleDetailView", 8, "TitleDetailView"))
.add(new Field("mangaViewer", 10, "MangaViewer")) .add(new Field("mangaViewer", 10, "MangaViewer"))
.add(new Field("webHomeView", 11, "WebHomeView")) .add(new Field("allTitlesViewV2", 25, "AllTitlesViewV2"))
.add(new Field("webHomeViewV3", 31, "WebHomeViewV3"))
); );
var TitleRankingView = new Type("TitleRankingView") var TitleRankingView = new Type("TitleRankingView")
.add(new Field("titles", 1, "Title", "repeated")); .add(new Field("titles", 1, "Title", "repeated"));
var AllTitlesView = new Type("AllTitlesView") var AllTitlesViewV2 = new Type("AllTitlesViewV2")
.add(new Field("titles", 1, "Title", "repeated")); .add(new Field("allTitlesGroup", 1, "AllTitlesGroup", "repeated"));
var WebHomeView = new Type("WebHomeView") var AlLTitlesGroup = new Type("AllTitlesGroup")
.add(new Field("groups", 2, "UpdatedTitleGroup", "repeated")); .add(new Field("theTitle", 1, "string"))
.add(new Field("titles", 2, "Title", "repeated"));
var WebHomeViewV3 = new Type("WebHomeViewV3")
.add(new Field("groups", 2, "UpdatedTitleV2Group", "repeated"));
var TitleDetailView = new Type("TitleDetailView") var TitleDetailView = new Type("TitleDetailView")
.add(new Field("title", 1, "Title")) .add(new Field("title", 1, "Title"))
@ -224,13 +247,20 @@ 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("FRENCH", 2)
// .add("PORTUGUESE_BR", 3); .add("INDONESIAN", 3)
.add("PORTUGUESE_BR", 4)
.add("RUSSIAN", 5)
.add("THAI", 6);
var UpdatedTitleGroup = new Type("UpdatedTitleGroup") var UpdatedTitleV2Group = new Type("UpdatedTitleV2Group")
.add(new Field("groupName", 1, "string")) .add(new Field("groupName", 1, "string"))
.add(new Field("titles", 2, "UpdatedTitle", "repeated")); .add(new Field("titleGroups", 2, "OriginalTitleGroup", "repeated"));
var OriginalTitleGroup = new Type("OriginalTitleGroup")
.add(new Field("theTitle", 1, "string"))
.add(new Field("titles", 3, "UpdatedTitle", "repeated"));
var UpdatedTitle = new Type("UpdatedTitle") var UpdatedTitle = new Type("UpdatedTitle")
.add(new Field("title", 1, "Title")) .add(new Field("title", 1, "Title"))
@ -263,14 +293,16 @@ const val DECODE_SCRIPT: String =
.add(Popup) .add(Popup)
.add(SuccessResult) .add(SuccessResult)
.add(TitleRankingView) .add(TitleRankingView)
.add(AllTitlesView) .add(AllTitlesViewV2)
.add(WebHomeView) .add(AllTitlesGroup)
.add(WebHomeViewV3)
.add(TitleDetailView) .add(TitleDetailView)
.add(UpdateTiming) .add(UpdateTiming)
.add(MangaViewer) .add(MangaViewer)
.add(Title) .add(Title)
.add(Language) .add(Language)
.add(UpdatedTitleGroup) .add(UpdatedTitleV2Group)
.add(OriginalTitleGroup)
.add(UpdatedTitle) .add(UpdatedTitle)
.add(Chapter) .add(Chapter)
.add(Page) .add(Page)

View File

@ -14,7 +14,7 @@ class MangaPlusFactory : SourceFactory {
} }
class MangaPlusEnglish : MangaPlus("en", "eng", Language.ENGLISH) class MangaPlusEnglish : MangaPlus("en", "eng", Language.ENGLISH)
class MangaPlusIndonesian : MangaPlus("id", "eng", Language.INDONESIAN) class MangaPlusIndonesian : MangaPlus("id", "ind", Language.INDONESIAN)
class MangaPlusPortuguese : MangaPlus("pt-BR", "eng", Language.PORTUGUESE_BR) class MangaPlusPortuguese : MangaPlus("pt-BR", "ptb", Language.PORTUGUESE_BR)
class MangaPlusSpanish : MangaPlus("es", "esp", Language.SPANISH) class MangaPlusSpanish : MangaPlus("es", "esp", Language.SPANISH)
class MangaPlusThai : MangaPlus("th", "eng", Language.THAI) class MangaPlusThai : MangaPlus("th", "tha", Language.THAI)