From 666fb511863415651e6d4ba2521b54f0ff736250 Mon Sep 17 00:00:00 2001 From: bapeey <90949336+bapeey@users.noreply.github.com> Date: Mon, 28 Oct 2024 05:01:19 -0500 Subject: [PATCH] EternalMangas: Fix data not found (#5731) * fix * edge case --- .../tachiyomi/multisrc/mangaesp/MangaEsp.kt | 2 +- src/all/eternalmangas/build.gradle | 2 +- .../all/eternalmangas/EternalMangas.kt | 70 +++++++++++++++++-- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt b/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt index 2cea58bb1..25abe935f 100644 --- a/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt +++ b/lib-multisrc/mangaesp/src/eu/kanade/tachiyomi/multisrc/mangaesp/MangaEsp.kt @@ -246,7 +246,7 @@ abstract class MangaEsp( companion object { private val UNESCAPE_REGEX = """\\(.)""".toRegex() val MANGA_LIST_REGEX = """self\.__next_f\.push\(.*data\\":(\[.*trending.*])\}""".toRegex() - private val MANGA_DETAILS_REGEX = """self\.__next_f\.push\(.*data\\":(\{.*lastChapters.*\}).*\\"numFollow""".toRegex() + val MANGA_DETAILS_REGEX = """self\.__next_f\.push\(.*data\\":(\{.*lastChapters.*\}).*\\"numFollow""".toRegex() const val MANGAS_PER_PAGE = 15 } } diff --git a/src/all/eternalmangas/build.gradle b/src/all/eternalmangas/build.gradle index 102c6b8aa..09deb9071 100644 --- a/src/all/eternalmangas/build.gradle +++ b/src/all/eternalmangas/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.EternalMangasFactory' themePkg = 'mangaesp' baseUrl = 'https://eternalmangas.com' - overrideVersionCode = 0 + overrideVersionCode = 1 isNsfw = true } diff --git a/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt b/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt index 64734ad2a..cd97fba84 100644 --- a/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt +++ b/src/all/eternalmangas/src/eu/kanade/tachiyomi/extension/all/eternalmangas/EternalMangas.kt @@ -7,11 +7,17 @@ import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage 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.util.asJsoup import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import okhttp3.FormBody import okhttp3.Response +import org.jsoup.Jsoup +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.Locale open class EternalMangas( lang: String, @@ -55,9 +61,62 @@ open class EternalMangas( return parseComicsList(page, query, filters) } - override fun pageListParse(response: Response): List { - var document = response.asJsoup() + override fun mangaDetailsParse(response: Response) = SManga.create().apply { + val body = jsRedirect(response) + MANGA_DETAILS_REGEX.find(body)?.groupValues?.get(1)?.let { + val unescapedJson = it.unescape() + return json.decodeFromString(unescapedJson).toSMangaDetails() + } + + val document = Jsoup.parse(body) + with(document.selectFirst("div#info")!!) { + title = select("div:has(p.font-bold:contains(Títuto)) > p.text-sm").text() + author = select("div:has(p.font-bold:contains(Autor)) > p.text-sm").text() + artist = select("div:has(p.font-bold:contains(Artista)) > p.text-sm").text() + genre = select("div:has(p.font-bold:contains(Género)) > p.text-sm > span").joinToString { it.ownText() } + } + description = document.select("div#sinopsis p").text() + thumbnail_url = document.selectFirst("div.contenedor img.object-cover")?.imgAttr() + } + + private val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US) + + override fun chapterListParse(response: Response): List { + val body = jsRedirect(response) + + MANGA_DETAILS_REGEX.find(body)?.groupValues?.get(1)?.let { + val unescapedJson = it.unescape() + val series = json.decodeFromString(unescapedJson) + return series.chapters.map { chapter -> chapter.toSChapter(seriesPath, series.slug) } + } + + val document = Jsoup.parse(body) + return document.select("div.contenedor > div.grid > div > a").map { + SChapter.create().apply { + name = it.selectFirst("span.text-sm")!!.text() + date_upload = try { + it.selectFirst("span.chapter-date")?.attr("data-date")?.let { date -> + dateFormat.parse(date)?.time + } ?: 0 + } catch (e: ParseException) { + 0 + } + setUrlWithoutDomain(it.selectFirst("a")!!.attr("href")) + } + } + } + + override fun pageListParse(response: Response): List { + val doc = Jsoup.parse(jsRedirect(response)) + return doc.select("main > img").mapIndexed { i, img -> + Page(i, imageUrl = img.imgAttr()) + } + } + + private fun jsRedirect(response: Response): String { + var body = response.body.string() + val document = Jsoup.parse(body) document.selectFirst("body > form[method=post]")?.let { val action = it.attr("action") val inputs = it.select("input") @@ -67,12 +126,9 @@ open class EternalMangas( form.add(input.attr("name"), input.attr("value")) } - document = client.newCall(POST(action, headers, form.build())).execute().asJsoup() - } - - return document.select("main > img").mapIndexed { i, img -> - Page(i, imageUrl = img.imgAttr()) + body = client.newCall(POST(action, headers, form.build())).execute().body.string() } + return body } @Serializable