diff --git a/src/all/mangaplus/build.gradle b/src/all/mangaplus/build.gradle index 08c58fb51..bcfdf5ac8 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 = 36 + extVersionCode = 37 } apply from: "$rootDir/common.gradle" 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 b0102f945..230bc2bf8 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 @@ -91,13 +91,7 @@ class MangaPlus( titleList = result.success.titleRankingView!!.titles .filter { it.language == langCode } - val mangas = titleList!!.map { - SManga.create().apply { - title = it.name - thumbnail_url = it.portraitImageUrl - url = "#/titles/${it.titleId}" - } - } + val mangas = titleList!!.map(Title::toSManga) return MangasPage(mangas, false) } @@ -131,22 +125,16 @@ class MangaPlus( .flatMap(OriginalTitleGroup::titles) .map(UpdatedTitle::title) .filter { it.language == langCode } - .map { - SManga.create().apply { - title = it.name - thumbnail_url = it.portraitImageUrl - url = "#/titles/${it.titleId}" - } - } + .map(Title::toSManga) .distinctBy(SManga::title) return MangasPage(mangas, false) } 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)) - } 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)) } @@ -173,13 +161,7 @@ class MangaPlus( .takeIf { it.language == langCode } ?: return MangasPage(emptyList(), hasNextPage = false) - val manga = SManga.create().apply { - title = mangaPlusTitle.name - thumbnail_url = mangaPlusTitle.portraitImageUrl - url = "#/titles/${mangaPlusTitle.titleId}" - } - - return MangasPage(listOf(manga), hasNextPage = false) + return MangasPage(listOf(mangaPlusTitle.toSManga()), hasNextPage = false) } if (result.success.mangaViewer != null) { @@ -202,7 +184,9 @@ class MangaPlus( 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) @@ -218,13 +202,7 @@ class MangaPlus( title.author.contains(filter, ignoreCase = true) } - val mangas = titleList!!.map { - SManga.create().apply { - title = it.name - thumbnail_url = it.portraitImageUrl - url = "#/titles/${it.titleId}" - } - } + val mangas = titleList!!.map(Title::toSManga) 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) - } - private fun titleDetailsParse(details: TitleDetailView): SManga? { - 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 } + return titleDetails.toSManga() } override fun chapterListRequest(manga: SManga): Request = titleDetailsRequest(manga.url) @@ -309,14 +273,7 @@ class MangaPlus( return chapters.reversed() // If the subTitle is null, then the chapter time expired. .filter { it.subTitle != null } - .map { - SChapter.create().apply { - name = "${it.name} - ${it.subTitle}" - date_upload = 1000L * it.startTimeStamp - url = "#/viewer/${it.chapterId}" - chapter_number = it.name.substringAfter("#").toFloatOrNull() ?: -1f - } - } + .map(Chapter::toSChapter) } override fun pageListRequest(chapter: SChapter): Request { @@ -483,7 +440,7 @@ 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/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 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_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 TITLE_THUMBNAIL_PATH = "title_thumbnail_portrait_list" diff --git a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusDto.kt b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusDto.kt index 43108ee12..206d87a41 100644 --- a/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusDto.kt +++ b/src/all/mangaplus/src/eu/kanade/tachiyomi/extension/all/mangaplus/MangaPlusDto.kt @@ -1,5 +1,7 @@ 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.Serializable @@ -76,18 +78,29 @@ data class TitleDetailView( get() = firstChapterList.size + lastChapterList.size private val isReEdition: Boolean - get() = viewingPeriodDescription.contains(MangaPlus.REEDITION_REGEX) + get() = viewingPeriodDescription.contains(REEDITION_REGEX) - val isCompleted: Boolean - get() = nonAppearanceInfo.contains(MangaPlus.COMPLETED_REGEX) || isOneShot + private val isCompleted: Boolean + get() = nonAppearanceInfo.contains(COMPLETED_REGEX) || isOneShot - val genres: List + private val genres: List get() = listOfNotNull( "Simulrelease".takeIf { isSimulReleased && !isReEdition && !isOneShot }, "One-shot".takeIf { isOneShot }, "Re-edition".takeIf { isReEdition }, "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 @@ -106,7 +119,16 @@ data class Title( val landscapeImageUrl: String, val viewCount: Int = 0, 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 { ENGLISH, @@ -142,7 +164,15 @@ data class Chapter( val startTimeStamp: Int, val endTimeStamp: Int, 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 data class MangaPlusPage(val mangaPage: MangaPage? = null)