Update UnionMangas url. (#4249)

Update UnionMangas url
This commit is contained in:
Alessandro Jean 2020-08-29 14:44:48 -03:00 committed by GitHub
parent 81a9818b84
commit 08e4481f5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 35 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Union Mangás' extName = 'Union Mangás'
pkgNameSuffix = 'pt.unionmangas' pkgNameSuffix = 'pt.unionmangas'
extClass = '.UnionMangas' extClass = '.UnionMangas'
extVersionCode = 15 extVersionCode = 16
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -33,7 +33,7 @@ class UnionMangas : ParsedHttpSource() {
override val name = "Union Mangás" override val name = "Union Mangás"
override val baseUrl = "https://unionleitor.top" override val baseUrl = "https://unionmangas.top"
override val lang = "pt-BR" override val lang = "pt-BR"
@ -50,11 +50,12 @@ class UnionMangas : ParsedHttpSource() {
override fun headersBuilder(): Headers.Builder = Headers.Builder() override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("User-Agent", USER_AGENT) .add("User-Agent", USER_AGENT)
.add("Origin", baseUrl) .add("Origin", baseUrl)
.add("Referer", "$baseUrl/awx") .add("Referer", "$baseUrl/ayx")
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
val listPath = if (page == 1) "" else "/visualizacoes/${page - 1}"
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
.set("Referer", "$baseUrl/lista-mangas" + (if (page == 1) "" else "/visualizacoes/${page - 1}")) .set("Referer", "$baseUrl/lista-mangas$listPath")
.build() .build()
val pageStr = if (page != 1) "/$page" else "" val pageStr = if (page != 1) "/$page" else ""
@ -138,31 +139,17 @@ class UnionMangas : ParsedHttpSource() {
setUrlWithoutDomain("$baseUrl/perfil-manga/${obj["url"].string}") 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 infoElement = document.select("div.tamanho-bloco-perfil").first()
val elAuthor = infoElement.select("div.row:eq(2) div.col-md-8:eq(4)").first() val rowInfo = infoElement.select("div.row:eq(2)").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()
return SManga.create().apply { title = infoElement.select("h2").text().withoutLanguage()
title = elTitle!!.text().withoutLanguage() author = rowInfo.select("div.col-md-8:eq(4)").first().textWithoutLabel()
author = elAuthor?.textWithoutLabel() artist = rowInfo.select("div.col-md-8:eq(5)").first().textWithoutLabel()
artist = elArtist?.textWithoutLabel() genre = rowInfo.select("div.col-md-8:eq(3)").first().textWithoutLabel()
genre = elGenre?.textWithoutLabel() status = rowInfo.select("div.col-md-8:eq(6)").first().text().toStatus()
status = parseStatus(elStatus?.text().orEmpty()) description = rowInfo.select("div.col-md-8:eq(8)").first().text()
description = elDescription?.text() thumbnail_url = infoElement.select(".img-thumbnail").first().attr("src")
thumbnail_url = imgThumbnail?.attr("src")
}
}
private fun parseStatus(status: String) = when {
status.contains("Ativo") -> SManga.ONGOING
status.contains("Completo") -> SManga.COMPLETED
else -> SManga.UNKNOWN
} }
override fun chapterListSelector() = "div.row.lancamento-linha" override fun chapterListSelector() = "div.row.lancamento-linha"
@ -173,10 +160,11 @@ class UnionMangas : ParsedHttpSource() {
name = firstColumn.select("a").first().text() name = firstColumn.select("a").first().text()
scanlator = secondColumn?.select("a")?.joinToString { it.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. // 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") .replace(" ", "%20")
setUrlWithoutDomain(absoluteUrlFixed) setUrlWithoutDomain(absoluteUrlFixed)
} }
@ -184,7 +172,9 @@ class UnionMangas : ParsedHttpSource() {
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
return document.select("img.img-responsive.img-manga") return document.select("img.img-responsive.img-manga")
.filter { it.attr("src").contains("/leitor/") } .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) = "" override fun imageUrlParse(document: Document) = ""
@ -203,26 +193,35 @@ class UnionMangas : ParsedHttpSource() {
override fun searchMangaNextPageSelector() = throw Exception("This method should not be called!") 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 { return try {
parse(date)?.time ?: 0L DATE_FORMATTER.parse(this)?.time ?: 0L
} catch (e: ParseException) { } catch (e: ParseException) {
0L 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 Element.textWithoutLabel(): String = text()!!.substringAfter(":").trim()
private fun Response.asJsonObject(): JsonObject = JSON_PARSER.parse(body()!!.string()).obj private fun Response.asJsonObject(): JsonObject = JSON_PARSER.parse(body()!!.string()).obj
companion object { 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 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:" const val PREFIX_ID_SEARCH = "id:"
} }