From f56ae7f01e6271e86e2fa41e242d6a41f00844a8 Mon Sep 17 00:00:00 2001 From: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> Date: Wed, 11 Oct 2023 23:07:24 -0300 Subject: [PATCH] Update YM to their new domain and fix no pages found (#18498) Update YM to their new domain and fix no pages found. --- src/pt/yugenmangas/build.gradle | 2 +- .../extension/pt/yugenmangas/YugenMangas.kt | 42 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/pt/yugenmangas/build.gradle b/src/pt/yugenmangas/build.gradle index b7d02f1b5..168effbc5 100644 --- a/src/pt/yugenmangas/build.gradle +++ b/src/pt/yugenmangas/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Yugen Mangás' pkgNameSuffix = 'pt.yugenmangas' extClass = '.YugenMangas' - extVersionCode = 35 + extVersionCode = 36 } apply from: "$rootDir/common.gradle" diff --git a/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangas.kt b/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangas.kt index 6099e5b46..939bd1dcc 100644 --- a/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangas.kt +++ b/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangas.kt @@ -8,6 +8,7 @@ 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.online.ParsedHttpSource +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json @@ -33,7 +34,7 @@ class YugenMangas : ParsedHttpSource() { override val name = "Yugen Mangás" - override val baseUrl = "https://yugenmangas.net.br" + override val baseUrl = "https://yugenmangas.org" override val lang = "pt-BR" @@ -83,7 +84,7 @@ class YugenMangas : ParsedHttpSource() { } override fun searchMangaParse(response: Response): MangasPage { - val result = json.decodeFromString>(response.body.string()) + val result = response.parseAs>() val matches = result.map { SManga.create().apply { title = it.name @@ -120,13 +121,29 @@ class YugenMangas : ParsedHttpSource() { url = element.attr("href") } - override fun pageListParse(document: Document): List { - return document.select("div.chapter-images > img[src]") - .mapIndexed { index, element -> - Page(index, document.location(), element.absUrl("src")) - } + override fun getChapterUrl(chapter: SChapter) = baseUrl + chapter.url + + override fun pageListRequest(chapter: SChapter): Request { + val paths = chapter.url.removePrefix("/").split("/") + + val newHeaders = headersBuilder() + .set("Referer", getChapterUrl(chapter)) + .build() + + return GET("$baseUrl/api/serie/${paths[1]}/chapter/${paths[2]}/images", newHeaders) } + override fun pageListParse(response: Response): List { + val result = response.parseAs() + val chapterUrl = response.request.headers["Referer"].orEmpty() + + return result.images.orEmpty().mapIndexed { index, image -> + Page(index, chapterUrl, "$CDN_BASE_URL/${image.removePrefix("/")}") + } + } + + override fun pageListParse(document: Document) = throw UnsupportedOperationException("Not used") + override fun imageUrlParse(document: Document) = "" override fun imageRequest(page: Page): Request { @@ -140,6 +157,11 @@ class YugenMangas : ParsedHttpSource() { @Serializable private data class SearchResultDto(val name: String, val slug: String) + @Serializable + private data class ReaderDto( + @SerialName("chapter_images") val images: List? = emptyList(), + ) + private fun String.toDate(): Long { return runCatching { DATE_FORMATTER.parse(trim())?.time } .getOrNull() ?: 0L @@ -151,7 +173,13 @@ class YugenMangas : ParsedHttpSource() { else -> SManga.UNKNOWN } + private inline fun Response.parseAs(): T = use { + json.decodeFromString(it.body.string()) + } + companion object { + private const val CDN_BASE_URL = "https://media.yugenmangas.org" + private val DATE_FORMATTER by lazy { SimpleDateFormat("dd.MM.yyyy", Locale("pt", "BR")) }