From aac7a7375f589d9441d38e3c57200f5419d72efd Mon Sep 17 00:00:00 2001 From: curche <72807749+curche@users.noreply.github.com> Date: Sat, 5 Jun 2021 03:43:17 +0530 Subject: [PATCH] Fix chapter names in FallenAngels (#7469) * create override for fallenangels in mmrcms * construct chapter name without manga name previous - : current - Chapter : * remove unnecessary code not specific to fallenangels - name the package correctly to fallenangels - remove excess code copied over from MMRCMS method that isn't required for fallenangel source - refactor parsing date for date_upload - parse the correct Tag from Element to get Chapter title * remove unused regex * update versionCode for FallenAngels in generator --- .../mmrcms/fallenangels/src/FallenAngels.kt | 55 +++++++++++++++++++ .../multisrc/mmrcms/MMRCMSSources.kt | 5 +- 2 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 multisrc/overrides/mmrcms/fallenangels/src/FallenAngels.kt diff --git a/multisrc/overrides/mmrcms/fallenangels/src/FallenAngels.kt b/multisrc/overrides/mmrcms/fallenangels/src/FallenAngels.kt new file mode 100644 index 000000000..0f77a4abf --- /dev/null +++ b/multisrc/overrides/mmrcms/fallenangels/src/FallenAngels.kt @@ -0,0 +1,55 @@ +package eu.kanade.tachiyomi.extension.en.fallenangels + +import eu.kanade.tachiyomi.multisrc.mmrcms.MMRCMS +import eu.kanade.tachiyomi.source.model.SChapter +import eu.kanade.tachiyomi.util.asJsoup +import okhttp3.Response +import org.jsoup.nodes.Element +import java.text.SimpleDateFormat +import java.util.Locale + +class FallenAngels : MMRCMS("Fallen Angels", "https://manga.fascans.com", "en") { + + /** + * Parses the response from the site and returns a list of chapters. + * + * Overriden to allow for null chapters + * + * @param response the response from the site. + */ + override fun chapterListParse(response: Response): List { + val document = response.asJsoup() + return document.select(chapterListSelector()).mapNotNull { nullableChapterFromElement(it) } + } + + /** + * Returns a chapter from the given element. + * + * @param element an element obtained from [chapterListSelector]. + */ + private fun nullableChapterFromElement(element: Element): SChapter? { + val chapter = SChapter.create() + + val titleWrapper = element.select("[class^=chapter-title-rtl]").first() + val chapterElement = titleWrapper.getElementsByTag("a") + val url = chapterElement.attr("href") + + chapter.url = getUrlWithoutBaseUrl(url) + + // Construct chapter names + // before -> : + // after -> Chapter : + val chapterText = chapterElement.text() + val numberRegex = Regex("""\d+""") + val chapterNumber = numberRegex.find(chapterText)?.value.orEmpty() + val chapterTitle = titleWrapper.getElementsByTag("em").text() + chapter.name = "Chapter $chapterNumber : $chapterTitle"// titleWrapper.text() + + // Parse date + val dateText = element.getElementsByClass("date-chapter-title-rtl").text().trim() + val dateFormat = SimpleDateFormat("d MMM. yyyy", Locale.US) + chapter.date_upload = dateFormat.parse(dateText)?.time ?: 0L + + return chapter + } +} diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt index 7fa4223f0..ce84935ed 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMSSources.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.multisrc.mmrcms import java.util.Locale - class MMRCMSSources { companion object { sealed class SourceData { @@ -37,7 +36,7 @@ class MMRCMSSources { val sourceList: List = listOf( SourceData.Single("مانجا اون لاين", "https://onma.me", "ar", className = "onma"), SourceData.Single("Read Comics Online", "https://readcomicsonline.ru", "en"), - SourceData.Single("Fallen Angels", "https://manga.fascans.com", "en"), + SourceData.Single("Fallen Angels", "https://manga.fascans.com", "en", overrideVersionCode = 1), SourceData.Single("Zahard", "https://zahard.top", "en", overrideVersionCode = 1), SourceData.Single("Manhwas Men", "https://manhwas.men", "en", isNsfw = true, overrideVersionCode = 1), SourceData.Single("Scan FR", "https://www.scan-fr.cc", "fr"), @@ -74,8 +73,6 @@ class MMRCMSSources { } } - - //SingleLang("Mangás Yuri", "https://mangasyuri.net", "pt-BR", className = "MangasYuri"), override val id: Long = 6456162511058446409 //SingleLang("FR Scan", "https://www.frscan.me", "fr"), // Reference from old Factory Source