Skip to content

Commit

Permalink
YugenMangas: Update domain and fix chapters (#4977)
Browse files Browse the repository at this point in the history
* Fix YugenMangas

* Changes

* Add getSeriesCode
  • Loading branch information
choppeh authored Sep 9, 2024
1 parent dcbeb4b commit 88574ee
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/pt/yugenmangas/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Yugen Mangás'
extClass = '.YugenMangas'
extVersionCode = 41
extVersionCode = 42
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 88574ee

Please sign in to comment.