From 08e4481f5d5da6bfaf95a294c4c416d0ff474156 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sat, 29 Aug 2020 14:44:48 -0300 Subject: [PATCH] Update UnionMangas url. (#4249) Update UnionMangas url --- src/pt/unionmangas/build.gradle | 2 +- .../extension/pt/unionmangas/UnionMangas.kt | 67 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/pt/unionmangas/build.gradle b/src/pt/unionmangas/build.gradle index 64eac6354..87731fed5 100644 --- a/src/pt/unionmangas/build.gradle +++ b/src/pt/unionmangas/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Union Mangás' pkgNameSuffix = 'pt.unionmangas' extClass = '.UnionMangas' - extVersionCode = 15 + extVersionCode = 16 libVersion = '1.2' } diff --git a/src/pt/unionmangas/src/eu/kanade/tachiyomi/extension/pt/unionmangas/UnionMangas.kt b/src/pt/unionmangas/src/eu/kanade/tachiyomi/extension/pt/unionmangas/UnionMangas.kt index 48199eaf1..866d441e0 100644 --- a/src/pt/unionmangas/src/eu/kanade/tachiyomi/extension/pt/unionmangas/UnionMangas.kt +++ b/src/pt/unionmangas/src/eu/kanade/tachiyomi/extension/pt/unionmangas/UnionMangas.kt @@ -33,7 +33,7 @@ class UnionMangas : ParsedHttpSource() { override val name = "Union Mangás" - override val baseUrl = "https://unionleitor.top" + override val baseUrl = "https://unionmangas.top" override val lang = "pt-BR" @@ -50,11 +50,12 @@ class UnionMangas : ParsedHttpSource() { override fun headersBuilder(): Headers.Builder = Headers.Builder() .add("User-Agent", USER_AGENT) .add("Origin", baseUrl) - .add("Referer", "$baseUrl/awx") + .add("Referer", "$baseUrl/ayx") override fun popularMangaRequest(page: Int): Request { + val listPath = if (page == 1) "" else "/visualizacoes/${page - 1}" val newHeaders = headersBuilder() - .set("Referer", "$baseUrl/lista-mangas" + (if (page == 1) "" else "/visualizacoes/${page - 1}")) + .set("Referer", "$baseUrl/lista-mangas$listPath") .build() val pageStr = if (page != 1) "/$page" else "" @@ -138,31 +139,17 @@ class UnionMangas : ParsedHttpSource() { setUrlWithoutDomain("$baseUrl/perfil-manga/${obj["url"].string}") } - override fun mangaDetailsParse(document: Document): SManga { + override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply { val infoElement = document.select("div.tamanho-bloco-perfil").first() - val elAuthor = infoElement.select("div.row:eq(2) div.col-md-8:eq(4)").first() - val elArtist = infoElement.select("div.row:eq(2) div.col-md-8:eq(5)").first() - val elGenre = infoElement.select("div.row:eq(2) div.col-md-8:eq(3)").first() - val elStatus = infoElement.select("div.row:eq(2) div.col-md-8:eq(6)").first() - val elDescription = infoElement.select("div.row:eq(2) div.col-md-8:eq(8)").first() - val imgThumbnail = infoElement.select(".img-thumbnail").first() - val elTitle = infoElement.select("h2").first() + val rowInfo = infoElement.select("div.row:eq(2)").first() - return SManga.create().apply { - title = elTitle!!.text().withoutLanguage() - author = elAuthor?.textWithoutLabel() - artist = elArtist?.textWithoutLabel() - genre = elGenre?.textWithoutLabel() - status = parseStatus(elStatus?.text().orEmpty()) - description = elDescription?.text() - thumbnail_url = imgThumbnail?.attr("src") - } - } - - private fun parseStatus(status: String) = when { - status.contains("Ativo") -> SManga.ONGOING - status.contains("Completo") -> SManga.COMPLETED - else -> SManga.UNKNOWN + title = infoElement.select("h2").text().withoutLanguage() + author = rowInfo.select("div.col-md-8:eq(4)").first().textWithoutLabel() + artist = rowInfo.select("div.col-md-8:eq(5)").first().textWithoutLabel() + genre = rowInfo.select("div.col-md-8:eq(3)").first().textWithoutLabel() + status = rowInfo.select("div.col-md-8:eq(6)").first().text().toStatus() + description = rowInfo.select("div.col-md-8:eq(8)").first().text() + thumbnail_url = infoElement.select(".img-thumbnail").first().attr("src") } override fun chapterListSelector() = "div.row.lancamento-linha" @@ -173,10 +160,11 @@ class UnionMangas : ParsedHttpSource() { name = firstColumn.select("a").first().text() scanlator = secondColumn?.select("a")?.joinToString { it.text() } - date_upload = DATE_FORMATTER.tryParseTime(firstColumn.select("span").last()!!.text()) + date_upload = firstColumn.select("span").last()!!.text().toDate() // For some reason, setUrlWithoutDomain does not work when the url have spaces. - val absoluteUrlFixed = firstColumn.select("a").first().attr("href") + val absoluteUrlFixed = firstColumn.select("a").first() + .attr("href") .replace(" ", "%20") setUrlWithoutDomain(absoluteUrlFixed) } @@ -184,7 +172,9 @@ class UnionMangas : ParsedHttpSource() { override fun pageListParse(document: Document): List { return document.select("img.img-responsive.img-manga") .filter { it.attr("src").contains("/leitor/") } - .mapIndexed { i, element -> Page(i, document.location(), element.absUrl("src")) } + .mapIndexed { i, element -> + Page(i, document.location(), element.absUrl("src")) + } } override fun imageUrlParse(document: Document) = "" @@ -203,26 +193,35 @@ class UnionMangas : ParsedHttpSource() { override fun searchMangaNextPageSelector() = throw Exception("This method should not be called!") - private fun SimpleDateFormat.tryParseTime(date: String): Long { + private fun String.toDate(): Long { return try { - parse(date)?.time ?: 0L + DATE_FORMATTER.parse(this)?.time ?: 0L } catch (e: ParseException) { 0L } } - private fun String.withoutLanguage(): String = replace("(pt-br)", "", true).trim() + private fun String.toStatus(): Int = when { + contains("Ativo") -> SManga.ONGOING + contains("Completo") -> SManga.COMPLETED + else -> SManga.UNKNOWN + } + + private fun String.withoutLanguage(): String = + replace("(pt-br)", "", true).trim() private fun Element.textWithoutLabel(): String = text()!!.substringAfter(":").trim() private fun Response.asJsonObject(): JsonObject = JSON_PARSER.parse(body()!!.string()).obj companion object { - private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" + private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36" private val JSON_PARSER by lazy { JsonParser() } - private val DATE_FORMATTER by lazy { SimpleDateFormat("(dd/MM/yyyy)", Locale.ENGLISH) } + private val DATE_FORMATTER by lazy { + SimpleDateFormat("(dd/MM/yyyy)", Locale.ENGLISH) + } const val PREFIX_ID_SEARCH = "id:" }