From 6770a0672a13dd20084cd28305bb67b558a9e332 Mon Sep 17 00:00:00 2001 From: Chopper <156493704+ttony2chopper@users.noreply.github.com> Date: Thu, 23 May 2024 07:57:33 -0300 Subject: [PATCH] Yugen Mangas: bugfix (#3193) Update paths and fix chapter pages --- src/pt/yugenmangas/build.gradle | 2 +- .../extension/pt/yugenmangas/YugenMangas.kt | 43 ++++++++----------- .../pt/yugenmangas/YugenMangasDto.kt | 13 +++--- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/pt/yugenmangas/build.gradle b/src/pt/yugenmangas/build.gradle index 806064114..41660ab7d 100644 --- a/src/pt/yugenmangas/build.gradle +++ b/src/pt/yugenmangas/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Yugen Mangás' extClass = '.YugenMangas' - extVersionCode = 38 + extVersionCode = 39 } 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 ae2ef2d1e..5c9724688 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 @@ -9,6 +9,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.HttpSource +import eu.kanade.tachiyomi.util.asJsoup import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -53,13 +54,12 @@ class YugenMangas : HttpSource() { .add("Sec-Fetch-Site", "same-site") override fun popularMangaRequest(page: Int): Request { - return GET("$API_BASE_URL/random_top_series/", apiHeaders) + return GET("$API_BASE_URL/top_series_all/", apiHeaders) } override fun popularMangaParse(response: Response): MangasPage { val result = response.parseAs>() - val mangaList = result.map { it.toSManga(baseUrl) } - + val mangaList = result.map { it.toSManga(API_HOST) } return MangasPage(mangaList, hasNextPage = false) } @@ -70,8 +70,8 @@ class YugenMangas : HttpSource() { override fun latestUpdatesParse(response: Response) = popularMangaParse(response) override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - val apiUrl = "$API_BASE_URL/series/list".toHttpUrl().newBuilder() - .addQueryParameter("query", query) + val apiUrl = "$API_BASE_URL/series".toHttpUrl().newBuilder() + .addQueryParameter("search", query) .build() return GET(apiUrl, apiHeaders) @@ -81,14 +81,13 @@ class YugenMangas : HttpSource() { override fun mangaDetailsRequest(manga: SManga): Request { val slug = manga.url.removePrefix("/series/") - - return POST("$API_BASE_URL/serie_details/$slug", apiHeaders) + return POST("$API_BASE_URL/serie/serie_details/$slug", apiHeaders) } override fun getMangaUrl(manga: SManga) = baseUrl + manga.url override fun mangaDetailsParse(response: Response): SManga { - return response.parseAs().toSManga(baseUrl) + return response.parseAs().toSManga(API_BASE_URL) } override fun chapterListRequest(manga: SManga): Request { @@ -101,7 +100,7 @@ class YugenMangas : HttpSource() { .set("Content-Type", payload.contentType().toString()) .build() - return POST("$API_BASE_URL/get_chapters_by_serie/", newHeaders, payload) + return POST("$API_BASE_URL/chapters/get_chapters_by_serie/", newHeaders, payload) } override fun chapterListParse(response: Response): List { @@ -114,23 +113,13 @@ class YugenMangas : HttpSource() { override fun getChapterUrl(chapter: SChapter) = baseUrl + chapter.url - override fun pageListRequest(chapter: SChapter): Request { - val paths = chapter.url.removePrefix("/").split("/") - - val newHeaders = apiHeadersBuilder() - .set("Referer", getChapterUrl(chapter)) - .build() - - return POST("$API_BASE_URL/serie/${paths[1]}/chapter/${paths[2]}/images/imgs/", 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, "$baseUrl/${image.removePrefix("/")}") - } + val json = response.asJsoup().selectFirst("script#__NUXT_DATA__")!!.data() + return CHAPTER_PAGES_REGEX.findAll(json) + .mapIndexed { index, image -> + Page(index, baseUrl, "$API_HOST/${image.value}") + } + .toList() } override fun imageUrlParse(response: Response) = "" @@ -153,7 +142,9 @@ class YugenMangas : HttpSource() { } companion object { - private const val API_BASE_URL = "https://api.yugenmangas.net.br/api" + private const val API_HOST = "https://api.yugenmangas.net.br" + private const val API_BASE_URL = "$API_HOST/api" + private val CHAPTER_PAGES_REGEX = """(media/series[^"]+)""".toRegex() private val JSON_MEDIA_TYPE = "application/json".toMediaType() } } diff --git a/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangasDto.kt b/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangasDto.kt index 809d21204..c498b2e28 100644 --- a/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangasDto.kt +++ b/src/pt/yugenmangas/src/eu/kanade/tachiyomi/extension/pt/yugenmangas/YugenMangasDto.kt @@ -30,9 +30,15 @@ data class YugenMangaDto( "completed", "finished" -> SManga.COMPLETED else -> SManga.UNKNOWN } - thumbnail_url = if (cover.startsWith("/")) baseUrl + cover else cover + + thumbnail_url = when { + cover.startsWith(listOf("/", "cover")) -> "$baseUrl/media/${cover.removePrefix("/")}" + else -> cover + } url = "/series/$slug" } + + private fun String.startsWith(group: List): Boolean = group.any(::startsWith) } @Serializable @@ -66,11 +72,6 @@ data class YugenChapterDto( } } -@Serializable -data class YugenReaderDto( - @SerialName("chapter_images") val images: List? = emptyList(), -) - @Serializable data class YugenGetChaptersBySeriesDto( @SerialName("serie_slug") val seriesSlug: String,