Yugen Mangas: bugfix (#3193)

Update paths and fix chapter pages
This commit is contained in:
Chopper 2024-05-23 07:57:33 -03:00 committed by Draff
parent f1a59ba618
commit 6770a0672a
3 changed files with 25 additions and 33 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Yugen Mangás'
extClass = '.YugenMangas'
extVersionCode = 38
extVersionCode = 39
}
apply from: "$rootDir/common.gradle"

View File

@ -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<List<YugenMangaDto>>()
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<YugenMangaDto>().toSManga(baseUrl)
return response.parseAs<YugenMangaDto>().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<SChapter> {
@ -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<Page> {
val result = response.parseAs<YugenReaderDto>()
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()
}
}

View File

@ -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<String>): Boolean = group.any(::startsWith)
}
@Serializable
@ -66,11 +72,6 @@ data class YugenChapterDto(
}
}
@Serializable
data class YugenReaderDto(
@SerialName("chapter_images") val images: List<String>? = emptyList(),
)
@Serializable
data class YugenGetChaptersBySeriesDto(
@SerialName("serie_slug") val seriesSlug: String,