From 6a1b3ae51508af165fec938cc2fc1c5896960958 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sun, 12 Dec 2021 20:03:59 -0300 Subject: [PATCH] Fix missing information in AR (closes #10076). (#10085) --- .../mmrcms/animaregia/src/AnimaRegia.kt | 101 ++++++++++++++++++ .../tachiyomi/multisrc/mmrcms/MMRCMS.kt | 6 +- .../multisrc/mmrcms/MMRCMSSources.kt | 2 +- 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/multisrc/overrides/mmrcms/animaregia/src/AnimaRegia.kt b/multisrc/overrides/mmrcms/animaregia/src/AnimaRegia.kt index 9488f165c..9fd0ceb5c 100644 --- a/multisrc/overrides/mmrcms/animaregia/src/AnimaRegia.kt +++ b/multisrc/overrides/mmrcms/animaregia/src/AnimaRegia.kt @@ -2,13 +2,114 @@ package eu.kanade.tachiyomi.extension.pt.animaregia import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.multisrc.mmrcms.MMRCMS +import eu.kanade.tachiyomi.source.model.MangasPage +import eu.kanade.tachiyomi.source.model.SChapter +import eu.kanade.tachiyomi.source.model.SManga +import eu.kanade.tachiyomi.util.asJsoup import okhttp3.OkHttpClient +import okhttp3.Response +import org.jsoup.nodes.Element +import java.text.SimpleDateFormat +import java.util.Locale import java.util.concurrent.TimeUnit class AnimaRegia : MMRCMS("AnimaRegia", "https://animaregia.net", "pt-BR") { + override val id: Long = 4378659695320121364 override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(RateLimitInterceptor(1, 2, TimeUnit.SECONDS)) .build() + + // Remove the language tag from the title name. + override fun internalMangaParse(response: Response): MangasPage { + return super.internalMangaParse(response).let { + it.copy( + mangas = it.mangas.map { manga -> + manga.apply { title = title.removeSuffix(LANGUAGE_SUFFIX) } + } + ) + } + } + + override fun latestUpdatesFromElement(element: Element, urlSelector: String): SManga? { + return super.latestUpdatesFromElement(element, urlSelector) + ?.apply { title = title.removeSuffix(LANGUAGE_SUFFIX) } + } + + override fun gridLatestUpdatesFromElement(element: Element): SManga { + return super.gridLatestUpdatesFromElement(element) + .apply { title = title.removeSuffix(LANGUAGE_SUFFIX) } + } + + // Override searchMangaParse with same body from internalMangaParse since + // it can use the other endpoint instead. + override fun searchMangaParse(response: Response): MangasPage { + return super.searchMangaParse(response).let { + it.copy( + mangas = it.mangas.map { manga -> + manga.apply { title = title.removeSuffix(LANGUAGE_SUFFIX) } + } + ) + } + } + + // The website modified the information panel. + override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply { + val document = response.asJsoup() + + title = document.selectFirst("h1.widget-title").text() + thumbnail_url = coverGuess( + document.select("div.col-sm-5 img.img-thumbnail").firstOrNull()?.attr("abs:src"), + document.location() + ) + description = document.select("div.row div.well p").text().trim() + + for (element in document.select("div.col-sm-5 ul.list-group li.list-group-item")) { + when (element.text().trim().toLowerCase(BRAZILIAN_LOCALE).substringBefore(":")) { + "autor(es)" -> author = element.select("a") + .joinToString(", ") { it.text().trim() } + "artist(s)" -> artist = element.select("a") + .joinToString(", ") { it.text().trim() } + "categorias" -> genre = element.select("a") + .joinToString(", ") { it.text().trim() } + "status" -> status = when (element.select("span.label").text()) { + "Completo", "ConcluĂ­do" -> SManga.COMPLETED + "Ativo" -> SManga.ONGOING + else -> SManga.UNKNOWN + } + } + } + } + + override fun chapterListSelector(): String = "div.row ul.chapters > li" + + override fun chapterListParse(response: Response): List { + return response.asJsoup() + .select(chapterListSelector()) + .map { el -> + SChapter.create().apply { + name = el.select("h5.chapter-title-rtl").text() + scanlator = el.select("div.col-md-3 ul li") + .joinToString(" & ") { it.text().trim() } + date_upload = el.select("div.col-md-4").firstOrNull() + ?.text()?.removeSuffix("Download")?.toDate() ?: 0L + setUrlWithoutDomain(el.select("h5.chapter-title-rtl a").first().attr("href")) + } + } + } + + private fun String.toDate(): Long { + return runCatching { DATE_FORMAT.parse(trim())?.time } + .getOrNull() ?: 0L + } + + companion object { + private const val LANGUAGE_SUFFIX = " (pt-br)" + private val BRAZILIAN_LOCALE = Locale("pt", "BR") + + private val DATE_FORMAT by lazy { + SimpleDateFormat("dd MMM. yyyy", Locale.ENGLISH) + } + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMS.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMS.kt index 1847fbadc..5ea2639fa 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMS.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mmrcms/MMRCMS.kt @@ -200,7 +200,7 @@ abstract class MMRCMS( } private fun latestUpdatesSelector() = "div.mangalist div.manga-item" private fun latestUpdatesNextPageSelector() = "a[rel=next]" - private fun latestUpdatesFromElement(element: Element, urlSelector: String): SManga? { + protected open fun latestUpdatesFromElement(element: Element, urlSelector: String): SManga? { return element.select(urlSelector).first().let { titleElement -> if (titleElement.text() in latestTitles) { null @@ -215,7 +215,7 @@ abstract class MMRCMS( } } private fun gridLatestUpdatesSelector() = "div.mangalist div.manga-item, div.grid-manga tr" - private fun gridLatestUpdatesFromElement(element: Element): SManga = SManga.create().apply { + protected open fun gridLatestUpdatesFromElement(element: Element): SManga = SManga.create().apply { element.select("a.chart-title").let { setUrlWithoutDomain(it.attr("href")) title = it.text() @@ -223,7 +223,7 @@ abstract class MMRCMS( thumbnail_url = element.select("img").attr("abs:src") } - private fun internalMangaParse(response: Response): MangasPage { + protected open fun internalMangaParse(response: Response): MangasPage { val document = response.asJsoup() val internalMangaSelector = when (name) { 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 16f5b7283..3610d0276 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 @@ -57,7 +57,7 @@ class MMRCMSSources { SourceData.Single("Mangazuki Raws", "https://raws.mangazuki.co", "ko"), SourceData.Single("Mangazuki", "https://mangazuki.co", "en"), SourceData.Single("Remangas", "https://remangas.top", "pt-BR", overrideVersionCode = 2), - SourceData.Single("AnimaRegia", "https://animaregia.net", "pt-BR", overrideVersionCode = 2), + SourceData.Single("AnimaRegia", "https://animaregia.net", "pt-BR", overrideVersionCode = 3), SourceData.Single("MangaVadisi", "http://manga-v2.mangavadisi.org", "tr"), SourceData.Single("MangaID", "https://mangaid.click", "id"), SourceData.Single("Jpmangas", "https://jpmangas.co", "fr"),