Update MangaHost user-agent (#2591)
* Update MangaHost user agent. * Update name and language. * Remove unused imports.
This commit is contained in:
parent
906d76a9aa
commit
ace294b5e3
|
@ -5,7 +5,7 @@ ext {
|
||||||
appName = 'Tachiyomi: MangaHost'
|
appName = 'Tachiyomi: MangaHost'
|
||||||
pkgNameSuffix = 'pt.mangahost'
|
pkgNameSuffix = 'pt.mangahost'
|
||||||
extClass = '.MangaHost'
|
extClass = '.MangaHost'
|
||||||
extVersionCode = 7
|
extVersionCode = 8
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.extension.pt.mangahost
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
import eu.kanade.tachiyomi.source.model.*
|
import eu.kanade.tachiyomi.source.model.*
|
||||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||||
import okhttp3.*
|
import okhttp3.Headers
|
||||||
|
import okhttp3.HttpUrl
|
||||||
|
import okhttp3.Request
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.nodes.Document
|
import org.jsoup.nodes.Document
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
|
@ -14,11 +16,14 @@ import java.util.Locale
|
||||||
|
|
||||||
class MangaHost : ParsedHttpSource() {
|
class MangaHost : ParsedHttpSource() {
|
||||||
|
|
||||||
override val name = "Manga Host"
|
// Hardcode the id because the name was wrong and the language wasn't specific.
|
||||||
|
override val id: Long = 3926812845500643354
|
||||||
|
|
||||||
|
override val name = "Mangá Host"
|
||||||
|
|
||||||
override val baseUrl = "https://mangahost2.com"
|
override val baseUrl = "https://mangahost2.com"
|
||||||
|
|
||||||
override val lang = "pt"
|
override val lang = "pt-BR"
|
||||||
|
|
||||||
override val supportsLatest = true
|
override val supportsLatest = true
|
||||||
|
|
||||||
|
@ -26,12 +31,14 @@ class MangaHost : ParsedHttpSource() {
|
||||||
.add("User-Agent", USER_AGENT)
|
.add("User-Agent", USER_AGENT)
|
||||||
.add("Referer", baseUrl)
|
.add("Referer", baseUrl)
|
||||||
|
|
||||||
private fun mangaFromElement(element: Element, lazy: Boolean = true): SManga = SManga.create().apply {
|
private fun genericMangaFromElement(element: Element, lazy: Boolean = true): SManga =
|
||||||
title = element.attr("title").replace(LANG_REGEX.toRegex(), "")
|
SManga.create().apply {
|
||||||
thumbnail_url = element.select("img.manga").attr(if (lazy) "data-path" else "src")
|
title = element.attr("title").withoutLanguage()
|
||||||
.replace(IMAGE_REGEX.toRegex(), "_large.")
|
thumbnail_url = element.select("img.manga")
|
||||||
setUrlWithoutDomain(element.attr("href"))
|
.attr(if (lazy) "data-path" else "src")
|
||||||
}
|
.toLargeUrl()
|
||||||
|
setUrlWithoutDomain(element.attr("href"))
|
||||||
|
}
|
||||||
|
|
||||||
override fun popularMangaRequest(page: Int): Request {
|
override fun popularMangaRequest(page: Int): Request {
|
||||||
val pageStr = if (page != 1) "/page/$page" else ""
|
val pageStr = if (page != 1) "/page/$page" else ""
|
||||||
|
@ -40,7 +47,7 @@ class MangaHost : ParsedHttpSource() {
|
||||||
|
|
||||||
override fun popularMangaSelector(): String = "div.thumbnail div a.pull-left"
|
override fun popularMangaSelector(): String = "div.thumbnail div a.pull-left"
|
||||||
|
|
||||||
override fun popularMangaFromElement(element: Element): SManga = mangaFromElement(element)
|
override fun popularMangaFromElement(element: Element): SManga = genericMangaFromElement(element)
|
||||||
|
|
||||||
override fun popularMangaNextPageSelector() = "div.wp-pagenavi:has(a.nextpostslink)"
|
override fun popularMangaNextPageSelector() = "div.wp-pagenavi:has(a.nextpostslink)"
|
||||||
|
|
||||||
|
@ -51,7 +58,7 @@ class MangaHost : ParsedHttpSource() {
|
||||||
|
|
||||||
override fun latestUpdatesSelector() = "table.table-lancamentos > tbody > tr > td:eq(0) > a"
|
override fun latestUpdatesSelector() = "table.table-lancamentos > tbody > tr > td:eq(0) > a"
|
||||||
|
|
||||||
override fun latestUpdatesFromElement(element: Element): SManga = mangaFromElement(element, false)
|
override fun latestUpdatesFromElement(element: Element): SManga = genericMangaFromElement(element, false)
|
||||||
|
|
||||||
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
|
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
|
||||||
|
|
||||||
|
@ -64,7 +71,7 @@ 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 = mangaFromElement(element)
|
override fun searchMangaFromElement(element: Element): SManga = genericMangaFromElement(element)
|
||||||
|
|
||||||
override fun searchMangaNextPageSelector(): String? = null
|
override fun searchMangaNextPageSelector(): String? = null
|
||||||
|
|
||||||
|
@ -98,10 +105,11 @@ class MangaHost : ParsedHttpSource() {
|
||||||
|
|
||||||
if (isNewLayout) {
|
if (isNewLayout) {
|
||||||
val content = Jsoup.parse(element.attr("data-content"))
|
val content = Jsoup.parse(element.attr("data-content"))
|
||||||
val date = content.select("small.clearfix").text().substringAfter("Adicionado em ")
|
val date = content.select("small.clearfix").text()
|
||||||
|
.substringAfter("Adicionado em ")
|
||||||
|
|
||||||
return SChapter.create().apply {
|
return SChapter.create().apply {
|
||||||
name = element.attr("data-original-title").replace(LANG_REGEX.toRegex(), "")
|
name = element.attr("data-original-title").withoutLanguage()
|
||||||
scanlator = content.select("small.clearfix strong").text()
|
scanlator = content.select("small.clearfix strong").text()
|
||||||
date_upload = parseChapterDate(date, DATE_FORMAT_NEW)
|
date_upload = parseChapterDate(date, DATE_FORMAT_NEW)
|
||||||
chapter_number = element.text().toFloatOrNull() ?: 1f
|
chapter_number = element.text().toFloatOrNull() ?: 1f
|
||||||
|
@ -114,16 +122,16 @@ class MangaHost : ParsedHttpSource() {
|
||||||
val thirdColumn = element.select("td:eq(2)")
|
val thirdColumn = element.select("td:eq(2)")
|
||||||
|
|
||||||
return SChapter.create().apply {
|
return SChapter.create().apply {
|
||||||
name = firstColumn.select("a").text().replace(LANG_REGEX.toRegex(), "")
|
name = firstColumn.select("a").text().withoutLanguage()
|
||||||
scanlator = secondColumn.text()
|
scanlator = secondColumn.text()
|
||||||
date_upload = parseChapterDate(thirdColumn.text(), DATE_FORMAT_OLD)
|
date_upload = parseChapterDate(thirdColumn.text(), DATE_FORMAT_OLD)
|
||||||
setUrlWithoutDomain(firstColumn.select("a").attr("href"))
|
setUrlWithoutDomain(firstColumn.select("a").attr("href"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseChapterDate(date: String, format: String) : Long {
|
private fun parseChapterDate(date: String, formatter: SimpleDateFormat) : Long {
|
||||||
return try {
|
return try {
|
||||||
SimpleDateFormat(format, Locale.ENGLISH).parse(date).time
|
formatter.parse(date).time
|
||||||
} catch (e: ParseException) {
|
} catch (e: ParseException) {
|
||||||
0L
|
0L
|
||||||
}
|
}
|
||||||
|
@ -140,8 +148,10 @@ class MangaHost : ParsedHttpSource() {
|
||||||
|
|
||||||
override fun pageListParse(document: Document): List<Page> {
|
override fun pageListParse(document: Document): List<Page> {
|
||||||
val documentStr = document.toString()
|
val documentStr = document.toString()
|
||||||
val images = documentStr.substringAfter(SCRIPT_BEGIN).substringBefore(SCRIPT_END)
|
val images = documentStr
|
||||||
.replace(SCRIPT_REGEX.toRegex(), "")
|
.substringAfter(SCRIPT_BEGIN)
|
||||||
|
.substringBefore(SCRIPT_END)
|
||||||
|
.replace(SCRIPT_REGEX, "")
|
||||||
|
|
||||||
val newDocument = Jsoup.parse(images)
|
val newDocument = Jsoup.parse(images)
|
||||||
val referer = document.select("link[rel='canonical']").first()
|
val referer = document.select("link[rel='canonical']").first()
|
||||||
|
@ -160,19 +170,23 @@ class MangaHost : ParsedHttpSource() {
|
||||||
return GET(page.imageUrl!!, newHeaders)
|
return GET(page.imageUrl!!, newHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.withoutLanguage(): String = replace(LANG_REGEX, "")
|
||||||
|
|
||||||
|
private fun String.toLargeUrl(): String = replace(IMAGE_REGEX, "_large")
|
||||||
|
|
||||||
private fun Elements.textWithoutLabel(): String = text()!!.substringAfter(":")
|
private fun Elements.textWithoutLabel(): String = text()!!.substringAfter(":")
|
||||||
|
|
||||||
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/69.0.3497.92 Safari/537.36"
|
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
|
||||||
|
|
||||||
private const val LANG_REGEX = "( )?\\((PT-)?BR\\)"
|
private val LANG_REGEX = "( )?\\((PT-)?BR\\)".toRegex()
|
||||||
private const val IMAGE_REGEX = "_(small|medium)\\."
|
private val IMAGE_REGEX = "_(small|medium)\\.".toRegex()
|
||||||
|
|
||||||
private const val DATE_FORMAT_OLD = "dd/MM/yyyy"
|
private val DATE_FORMAT_OLD by lazy { SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH) }
|
||||||
private const val DATE_FORMAT_NEW = "MMM d, yyyy"
|
private val DATE_FORMAT_NEW by lazy { SimpleDateFormat("MMM d, yyyy", Locale.ENGLISH) }
|
||||||
|
|
||||||
private const val SCRIPT_BEGIN = "var images = ["
|
private const val SCRIPT_BEGIN = "var images = ["
|
||||||
private const val SCRIPT_END = "];"
|
private const val SCRIPT_END = "];"
|
||||||
private const val SCRIPT_REGEX = "[\",]"
|
private val SCRIPT_REGEX = "[\",]".toRegex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue