From 66244d5c2cc1e347bacc882bd423b327faf589cd Mon Sep 17 00:00:00 2001 From: Chopper <156493704+choppeh@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:21:43 -0300 Subject: [PATCH] YugenMangas: Update domain and fix chapters (#4977) * Fix YugenMangas * Changes * Add getSeriesCode --- src/pt/yugenmangas/build.gradle | 2 +- .../extension/pt/yugenmangas/YugenMangas.kt | 30 +++++++++++----- .../pt/yugenmangas/YugenMangasDto.kt | 34 +++++++++++++++---- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/pt/yugenmangas/build.gradle b/src/pt/yugenmangas/build.gradle index 2513c2184..33dd444b0 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 = 41 + extVersionCode = 42 } 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 ba4a81912..158510007 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 @@ -21,16 +21,15 @@ import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response import okio.Buffer +import rx.Observable import uy.kohesive.injekt.injectLazy -import java.text.SimpleDateFormat -import java.util.Locale import java.util.concurrent.TimeUnit class YugenMangas : HttpSource() { override val name = "Yugen Mangás" - override val baseUrl = "https://yugenweb.com" + override val baseUrl = "https://yugenmangasbr.voblog.xyz" override val lang = "pt-BR" @@ -101,12 +100,28 @@ class YugenMangas : HttpSource() { return response.parseAs().toSManga() } - override fun chapterListRequest(manga: SManga): Request { + private fun chapterListRequest(manga: SManga, page: Int): Request { val code = manga.url.substringAfterLast("/") val payload = json.encodeToString(SeriesDto(code)).toRequestBody(JSON_MEDIA_TYPE) - return POST("$BASE_API/series/chapters/get-series-chapters/", apiHeaders, payload) + return POST("$BASE_API/series/chapters/get-series-chapters/?page=$page", apiHeaders, payload) } + override fun fetchChapterList(manga: SManga): Observable> { + var page = 1 + val chapters = mutableListOf() + do { + val response = client.newCall(chapterListRequest(manga, page++)).execute() + val series = response.getSeriesCode() + val chapterContainer = response.parseAs() + chapters += chapterContainer.toSChapter(series.code) + } while (chapterContainer.next != null) + + return Observable.just(chapters) + } + + private fun Response.getSeriesCode(): SeriesDto = + this.request.body!!.parseAs() + override fun pageListRequest(chapter: SChapter): Request { val code = chapter.url.substringAfterLast("/") val payload = json.encodeToString(SeriesDto(code)).toRequestBody(JSON_MEDIA_TYPE) @@ -115,9 +130,7 @@ class YugenMangas : HttpSource() { override fun chapterListParse(response: Response): List { val series = response.request.body!!.parseAs() - return response.parseAs>() - .map { it.toSChapter(series.code) } - .reversed() + return response.parseAs().toSChapter(series.code) } override fun getChapterUrl(chapter: SChapter) = baseUrl + chapter.url @@ -151,6 +164,5 @@ class YugenMangas : HttpSource() { private const val BASE_API = "https://api.yugenweb.com/api" private const val BASE_MEDIA = "https://media.yugenweb.com" private val JSON_MEDIA_TYPE = "application/json".toMediaType() - val DATE_FORMAT = SimpleDateFormat("dd/MM/yyyy", Locale.ROOT) } } 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 75b35bb0b..c85d25539 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.extension.pt.yugenmangas -import eu.kanade.tachiyomi.extension.pt.yugenmangas.YugenMangas.Companion.DATE_FORMAT import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import kotlinx.serialization.SerialName @@ -70,6 +69,21 @@ class MangaDetailsDto( } } +@Serializable +class ChapterContainerDto( + val results: WrapperDto, + val next: String?, +) { + fun toSChapter(seriesCode: String): List { + return results.chapters.map { it.toSChapter(seriesCode) } + } + + @Serializable + class WrapperDto( + val chapters: List, + ) +} + @Serializable class ChapterDto( val code: String, @@ -79,21 +93,27 @@ class ChapterDto( ) { fun toSChapter(mangaCode: String): SChapter = SChapter.create().apply { name = this@ChapterDto.name - date_upload = try { parseDate() } catch (_: Exception) { 0L } + date_upload = parseDate() url = "/series/$mangaCode/$code" } private fun parseDate(): Long { return try { - if ("dia" in date) { - val number = Regex("""(\d+)""").find(date)?.value?.toIntOrNull() ?: return 0L - return Calendar.getInstance().let { - it.apply { add(Calendar.DAY_OF_MONTH, -number) }.timeInMillis + val number = Regex("""(\d+)""").find(date)?.value?.toIntOrNull() ?: return 0L + Calendar.getInstance().let { + when { + date.contains("dia") -> it.apply { add(Calendar.DAY_OF_MONTH, -number) }.timeInMillis + date.contains("mês", "meses") -> it.apply { add(Calendar.MONTH, -number) }.timeInMillis + date.contains("ano") -> it.apply { add(Calendar.YEAR, -number) }.timeInMillis + else -> 0L } } - return DATE_FORMAT.parse(date)!!.time } catch (_: Exception) { 0L } } + + private fun String.contains(vararg elements: String): Boolean { + return elements.any { this.contains(it, true) } + } } @Serializable