From c50ac5ee877c1712c7eb42e38e30cfdbaa433ea5 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sun, 27 Feb 2022 11:47:19 -0300 Subject: [PATCH] Fix YT chapter images not loading (#10922). (#10944) --- .../madara/yaoitoshokan/src/YaoiToshokan.kt | 29 +++++++++++++++++-- .../multisrc/madara/MadaraGenerator.kt | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt b/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt index 9a80d38f0..3ef84bc3a 100644 --- a/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt +++ b/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt @@ -2,8 +2,11 @@ package eu.kanade.tachiyomi.extension.pt.yaoitoshokan import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.multisrc.madara.Madara +import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.Page +import okhttp3.Headers import okhttp3.OkHttpClient +import okhttp3.Request import org.jsoup.nodes.Document import java.text.SimpleDateFormat import java.util.Locale @@ -11,12 +14,15 @@ import java.util.concurrent.TimeUnit class YaoiToshokan : Madara( "Yaoi Toshokan", - "https://yaoitoshokan.net", + "https://www.yaoitoshokan.net", "pt-BR", SimpleDateFormat("dd MMM yyyy", Locale("pt", "BR")) ) { - override val client: OkHttpClient = super.client.newBuilder() + override fun headersBuilder(): Headers.Builder = super.headersBuilder() + .removeAll("User-Agent") + + override val client: OkHttpClient = network.client.newBuilder() .addInterceptor(RateLimitInterceptor(1, 2, TimeUnit.SECONDS)) .build() @@ -24,11 +30,28 @@ class YaoiToshokan : Madara( override val popularMangaUrlSelector = "div.post-title a:not([target])" override fun pageListParse(document: Document): List { + countViews(document) + return document.select(pageListParseSelector) .mapIndexed { index, element -> // Had to add trim because of white space in source. val imageUrl = element.select("img").attr("data-src").trim() - Page(index, document.location(), imageUrl) + Page(index, "$baseUrl/", imageUrl) } } + + override fun imageRequest(page: Page): Request { + val newHeaders = headersBuilder() + .add("Accept", ACCEPT_IMAGE) + .add("Accept-Language", ACCEPT_LANGUAGE) + .set("Referer", page.url) + .build() + + return GET(page.imageUrl!!, newHeaders) + } + + companion object { + private const val ACCEPT_IMAGE = "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8" + private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,gl;q=0.5" + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt index 569e76dda..15dff6078 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt @@ -456,7 +456,7 @@ class MadaraGenerator : ThemeSourceGenerator { SingleLang("XManga", "https://xmanga.io", "en", isNsfw = true), SingleLang("XuN Scans", "https://xunscans.xyz", "en", overrideVersionCode = 2), SingleLang("Yaoi Hentai", "https://yaoihentai.me", "en", isNsfw = true), - SingleLang("Yaoi Toshokan", "https://yaoitoshokan.net", "pt-BR", isNsfw = true, overrideVersionCode = 3), + SingleLang("Yaoi Toshokan", "https://yaoitoshokan.net", "pt-BR", isNsfw = true, overrideVersionCode = 4), SingleLang("Yaoi.mobi", "https://yaoi.mobi", "en", isNsfw = true, className = "YaoiManga", pkgName = "yaoimanga", overrideVersionCode = 4), SingleLang("YaoiScan", "https://yaoiscan.com", "en", isNsfw = true), SingleLang("YaoiToon", "https://yaoitoon.com", "en", isNsfw = true),