Fix pages and thumbnails not loading at MangaHost (#3913)

* Fix pages and thumbnails not loading at MangaHost.

* Change thumbnail quality to the best available.
This commit is contained in:
Alessandro Jean 2020-07-26 22:04:01 -03:00 committed by GitHub
parent 42ccc17e4c
commit c0354c9b58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 21 deletions

View File

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

View File

@ -13,7 +13,6 @@ import okhttp3.Headers
import okhttp3.HttpUrl import okhttp3.HttpUrl
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import org.jsoup.Jsoup
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import org.jsoup.select.Elements import org.jsoup.select.Elements
@ -37,12 +36,10 @@ class MangaHost : ParsedHttpSource() {
.add("User-Agent", USER_AGENT) .add("User-Agent", USER_AGENT)
.add("Referer", baseUrl) .add("Referer", baseUrl)
private fun genericMangaFromElement(element: Element): SManga = private fun genericMangaFromElement(element: Element, attr: String = "src"): SManga =
SManga.create().apply { SManga.create().apply {
title = element.attr("title").withoutLanguage() title = element.attr("title").withoutLanguage()
thumbnail_url = element.select("img") thumbnail_url = element.select("img").attr(attr).toLargeUrl()
.attr("data-path")
.toLargeUrl()
setUrlWithoutDomain(element.attr("href").substringBeforeLast("-mh")) setUrlWithoutDomain(element.attr("href").substringBeforeLast("-mh"))
} }
@ -85,7 +82,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 = genericMangaFromElement(element) override fun searchMangaFromElement(element: Element): SManga = genericMangaFromElement(element, "data-path")
override fun searchMangaNextPageSelector(): String? = null override fun searchMangaNextPageSelector(): String? = null
@ -128,17 +125,8 @@ class MangaHost : ParsedHttpSource() {
} }
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
val imagesHtml = document.select("script:containsData(var images)").first()!! return document.select("div#slider a img")
.data() .mapIndexed { i, el -> Page(i, document.location(), el.attr("src")) }
.substringAfter("var images = [")
.substringBefore("];")
.replace(SCRIPT_REGEX, "")
return Jsoup.parse(imagesHtml)
.select("a img")
.mapIndexed { i, el ->
Page(i, document.location(), el.attr("src"))
}
} }
override fun imageUrlParse(document: Document) = "" override fun imageUrlParse(document: Document) = ""
@ -167,7 +155,7 @@ class MangaHost : ParsedHttpSource() {
private fun String.withoutLanguage(): String = replace(LANG_REGEX, "") private fun String.withoutLanguage(): String = replace(LANG_REGEX, "")
private fun String.toLargeUrl(): String = replace(IMAGE_REGEX, "_large.") private fun String.toLargeUrl(): String = replace(IMAGE_REGEX, ".")
private fun Elements.textWithoutLabel(): String = text()!!.substringAfter(":").trim() private fun Elements.textWithoutLabel(): String = text()!!.substringAfter(":").trim()
@ -178,7 +166,5 @@ class MangaHost : ParsedHttpSource() {
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) }
private val SCRIPT_REGEX = "[\",]".toRegex()
} }
} }