From 5b1d9f51bdc7341736f8f054afb96f7b16f278cc Mon Sep 17 00:00:00 2001 From: Eshlender <35057681+e-shl@users.noreply.github.com> Date: Sat, 15 Oct 2022 01:56:14 +0500 Subject: [PATCH] [RU]Mangahub fix (#13856) * [RU]Mangahub fix * update user agent * cover reload --- src/ru/mangahub/build.gradle | 2 +- .../extension/ru/mangahub/Mangahub.kt | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/ru/mangahub/build.gradle b/src/ru/mangahub/build.gradle index d71795d79..8869027d6 100644 --- a/src/ru/mangahub/build.gradle +++ b/src/ru/mangahub/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Mangahub' pkgNameSuffix = 'ru.mangahub' extClass = '.Mangahub' - extVersionCode = 15 + extVersionCode = 16 } apply from: "$rootDir/common.gradle" diff --git a/src/ru/mangahub/src/eu/kanade/tachiyomi/extension/ru/mangahub/Mangahub.kt b/src/ru/mangahub/src/eu/kanade/tachiyomi/extension/ru/mangahub/Mangahub.kt index 3c1117ff7..75e6bb06b 100644 --- a/src/ru/mangahub/src/eu/kanade/tachiyomi/extension/ru/mangahub/Mangahub.kt +++ b/src/ru/mangahub/src/eu/kanade/tachiyomi/extension/ru/mangahub/Mangahub.kt @@ -19,6 +19,8 @@ import org.jsoup.nodes.Element import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale +import kotlin.math.absoluteValue +import kotlin.random.Random open class Mangahub : ParsedHttpSource() { @@ -30,10 +32,17 @@ open class Mangahub : ParsedHttpSource() { override val supportsLatest = true - override val client: OkHttpClient = network.client.newBuilder() + override val client: OkHttpClient = network.cloudflareClient.newBuilder() .rateLimit(2) .build() + private val userAgentRandomizer = "${Random.nextInt().absoluteValue}" + + override fun headersBuilder() = Headers.Builder().apply { + add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.$userAgentRandomizer") + add("Referer", baseUrl) + } + private val json: Json by injectLazy() override fun popularMangaRequest(page: Int): Request = @@ -48,16 +57,16 @@ open class Mangahub : ParsedHttpSource() { override fun popularMangaFromElement(element: Element): SManga { val manga = SManga.create() - manga.thumbnail_url = element.select("div.comic-grid-image").attr("data-background-image") - manga.title = element.select("a.comic-grid-name").text() - manga.setUrlWithoutDomain(element.select("a.comic-grid-name").attr("href")) + manga.thumbnail_url = baseUrl + element.select("div.fast-view-layer-scale").attr("data-background-image") + manga.title = element.select("a.fw-medium").text() + manga.setUrlWithoutDomain(element.select("a.fw-medium").attr("href")) return manga } override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element) - override fun popularMangaNextPageSelector() = "li.next > a" + override fun popularMangaNextPageSelector() = ".page-link:contains(→)" override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector() @@ -65,15 +74,10 @@ open class Mangahub : ParsedHttpSource() { return GET("$baseUrl/search/manga?query=$query&sort=rating_short&page=$page") } - override fun searchMangaSelector() = "div.comic-grid-col-xl" + override fun searchMangaSelector() = popularMangaSelector() - override fun searchMangaFromElement(element: Element): SManga { - val manga = SManga.create() - manga.thumbnail_url = element.select("div.comic-grid-image").attr("data-background-image") - manga.title = element.select("a.comic-grid-name").text() - manga.setUrlWithoutDomain(element.select("a.comic-grid-name").attr("href")) - return manga - } + override fun searchMangaFromElement(element: Element): SManga = + popularMangaFromElement(element) override fun searchMangaNextPageSelector(): String? = popularMangaNextPageSelector() @@ -87,7 +91,7 @@ open class Mangahub : ParsedHttpSource() { manga.genre = document.select(".tags").text().replace(" ", ", ") manga.description = document.select("div.markdown-style").text() manga.status = parseStatus(document.select("div.detail-attr:contains(перевод):eq(0)").toString()) - manga.thumbnail_url = document.select("img.cover-detail").attr("src") + manga.thumbnail_url = baseUrl + document.select("img.cover-detail").attr("src") return manga }