YugenMangas: Update domain and fix chapters (#4977)

* Fix YugenMangas

* Changes

* Add getSeriesCode
This commit is contained in:
Chopper 2024-09-09 09:21:43 -03:00 committed by Draff
parent 9a08636bda
commit 66244d5c2c
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 49 additions and 17 deletions

View File

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

View File

@ -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<MangaDetailsDto>().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<List<SChapter>> {
var page = 1
val chapters = mutableListOf<SChapter>()
do {
val response = client.newCall(chapterListRequest(manga, page++)).execute()
val series = response.getSeriesCode()
val chapterContainer = response.parseAs<ChapterContainerDto>()
chapters += chapterContainer.toSChapter(series.code)
} while (chapterContainer.next != null)
return Observable.just(chapters)
}
private fun Response.getSeriesCode(): SeriesDto =
this.request.body!!.parseAs<SeriesDto>()
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<SChapter> {
val series = response.request.body!!.parseAs<SeriesDto>()
return response.parseAs<List<ChapterDto>>()
.map { it.toSChapter(series.code) }
.reversed()
return response.parseAs<ChapterContainerDto>().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)
}
}

View File

@ -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<SChapter> {
return results.chapters.map { it.toSChapter(seriesCode) }
}
@Serializable
class WrapperDto(
val chapters: List<ChapterDto>,
)
}
@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