From 023b928462cec881c157297128b29aa1a1ae7027 Mon Sep 17 00:00:00 2001 From: Creepler13 Date: Tue, 3 Dec 2024 14:18:35 +0100 Subject: [PATCH] Fix HentaiRead (#6408) * Fix HentaiRead * Change to Regex * Added Description --- src/en/hentairead/build.gradle | 2 +- .../extension/en/hentairead/HentaiReadDTO.kt | 25 +++++++++++++++++ .../extension/en/hentairead/Hentairead.kt | 28 +++++++++++-------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/en/hentairead/build.gradle b/src/en/hentairead/build.gradle index 45827c6eb..7bcfc9617 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 = 8 + overrideVersionCode = 9 isNsfw = true } diff --git a/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/HentaiReadDTO.kt b/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/HentaiReadDTO.kt index e87a6f576..e5cf1436e 100644 --- a/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/HentaiReadDTO.kt +++ b/src/en/hentairead/src/eu/kanade/tachiyomi/extension/en/hentairead/HentaiReadDTO.kt @@ -12,3 +12,28 @@ class Result( val id: Int, val text: String, ) + +@Serializable +class ImageBaseUrlDto( + val baseUrl: String, +) + +@Serializable +class PagesDto( + val data: Data, +) { + @Serializable + class Data( + val chapter: Chapter, + ) { + @Serializable + class Chapter( + val images: List, + ) { + @Serializable + class Image( + val src: String, + ) + } + } +} 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 095f758de..e11cef338 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 @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.extension.en.hentairead +import android.util.Base64 import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.FilterList @@ -8,7 +9,6 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.UpdateStrategy -import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.Request @@ -185,18 +185,27 @@ class Hentairead : Madara("HentaiRead", "https://hentairead.com", "en", dateForm } } + // chapterExtraData = ({...}); + private val chapterExtraDataRegex = Regex("""= (\{[^;]+)""") + + // window.mMjM5MjM2 = '(eyJkYX...); + private val pagesDataRegex = Regex(""".(ey\S+).\s""") + // From ManhwaHentai - modified override fun pageListParse(document: Document): List { launchIO { countViews(document) } - val pages = document.selectFirst("[id=single-chapter-js-extra]")?.data() - ?.substringAfter(":[") - ?.substringBefore("],") - ?.let { json.decodeFromString>("[$it]") } + val pageBaseUrl = document.selectFirst("[id=single-chapter-js-extra]")?.data() + ?.let { chapterExtraDataRegex.find(it)?.groups }?.get(1)?.value + ?.let { json.decodeFromString(it).baseUrl } + + val pages = document.selectFirst("[id=single-chapter-js-before]")?.data() + ?.let { pagesDataRegex.find(it)?.groups }?.get(1)?.value + ?.let { json.decodeFromString(String(Base64.decode(it, Base64.DEFAULT))) } ?: throw Exception("Failed to find page list. Non-English entries are not supported.") - return pages.mapIndexed { idx, page -> - Page(idx, document.location(), page.src) + return pages.data.chapter.images.mapIndexed { idx, page -> + Page(idx, document.location(), "$pageBaseUrl/${page.src}") } } @@ -238,8 +247,3 @@ class Hentairead : Madara("HentaiRead", "https://hentairead.com", "en", dateForm return json.decodeFromString(body.string()) } } - -@Serializable -class PageDto( - val src: String, -)