From a14fabf78fbb708b33ff7642260b9c9d4eb82913 Mon Sep 17 00:00:00 2001 From: kana-shii <79055104+kana-shii@users.noreply.github.com> Date: Tue, 22 Oct 2024 23:11:17 -0300 Subject: [PATCH] Clean ZinChanManga.com titles (#5646) --- src/en/zinchanmangacom/build.gradle | 2 +- .../en/zinchanmangacom/ZinChanMangaCom.kt | 48 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/en/zinchanmangacom/build.gradle b/src/en/zinchanmangacom/build.gradle index 691d771da..867c51d54 100644 --- a/src/en/zinchanmangacom/build.gradle +++ b/src/en/zinchanmangacom/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.ZinChanMangaCom' themePkg = 'madara' baseUrl = 'https://zinchanmanga.com' - overrideVersionCode = 0 + overrideVersionCode = 1 isNsfw = true } diff --git a/src/en/zinchanmangacom/src/eu/kanade/tachiyomi/extension/en/zinchanmangacom/ZinChanMangaCom.kt b/src/en/zinchanmangacom/src/eu/kanade/tachiyomi/extension/en/zinchanmangacom/ZinChanMangaCom.kt index 6c8585cff..ebeed75b3 100644 --- a/src/en/zinchanmangacom/src/eu/kanade/tachiyomi/extension/en/zinchanmangacom/ZinChanMangaCom.kt +++ b/src/en/zinchanmangacom/src/eu/kanade/tachiyomi/extension/en/zinchanmangacom/ZinChanMangaCom.kt @@ -1,5 +1,51 @@ package eu.kanade.tachiyomi.extension.en.zinchanmangacom import eu.kanade.tachiyomi.multisrc.madara.Madara +import eu.kanade.tachiyomi.source.model.SManga +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element -class ZinChanMangaCom : Madara("ZinChanManga.com", "https://zinchanmanga.com", "en") +class ZinChanMangaCom : Madara("ZinChanManga.com", "https://zinchanmanga.com", "en") { + override val useNewChapterEndpoint = true + + override fun popularMangaFromElement(element: Element): SManga { + return super.popularMangaFromElement(element).apply { + title = url.urlToTitle() ?: title + } + } + + override fun searchMangaFromElement(element: Element): SManga { + return super.searchMangaFromElement(element).apply { + title = url.urlToTitle() ?: title + } + } + + override fun mangaDetailsParse(document: Document): SManga { + return super.mangaDetailsParse(document).apply { + title = document.location().urlToTitle() ?: title + } + } + + private fun String.urlToTitle(): String? { + val slug = substringAfter("/manga/", "") + .substringBefore("/") + .takeUnless { it.isBlank() } + ?: return null + + val result = StringBuilder(slug.length) + var capitalize = true + for (char in slug) { + result.append( + if (char == '-') { + ' ' + } else if (capitalize) { + char.uppercase() + } else { + char.lowercase() + }, + ) + capitalize = char == '-' + } + return result.toString() + } +}