Optimize the MangaPlus code a little. (#13652)
This commit is contained in:
parent
b08202cf32
commit
63f0776018
|
@ -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 = 36
|
extVersionCode = 37
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -91,13 +91,7 @@ class MangaPlus(
|
||||||
titleList = result.success.titleRankingView!!.titles
|
titleList = result.success.titleRankingView!!.titles
|
||||||
.filter { it.language == langCode }
|
.filter { it.language == langCode }
|
||||||
|
|
||||||
val mangas = titleList!!.map {
|
val mangas = titleList!!.map(Title::toSManga)
|
||||||
SManga.create().apply {
|
|
||||||
title = it.name
|
|
||||||
thumbnail_url = it.portraitImageUrl
|
|
||||||
url = "#/titles/${it.titleId}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MangasPage(mangas, false)
|
return MangasPage(mangas, false)
|
||||||
}
|
}
|
||||||
|
@ -131,22 +125,16 @@ class MangaPlus(
|
||||||
.flatMap(OriginalTitleGroup::titles)
|
.flatMap(OriginalTitleGroup::titles)
|
||||||
.map(UpdatedTitle::title)
|
.map(UpdatedTitle::title)
|
||||||
.filter { it.language == langCode }
|
.filter { it.language == langCode }
|
||||||
.map {
|
.map(Title::toSManga)
|
||||||
SManga.create().apply {
|
|
||||||
title = it.name
|
|
||||||
thumbnail_url = it.portraitImageUrl
|
|
||||||
url = "#/titles/${it.titleId}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.distinctBy(SManga::title)
|
.distinctBy(SManga::title)
|
||||||
|
|
||||||
return MangasPage(mangas, false)
|
return MangasPage(mangas, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
if (query.startsWith(PREFIX_ID_SEARCH) && query.matches(ID_SEARCH_PATTERN)) {
|
if (query.matches(ID_SEARCH_PATTERN)) {
|
||||||
return titleDetailsRequest(query.removePrefix(PREFIX_ID_SEARCH))
|
return titleDetailsRequest(query.removePrefix(PREFIX_ID_SEARCH))
|
||||||
} else if (query.startsWith(PREFIX_CHAPTER_ID_SEARCH) && query.matches(CHAPTER_ID_SEARCH_PATTERN)) {
|
} else if (query.matches(CHAPTER_ID_SEARCH_PATTERN)) {
|
||||||
return mangaViewerRequest(query.removePrefix(PREFIX_CHAPTER_ID_SEARCH))
|
return mangaViewerRequest(query.removePrefix(PREFIX_CHAPTER_ID_SEARCH))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,13 +161,7 @@ class MangaPlus(
|
||||||
.takeIf { it.language == langCode }
|
.takeIf { it.language == langCode }
|
||||||
?: return MangasPage(emptyList(), hasNextPage = false)
|
?: return MangasPage(emptyList(), hasNextPage = false)
|
||||||
|
|
||||||
val manga = SManga.create().apply {
|
return MangasPage(listOf(mangaPlusTitle.toSManga()), hasNextPage = false)
|
||||||
title = mangaPlusTitle.name
|
|
||||||
thumbnail_url = mangaPlusTitle.portraitImageUrl
|
|
||||||
url = "#/titles/${mangaPlusTitle.titleId}"
|
|
||||||
}
|
|
||||||
|
|
||||||
return MangasPage(listOf(manga), hasNextPage = false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.success.mangaViewer != null) {
|
if (result.success.mangaViewer != null) {
|
||||||
|
@ -202,7 +184,9 @@ class MangaPlus(
|
||||||
titleResult.error!!.langPopup(langCode)?.body ?: intl.unknownError
|
titleResult.error!!.langPopup(langCode)?.body ?: intl.unknownError
|
||||||
}
|
}
|
||||||
|
|
||||||
titleDetailsParse(titleResult.success.titleDetailView!!)
|
titleResult.success.titleDetailView!!
|
||||||
|
.takeIf { it.title.language == langCode }
|
||||||
|
?.toSManga()
|
||||||
}
|
}
|
||||||
|
|
||||||
return MangasPage(listOfNotNull(manga), hasNextPage = false)
|
return MangasPage(listOfNotNull(manga), hasNextPage = false)
|
||||||
|
@ -218,13 +202,7 @@ class MangaPlus(
|
||||||
title.author.contains(filter, ignoreCase = true)
|
title.author.contains(filter, ignoreCase = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val mangas = titleList!!.map {
|
val mangas = titleList!!.map(Title::toSManga)
|
||||||
SManga.create().apply {
|
|
||||||
title = it.name
|
|
||||||
thumbnail_url = it.portraitImageUrl
|
|
||||||
url = "#/titles/${it.titleId}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MangasPage(mangas, hasNextPage = false)
|
return MangasPage(mangas, hasNextPage = false)
|
||||||
}
|
}
|
||||||
|
@ -266,25 +244,11 @@ class MangaPlus(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return titleDetailsParse(result.success.titleDetailView!!)
|
val titleDetails = result.success.titleDetailView!!
|
||||||
|
.takeIf { it.title.language == langCode }
|
||||||
?: throw Exception(intl.notAvailable)
|
?: throw Exception(intl.notAvailable)
|
||||||
}
|
|
||||||
|
|
||||||
private fun titleDetailsParse(details: TitleDetailView): SManga? {
|
return titleDetails.toSManga()
|
||||||
val titleObj = details.title
|
|
||||||
|
|
||||||
val manga = SManga.create().apply {
|
|
||||||
title = titleObj.name
|
|
||||||
author = titleObj.author.replace(" / ", ", ")
|
|
||||||
artist = author
|
|
||||||
description = details.overview + "\n\n" + details.viewingPeriodDescription
|
|
||||||
status = if (details.isCompleted) SManga.COMPLETED else SManga.ONGOING
|
|
||||||
genre = details.genres.joinToString()
|
|
||||||
thumbnail_url = titleObj.portraitImageUrl
|
|
||||||
url = "#/titles/${titleObj.titleId}"
|
|
||||||
}
|
|
||||||
|
|
||||||
return manga.takeIf { titleObj.language == langCode }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListRequest(manga: SManga): Request = titleDetailsRequest(manga.url)
|
override fun chapterListRequest(manga: SManga): Request = titleDetailsRequest(manga.url)
|
||||||
|
@ -309,14 +273,7 @@ class MangaPlus(
|
||||||
return chapters.reversed()
|
return chapters.reversed()
|
||||||
// If the subTitle is null, then the chapter time expired.
|
// If the subTitle is null, then the chapter time expired.
|
||||||
.filter { it.subTitle != null }
|
.filter { it.subTitle != null }
|
||||||
.map {
|
.map(Chapter::toSChapter)
|
||||||
SChapter.create().apply {
|
|
||||||
name = "${it.name} - ${it.subTitle}"
|
|
||||||
date_upload = 1000L * it.startTimeStamp
|
|
||||||
url = "#/viewer/${it.chapterId}"
|
|
||||||
chapter_number = it.name.substringAfter("#").toFloatOrNull() ?: -1f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListRequest(chapter: SChapter): Request {
|
override fun pageListRequest(chapter: SChapter): Request {
|
||||||
|
@ -483,7 +440,7 @@ 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/104.0.0.0 Safari/537.36"
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
|
||||||
|
|
||||||
private const val QUALITY_PREF_KEY = "imageResolution"
|
private const val QUALITY_PREF_KEY = "imageResolution"
|
||||||
private val QUALITY_PREF_ENTRY_VALUES = arrayOf("low", "high", "super_high")
|
private val QUALITY_PREF_ENTRY_VALUES = arrayOf("low", "high", "super_high")
|
||||||
|
@ -492,9 +449,6 @@ class MangaPlus(
|
||||||
private const val SPLIT_PREF_KEY = "splitImage"
|
private const val SPLIT_PREF_KEY = "splitImage"
|
||||||
private const val SPLIT_PREF_DEFAULT_VALUE = true
|
private const val SPLIT_PREF_DEFAULT_VALUE = true
|
||||||
|
|
||||||
val COMPLETED_REGEX = "completado|complete|completo".toRegex()
|
|
||||||
val REEDITION_REGEX = "revival|remasterizada".toRegex()
|
|
||||||
|
|
||||||
private const val NOT_FOUND_SUBJECT = "Not Found"
|
private const val NOT_FOUND_SUBJECT = "Not Found"
|
||||||
|
|
||||||
private const val TITLE_THUMBNAIL_PATH = "title_thumbnail_portrait_list"
|
private const val TITLE_THUMBNAIL_PATH = "title_thumbnail_portrait_list"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.kanade.tachiyomi.extension.all.mangaplus
|
package eu.kanade.tachiyomi.extension.all.mangaplus
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@ -76,18 +78,29 @@ data class TitleDetailView(
|
||||||
get() = firstChapterList.size + lastChapterList.size
|
get() = firstChapterList.size + lastChapterList.size
|
||||||
|
|
||||||
private val isReEdition: Boolean
|
private val isReEdition: Boolean
|
||||||
get() = viewingPeriodDescription.contains(MangaPlus.REEDITION_REGEX)
|
get() = viewingPeriodDescription.contains(REEDITION_REGEX)
|
||||||
|
|
||||||
val isCompleted: Boolean
|
private val isCompleted: Boolean
|
||||||
get() = nonAppearanceInfo.contains(MangaPlus.COMPLETED_REGEX) || isOneShot
|
get() = nonAppearanceInfo.contains(COMPLETED_REGEX) || isOneShot
|
||||||
|
|
||||||
val genres: List<String>
|
private val genres: List<String>
|
||||||
get() = listOfNotNull(
|
get() = listOfNotNull(
|
||||||
"Simulrelease".takeIf { isSimulReleased && !isReEdition && !isOneShot },
|
"Simulrelease".takeIf { isSimulReleased && !isReEdition && !isOneShot },
|
||||||
"One-shot".takeIf { isOneShot },
|
"One-shot".takeIf { isOneShot },
|
||||||
"Re-edition".takeIf { isReEdition },
|
"Re-edition".takeIf { isReEdition },
|
||||||
"Webtoon".takeIf { isWebtoon }
|
"Webtoon".takeIf { isWebtoon }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun toSManga(): SManga = title.toSManga().apply {
|
||||||
|
description = overview + "\n\n" + viewingPeriodDescription
|
||||||
|
status = if (isCompleted) SManga.COMPLETED else SManga.ONGOING
|
||||||
|
genre = genres.joinToString()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val COMPLETED_REGEX = "completado|complete|completo".toRegex()
|
||||||
|
private val REEDITION_REGEX = "revival|remasterizada".toRegex()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -106,7 +119,16 @@ data class Title(
|
||||||
val landscapeImageUrl: String,
|
val landscapeImageUrl: String,
|
||||||
val viewCount: Int = 0,
|
val viewCount: Int = 0,
|
||||||
val language: Language? = Language.ENGLISH
|
val language: Language? = Language.ENGLISH
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
fun toSManga(): SManga = SManga.create().apply {
|
||||||
|
title = name
|
||||||
|
author = this@Title.author.replace(" / ", ", ")
|
||||||
|
artist = author
|
||||||
|
thumbnail_url = portraitImageUrl
|
||||||
|
url = "#/titles/$titleId"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum class Language {
|
enum class Language {
|
||||||
ENGLISH,
|
ENGLISH,
|
||||||
|
@ -142,7 +164,15 @@ data class Chapter(
|
||||||
val startTimeStamp: Int,
|
val startTimeStamp: Int,
|
||||||
val endTimeStamp: Int,
|
val endTimeStamp: Int,
|
||||||
val isVerticalOnly: Boolean = false
|
val isVerticalOnly: Boolean = false
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
fun toSChapter(): SChapter = SChapter.create().apply {
|
||||||
|
name = "${this@Chapter.name} - $subTitle"
|
||||||
|
date_upload = 1000L * startTimeStamp
|
||||||
|
url = "#/viewer/$chapterId"
|
||||||
|
chapter_number = this@Chapter.name.substringAfter("#").toFloatOrNull() ?: -1f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class MangaPlusPage(val mangaPage: MangaPage? = null)
|
data class MangaPlusPage(val mangaPage: MangaPage? = null)
|
||||||
|
|
Loading…
Reference in New Issue