ReadMangas: Fix chapter loading (#6581)

* Fix chapter loading

* Bump version
This commit is contained in:
Chopper 2024-12-12 03:27:27 -03:00 committed by Draff
parent eb41438fb3
commit 5df41c9b5f
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 23 additions and 6 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Read Mangas' extName = 'Read Mangas'
extClass = '.ReadMangas' extClass = '.ReadMangas'
extVersionCode = 31 extVersionCode = 32
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -26,6 +26,7 @@ import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.util.Locale import java.util.Locale
import java.util.TimeZone import java.util.TimeZone
import java.util.concurrent.TimeUnit
class ReadMangas() : HttpSource() { class ReadMangas() : HttpSource() {
@ -40,6 +41,7 @@ class ReadMangas() : HttpSource() {
private val json: Json by injectLazy() private val json: Json by injectLazy()
override val client = network.cloudflareClient.newBuilder() override val client = network.cloudflareClient.newBuilder()
.readTimeout(2, TimeUnit.MINUTES)
.rateLimit(2) .rateLimit(2)
.build() .build()
@ -176,14 +178,14 @@ class ReadMangas() : HttpSource() {
val id = manga.url.substringAfterLast("#") val id = manga.url.substringAfterLast("#")
val input = buildJsonObject { val input = buildJsonObject {
put( put(
"1", "0",
buildJsonObject { buildJsonObject {
put( put(
"json", "json",
buildJsonObject { buildJsonObject {
put("id", id) put("id", id)
put("page", page) put("page", page)
put("limit", 10) put("limit", 50)
put("sort", "desc") put("sort", "desc")
put("search", "") put("search", "")
}, },
@ -192,19 +194,25 @@ class ReadMangas() : HttpSource() {
) )
} }
val url = "$baseUrl/api/trpc/manga.getLiked,chapter.publicAllChapters".toHttpUrl().newBuilder() val url = "$baseUrl/api/trpc/chapter.publicAllChapters".toHttpUrl().newBuilder()
.addQueryParameter("batch", "1") .addQueryParameter("batch", "1")
.addQueryParameter("input", input.toString()) .addQueryParameter("input", input.toString())
.build() .build()
return GET(url, headers) val apiHeaders = headers.newBuilder()
.set("Referer", "$baseUrl${manga.url.substringBeforeLast("#")}")
.set("Content-Type", "application/json")
.set("Cache-Control", "no-cache")
.build()
return GET(url, apiHeaders)
} }
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> { override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
val chapters = mutableListOf<SChapter>() val chapters = mutableListOf<SChapter>()
var page = 1 var page = 1
do { do {
val response = client.newCall(this.chapterListRequest(manga, page++)).execute() val response = tryFetchChapterPage(manga, page++)
val dto = response val dto = response
.parseAs<List<WrapperResult<ChapterListDto>>>() .parseAs<List<WrapperResult<ChapterListDto>>>()
.firstNotNullOf { it.result } .firstNotNullOf { it.result }
@ -215,6 +223,15 @@ class ReadMangas() : HttpSource() {
return Observable.just(chapters) return Observable.just(chapters)
} }
private val attempts = 3
private fun tryFetchChapterPage(manga: SManga, page: Int): Response {
repeat(attempts) { index ->
try { return client.newCall(this.chapterListRequest(manga, page)).execute() } catch (e: Exception) { /* do nothing */ }
}
throw Exception("Não foi possivel obter os capitulos da página: $page")
}
private fun chapterListParse(chapters: List<ChapterDto>): List<SChapter> { private fun chapterListParse(chapters: List<ChapterDto>): List<SChapter> {
return chapters.map { return chapters.map {
SChapter.create().apply { SChapter.create().apply {