Fix missing information in AR (closes #10076). (#10085)

This commit is contained in:
Alessandro Jean 2021-12-12 20:03:59 -03:00 committed by GitHub
parent ae0f49fc7c
commit 6a1b3ae515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 4 deletions

View File

@ -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<SChapter> {
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)
}
}
}

View File

@ -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) {

View File

@ -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"),