From 7cfd2858c901eb60d6ba270d22c21c3dc324b05a Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sat, 9 May 2020 12:29:51 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20wrong=20title=20parsing=20at=20Golden=20M?= =?UTF-8?q?ang=C3=A1s.=20(#3082)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pt/goldenmangas/build.gradle | 2 +- .../extension/pt/goldenmangas/GoldenMangas.kt | 60 +++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/pt/goldenmangas/build.gradle b/src/pt/goldenmangas/build.gradle index d28d03aa5..0f5862a4c 100644 --- a/src/pt/goldenmangas/build.gradle +++ b/src/pt/goldenmangas/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Golden Mangás' pkgNameSuffix = 'pt.goldenmangas' extClass = '.GoldenMangas' - extVersionCode = 3 + extVersionCode = 4 libVersion = '1.2' } diff --git a/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt b/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt index e7d89991b..d14c9cfc9 100644 --- a/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt +++ b/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt @@ -24,7 +24,7 @@ class GoldenMangas : ParsedHttpSource() { override val name = "Golden Mangás" - override val baseUrl = "https://goldenmanga.top" + override val baseUrl = "https://goldenmangas.online" override val lang = "pt-BR" @@ -43,11 +43,11 @@ class GoldenMangas : ParsedHttpSource() { override fun popularMangaRequest(page: Int): Request = GET(baseUrl, headers) - override fun popularMangaSelector(): String = "div.itemmanga" + override fun popularMangaSelector(): String = "div#maisLidos div.itemmanga" override fun popularMangaFromElement(element: Element): SManga = SManga.create().apply { - title = removeLanguage(element.select("h3").first().text()) - thumbnail_url = baseUrl + element.select("img").first()?.attr("src") + title = element.select("h3").first().text().withoutLanguage() + thumbnail_url = element.select("img").first()?.attr("abs:src") url = element.attr("href") } @@ -62,10 +62,10 @@ class GoldenMangas : ParsedHttpSource() { override fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply { val infoElement = element.select("div.col-sm-10.col-xs-8 h3").first() - val thumb = element.select("a:first-child div img").first().attr("src") + val thumb = element.select("a:first-child div img").first().attr("abs:src") - title = removeLanguage(infoElement.text()) - thumbnail_url = baseUrl + thumb.replace("w=80&h=120", "w=380&h=600") + title = infoElement.text().withoutLanguage() + thumbnail_url = thumb.replace("w=80&h=120", "w=380&h=600") url = element.select("a:first-child").attr("href") } @@ -85,8 +85,8 @@ class GoldenMangas : ParsedHttpSource() { override fun searchMangaSelector() = "div.mangas.col-lg-2 a" override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply { - title = removeLanguage(element.select("h3").first().text()) - thumbnail_url = baseUrl + element.select("img").first().attr("src") + title = element.select("h3").first().text().withoutLanguage() + thumbnail_url = element.select("img").first().attr("abs:src") url = element.attr("href") } @@ -97,15 +97,15 @@ class GoldenMangas : ParsedHttpSource() { val firstColumn = infoElement.select("div.col-sm-4.text-right > img").first() val secondColumn = infoElement.select("div.col-sm-8").first() - title = removeLanguage(secondColumn.select("h2:eq(1)").text()) - author = removeLabel(secondColumn.select("h5:eq(3)").text()) - artist = removeLabel(secondColumn.select("h5:eq(4)").text()) + title = secondColumn.select("h2:eq(0)").text().withoutLanguage() + author = secondColumn.select("h5:eq(3)")!!.text().withoutLabel() + artist = secondColumn.select("h5:eq(4)")!!.text().withoutLabel() genre = secondColumn.select("h5:eq(2) a") .filter { it.text().isNotEmpty() } .joinToString { it.text() } status = parseStatus(secondColumn.select("h5:eq(5) a").text().orEmpty()) description = document.select("#manga_capitulo_descricao").text() - thumbnail_url = baseUrl + firstColumn.attr("src") + thumbnail_url = firstColumn.attr("abs:src") } private fun parseStatus(status: String) = when { @@ -120,36 +120,48 @@ class GoldenMangas : ParsedHttpSource() { val firstColumn = element.select("a > div.col-sm-5") val secondColumn = element.select("div.col-sm-5.text-right a[href^='http']") - name = firstColumn.select("div.col-sm-5").first().text().substringBefore("(").trim() + name = firstColumn.select("div.col-sm-5").first().text() + .substringBefore("(").trim() scanlator = secondColumn?.joinToString { it.text() } - date_upload = parseChapterDate(firstColumn.select("div.col-sm-5 span[style]").first().text()) + date_upload = DATE_FORMATTER.tryParseTime(firstColumn.select("div.col-sm-5 span[style]").first().text()) url = element.select("a").first().attr("href") } override fun pageListParse(document: Document): List { - val chapImages = document.select("div.col-sm-12[id^='capitulos_images']").first() - val pages = chapImages.select("img[pag]") + val chapterUrl = document.location() + val chapterImages = document.select("div.col-sm-12[id^='capitulos_images']").first() - return pages - .mapIndexed { i, element -> Page(i, "", baseUrl + element.attr("src")) } + return chapterImages.select("img[pag]") + .mapIndexed { i, element -> Page(i, chapterUrl, element.attr("abs:src")) } } override fun imageUrlParse(document: Document) = "" - private fun removeLanguage(text: String): String = text.replace(FLAG_REGEX, "").trim() + override fun imageRequest(page: Page): Request { + val newHeaders = headersBuilder() + .set("Referer", page.url) + .build() - private fun removeLabel(text: String?): String = text!!.substringAfter(":").trim() + return GET(page.imageUrl!!, newHeaders) + } - private fun parseChapterDate(date: String): Long { + private fun String.withoutLanguage(): String = replace(FLAG_REGEX, "").trim() + + private fun String.withoutLabel(): String = substringAfter(":").trim() + + private fun SimpleDateFormat.tryParseTime(date: String): Long { return try { - SimpleDateFormat("(dd/MM/yyyy)", Locale.ENGLISH).parse(date).time + parse(date).time } catch (e: ParseException) { 0L } } companion object { - private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36" + private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" + private val FLAG_REGEX = "\\((Pt[-/]br|Scan)\\)".toRegex(RegexOption.IGNORE_CASE) + + private val DATE_FORMATTER by lazy { SimpleDateFormat("(dd/MM/yyyy)", Locale.ENGLISH) } } }