From ccb12ca50944284b37cdf006ddb83aa22afd9b59 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Wed, 18 Sep 2019 22:43:23 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20the=20HTTP=20403=20errors=20in=20YES=20Ma?= =?UTF-8?q?ng=C3=A1s=20and=20other=20things=20(#1528)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the HTTP 403 errors in YES Mangás and other things --- src/pt/yesmangas/build.gradle | 2 +- .../extension/pt/yesmangas/YesMangas.kt | 57 +++++++++++-------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/pt/yesmangas/build.gradle b/src/pt/yesmangas/build.gradle index 11e011373..80863b9b2 100644 --- a/src/pt/yesmangas/build.gradle +++ b/src/pt/yesmangas/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: YES Mangás' pkgNameSuffix = 'pt.yesmangas' extClass = '.YesMangas' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' } diff --git a/src/pt/yesmangas/src/eu/kanade/tachiyomi/extension/pt/yesmangas/YesMangas.kt b/src/pt/yesmangas/src/eu/kanade/tachiyomi/extension/pt/yesmangas/YesMangas.kt index 0213c4c0f..b2e3c4bc8 100644 --- a/src/pt/yesmangas/src/eu/kanade/tachiyomi/extension/pt/yesmangas/YesMangas.kt +++ b/src/pt/yesmangas/src/eu/kanade/tachiyomi/extension/pt/yesmangas/YesMangas.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import okhttp3.Headers +import okhttp3.HttpUrl import okhttp3.Request import org.jsoup.Jsoup import org.jsoup.nodes.Document @@ -16,53 +17,56 @@ class YesMangas : ParsedHttpSource() { override val name = "YES Mangás" - override val baseUrl = "https://yesmangasbr.com" + override val baseUrl = "https://yesmangas1.com" override val lang = "pt" override val supportsLatest = true - private val catalogHeaders = Headers.Builder().apply { - add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)") - add("Host", "yesmangasbr.com") - add("Referer", baseUrl) - }.build() + override fun headersBuilder(): Headers.Builder = Headers.Builder() + .add("User-Agent", USER_AGENT) + .add("Origin", baseUrl) + .add("Referer", baseUrl) - override fun popularMangaRequest(page: Int): Request = GET(baseUrl, catalogHeaders) + override fun popularMangaRequest(page: Int): Request = GET(baseUrl, headers) override fun popularMangaSelector(): String = "div#destaques div.three.columns a.img" override fun popularMangaFromElement(element: Element): SManga = SManga.create().apply { - title = element.attr("title").replace(LANG_REGEX.toRegex(), "") + title = element.attr("title").replace(LANG_REGEX, "") thumbnail_url = element.select("img").attr("data-path") - .replace("xmedium", "xlarge") + .replace("xmedium", "xlarge") url = element.attr("href") } override fun popularMangaNextPageSelector(): String? = null - override fun latestUpdatesRequest(page: Int): Request = GET(baseUrl, catalogHeaders) + override fun latestUpdatesRequest(page: Int): Request = GET(baseUrl, headers) override fun latestUpdatesSelector(): String = "div#lancamentos table.u-full-width tbody tr td:eq(0) a" override fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply { - title = element.attr("title").replace(LANG_REGEX.toRegex(), "") + title = element.attr("title").replace(LANG_REGEX, "") thumbnail_url = element.select("img").attr("data-path") - .replace("medium", "xlarge") + .replace("xmedium", "xlarge") setUrlWithoutDomain(element.attr("href")) } override fun latestUpdatesNextPageSelector(): String? = null override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - return GET("$baseUrl/search?q=$query", catalogHeaders) + val url = HttpUrl.parse("$baseUrl/search")!!.newBuilder() + .addQueryParameter("q", query) + + return GET(url.toString(), headers) } override fun searchMangaSelector(): String = "tbody#leituras tr td:eq(0) a" override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply { - title = element.select("img").attr("alt").replace(LANG_REGEX.toRegex(), "") - thumbnail_url = element.select("img").attr("data-path").replace("medium", "xlarge") + title = element.select("img").attr("alt").replace(LANG_REGEX, "") + thumbnail_url = element.select("img").attr("data-path") + .replace("medium", "xlarge") setUrlWithoutDomain(element.attr("href")) } @@ -70,21 +74,22 @@ class YesMangas : ParsedHttpSource() { override fun mangaDetailsParse(document: Document): SManga { var container = document.select("div#descricao") - var status = container.select("ul li:contains(Status)") - var author = container.select("ul li:contains(Autor)") - var artist = container.select("ul li:contains(Desenho)") + var statusEl = container.select("ul li:contains(Status)") + var authorEl = container.select("ul li:contains(Autor)") + var artistEl = container.select("ul li:contains(Desenho)") + var genresEl = container.select("ul li:contains(Categorias)") var synopsis = container.select("article") return SManga.create().apply { - this.status = parseStatus(removeLabel(status.text())) - this.author = removeLabel(author.text()) - this.artist = removeLabel(artist.text()) + status = parseStatus(removeLabel(statusEl.text())) + author = removeLabel(authorEl.text()) + artist = removeLabel(artistEl.text()) description = synopsis.text().substringBefore("Relacionados") + genre = removeLabel(genresEl.text()) + thumbnail_url = container.select("img").first().attr("data-path") } } - private fun removeLabel(info: String) = info.substringAfter(":") - private fun parseStatus(status: String) = when { status.contains("Completo") -> SManga.COMPLETED status.contains("Ativo") -> SManga.ONGOING @@ -112,8 +117,12 @@ class YesMangas : ParsedHttpSource() { override fun imageUrlParse(document: Document): String = "" + private fun removeLabel(info: String) = info.substringAfter(":") + companion object { - private const val LANG_REGEX = "( )?\\((PT-)?BR\\)" + 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 val LANG_REGEX = "( )?\\((PT-)?BR\\)".toRegex() + private const val SCRIPT_BEGIN = "var images = [" private const val SCRIPT_END = "];" private const val SCRIPT_REGEX = "\"|,"