Update MangaHost url. (#4250)

This commit is contained in:
Alessandro Jean 2020-08-29 23:36:27 -03:00 committed by GitHub
parent 08e4481f5d
commit 29c3798c2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 27 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'MangaHost' extName = 'MangaHost'
pkgNameSuffix = 'pt.mangahost' pkgNameSuffix = 'pt.mangahost'
extClass = '.MangaHost' extClass = '.MangaHost'
extVersionCode = 11 extVersionCode = 12
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -24,7 +24,7 @@ class MangaHost : ParsedHttpSource() {
override val name = "Mangá Host" override val name = "Mangá Host"
override val baseUrl = "https://mangahost2.com" override val baseUrl = "https://mangahosted.com"
override val lang = "pt-BR" override val lang = "pt-BR"
@ -44,8 +44,9 @@ class MangaHost : ParsedHttpSource() {
} }
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
val listPath = if (page == 1) "" else "/mais-visualizados/page/${page - 1}"
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
.set("Referer", "$baseUrl/mangas" + (if (page == 1) "" else "/mais-visualizados/page/${page - 1}")) .set("Referer", "$baseUrl/mangas$listPath")
.build() .build()
val pageStr = if (page != 1) "/page/$page" else "" val pageStr = if (page != 1) "/page/$page" else ""
@ -59,8 +60,9 @@ class MangaHost : ParsedHttpSource() {
override fun popularMangaNextPageSelector() = "div.wp-pagenavi:has(a.nextpostslink)" override fun popularMangaNextPageSelector() = "div.wp-pagenavi:has(a.nextpostslink)"
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
val listPath = if (page == 1) "" else "/lancamentos/page/${page - 1}"
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
.set("Referer", baseUrl + (if (page == 1) "" else "/lancamentos/page/${page - 1}")) .set("Referer", baseUrl + listPath)
.build() .build()
val pageStr = if (page != 1) "/page/$page" else "" val pageStr = if (page != 1) "/page/$page" else ""
@ -82,23 +84,22 @@ class MangaHost : ParsedHttpSource() {
override fun searchMangaSelector() = "table.table-search > tbody > tr > td:eq(0) > a" override fun searchMangaSelector() = "table.table-search > tbody > tr > td:eq(0) > a"
override fun searchMangaFromElement(element: Element): SManga = genericMangaFromElement(element, "data-path") override fun searchMangaFromElement(element: Element): SManga =
genericMangaFromElement(element, "data-path")
override fun searchMangaNextPageSelector(): String? = null override fun searchMangaNextPageSelector(): String? = null
override fun mangaDetailsParse(document: Document): SManga { override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply {
val infoElement = document.select("div.box-content div.w-row div.w-col:eq(1) article") val infoElement = document.select("div.box-content div.w-row div.w-col:eq(1) article")
return SManga.create().apply { author = infoElement.select("div.text li div:contains(Autor:)").textWithoutLabel()
author = infoElement.select("div.text li div:contains(Autor:)").textWithoutLabel() artist = infoElement.select("div.text li div:contains(Arte:)").textWithoutLabel()
artist = infoElement.select("div.text li div:contains(Arte:)").textWithoutLabel() genre = infoElement.select("h3.subtitle + div.tags a").joinToString { it.text() }
genre = infoElement.select("h3.subtitle + div.tags a").joinToString { it.text() } description = infoElement.select("div.text div.paragraph").first()?.text()
description = infoElement.select("div.text div.paragraph").first()?.text() ?.substringBefore("Relacionados:")
?.substringBefore("Relacionados:") status = infoElement.select("div.text li div:contains(Status:)").text().toStatus()
status = infoElement.select("div.text li div:contains(Status:)").text().toStatus() thumbnail_url = document.select("div.box-content div.w-row div.w-col:eq(0) div.widget img")
thumbnail_url = document.select("div.box-content div.w-row div.w-col:eq(0) div.widget img") .attr("src")
.attr("src")
}
} }
override fun chapterListSelector(): String = override fun chapterListSelector(): String =
@ -109,7 +110,7 @@ class MangaHost : ParsedHttpSource() {
scanlator = element.select("div.pop-content small strong").text() scanlator = element.select("div.pop-content small strong").text()
date_upload = element.select("small.clearfix").text() date_upload = element.select("small.clearfix").text()
.substringAfter("Adicionado em ") .substringAfter("Adicionado em ")
.let { DATE_FORMAT.tryParseTime(it) } .toDate()
chapter_number = element.select("div.pop-title span.btn-caps").text() chapter_number = element.select("div.pop-title span.btn-caps").text()
.toFloatOrNull() ?: 1f .toFloatOrNull() ?: 1f
setUrlWithoutDomain(element.select("div.tags a").attr("href")) setUrlWithoutDomain(element.select("div.tags a").attr("href"))
@ -139,20 +140,20 @@ class MangaHost : ParsedHttpSource() {
return GET(page.imageUrl!!, newHeaders) return GET(page.imageUrl!!, newHeaders)
} }
private fun String.toDate(): Long {
return try {
DATE_FORMAT.parse(this)?.time ?: 0L
} catch (e: ParseException) {
0L
}
}
private fun String.toStatus() = when { private fun String.toStatus() = when {
contains("Ativo") -> SManga.ONGOING contains("Ativo") -> SManga.ONGOING
contains("Completo") -> SManga.COMPLETED contains("Completo") -> SManga.COMPLETED
else -> SManga.UNKNOWN else -> SManga.UNKNOWN
} }
private fun SimpleDateFormat.tryParseTime(date: String): Long {
return try {
parse(date)!!.time
} catch (e: ParseException) {
0L
}
}
private fun String.withoutLanguage(): String = replace(LANG_REGEX, "") private fun String.withoutLanguage(): String = replace(LANG_REGEX, "")
private fun String.toLargeUrl(): String = replace(IMAGE_REGEX, ".") private fun String.toLargeUrl(): String = replace(IMAGE_REGEX, ".")
@ -160,11 +161,13 @@ class MangaHost : ParsedHttpSource() {
private fun Elements.textWithoutLabel(): String = text()!!.substringAfter(":").trim() private fun Elements.textWithoutLabel(): String = text()!!.substringAfter(":").trim()
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 LANG_REGEX = "( )?\\((PT-)?BR\\)".toRegex() private val LANG_REGEX = "( )?\\((PT-)?BR\\)".toRegex()
private val IMAGE_REGEX = "_(small|medium|xmedium)\\.".toRegex() private val IMAGE_REGEX = "_(small|medium|xmedium)\\.".toRegex()
private val DATE_FORMAT by lazy { SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH) } private val DATE_FORMAT by lazy {
SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH)
}
} }
} }