From e2d97e0860666d942017b57bfab2811ae4172e2d Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Sun, 2 Jun 2024 02:32:19 -0500 Subject: [PATCH] HentaiRead: Fix images (#3343) * Fix images * yep --- src/en/hentairead/build.gradle | 2 +- .../extension/en/hentairead/Hentairead.kt | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/en/hentairead/build.gradle b/src/en/hentairead/build.gradle index 474321096..4a786702c 100644 --- a/src/en/hentairead/build.gradle +++ b/src/en/hentairead/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.Hentairead' themePkg = 'madara' baseUrl = 'https://hentairead.com' - overrideVersionCode = 5 + overrideVersionCode = 6 isNsfw = true } diff --git a/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/Hentairead.kt b/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/Hentairead.kt index ae0b24c79..c20d6cad1 100644 --- a/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/Hentairead.kt +++ b/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/Hentairead.kt @@ -12,6 +12,7 @@ import kotlinx.serialization.decodeFromString import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request import org.jsoup.nodes.Document +import org.jsoup.nodes.Element import rx.Observable import java.text.SimpleDateFormat import java.util.Locale @@ -20,6 +21,21 @@ class Hentairead : Madara("HentaiRead", "https://hentairead.com", "en", dateForm override val versionId: Int = 2 + private val cdnHeaders = super.headersBuilder() + .add("Accept", "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8") + .build() + + override val client = super.client.newBuilder() + .addInterceptor { chain -> + val request = chain.request() + val url = request.url.toString() + if (url.contains("/wp-content/uploads/")) { + return@addInterceptor chain.proceed(request.newBuilder().headers(cdnHeaders).build()) + } + chain.proceed(request) + } + .build() + override val mangaSubString = "hentai" override val fetchGenres = false @@ -86,6 +102,16 @@ class Hentairead : Madara("HentaiRead", "https://hentairead.com", "en", dateForm } return GET(baseUrl + url, headers) } + + override fun imageFromElement(element: Element): String? { + return when { + element.hasAttr("data-src") -> element.attr("abs:data-src") + element.hasAttr("data-lazy-src") -> element.attr("abs:data-lazy-src") + element.hasAttr("srcset") -> element.attr("abs:srcset").substringBefore(" ").removeSuffix(",") + element.hasAttr("data-cfsrc") -> element.attr("abs:data-cfsrc") + else -> element.attr("abs:src") + } + } } @Serializable