From febdab05c183134463e6a3baf44be576fe52963d Mon Sep 17 00:00:00 2001 From: Troy121 Date: Fri, 28 Jan 2022 06:49:35 +0100 Subject: [PATCH] Imperfect Comics: Fixed image parsing (#10576) --- .../imperfectcomics/src/ImperfectComics.kt | 24 ++++++++++++------- .../multisrc/madara/MadaraGenerator.kt | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/multisrc/overrides/madara/imperfectcomics/src/ImperfectComics.kt b/multisrc/overrides/madara/imperfectcomics/src/ImperfectComics.kt index fff2aaa0a..36ec7d688 100644 --- a/multisrc/overrides/madara/imperfectcomics/src/ImperfectComics.kt +++ b/multisrc/overrides/madara/imperfectcomics/src/ImperfectComics.kt @@ -19,34 +19,40 @@ import org.jsoup.nodes.Document import java.io.ByteArrayOutputStream import java.io.InputStream import java.text.SimpleDateFormat +import java.util.concurrent.TimeUnit class ImperfectComics : Madara("Imperfect Comics", "https://imperfectcomic.com", "en", SimpleDateFormat("yyyy-MM-dd")) { override val useNewChapterEndpoint: Boolean = true - override val client: OkHttpClient = super.client.newBuilder() + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) .addInterceptor(::imageIntercept) .build() override fun pageListParse(document: Document): List { val mangaId = document.select("#manga-reading-nav-head").attr("data-id") val chapterId = document.select("#wp-manga-current-chap").attr("data-id") - val mangaRegex = """data-id=\"$mangaId\"(?:.|\n)*?(?=\})""".toRegex() - val chapterRegex = """data-id=\"$chapterId\"(?:.|\n)*?(?=\})""".toRegex() + val mangaRegex = """div\[data-id=\"$mangaId\"(?:.|\n)*?(?=\})""".toRegex() + val chapterRegex = """input\[data-id=\"$chapterId\"(?:.|\n)*?(?=\})""".toRegex() val css = document.selectFirst("#wp-custom-css").html() - val props = mangaRegex.find(css).let { mId -> - mId?.value ?: chapterRegex.find(css).let { cId -> - cId?.value ?: "" + + //Checking for chapter first to handle mirrored manga with specific un-mirrored chapters + val props = chapterRegex.find(css).let { cId -> + cId?.value ?: mangaRegex.find(css).let { mId -> + mId?.value ?: "" } } countViews(document) return document.select(pageListParseSelector).mapIndexed { index, element -> - val imageUrl = element.selectFirst("img")?.absUrl("src")!! - .toHttpUrlOrNull()!!.newBuilder() + val imageUrl = element.selectFirst("img")?.let { + it.absUrl(if (it.hasAttr("data-src")) "data-src" else "src") + }!!.toHttpUrlOrNull()!!.newBuilder() - if (props.contains("transform")) + if (props.contains("transform: scaleX(-1)")) imageUrl.addQueryParameter("mirror", "1") if (props.contains("invert")) imageUrl.addQueryParameter("invert", "1") 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 a6dba5f3c..948c2b2ec 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 @@ -119,7 +119,7 @@ class MadaraGenerator : ThemeSourceGenerator { SingleLang("Ichirin No Hana Yuri", "https://ichirinnohanayuri.com.br", "pt-BR", overrideVersionCode = 3), SingleLang("Ikifeng", "https://ikifeng.com", "es", isNsfw = true), SingleLang("Immortal Updates", "https://immortalupdates.com", "en", overrideVersionCode = 2), - SingleLang("Imperfect Comics", "https://imperfectcomic.com", "en", overrideVersionCode = 3), + SingleLang("Imperfect Comics", "https://imperfectcomic.com", "en", overrideVersionCode = 4), SingleLang("Império Scans", "https://imperioscans.com.br", "pt-BR", className = "ImperioScans", overrideVersionCode = 1), SingleLang("InfraFandub", "https://infrafandub.xyz", "es"), SingleLang("Inmortal Scan", "https://manga.mundodrama.site", "es"),