diff --git a/src/pt/readmangas/build.gradle b/src/pt/readmangas/build.gradle index 41f761131..f072faa2f 100644 --- a/src/pt/readmangas/build.gradle +++ b/src/pt/readmangas/build.gradle @@ -1,7 +1,7 @@ ext { extName = 'Read Mangas' extClass = '.ReadMangas' - extVersionCode = 31 + extVersionCode = 32 } apply from: "$rootDir/common.gradle" diff --git a/src/pt/readmangas/src/eu/kanade/tachiyomi/extension/pt/readmangas/ReadMangas.kt b/src/pt/readmangas/src/eu/kanade/tachiyomi/extension/pt/readmangas/ReadMangas.kt index e629b54b9..3f1f9795c 100644 --- a/src/pt/readmangas/src/eu/kanade/tachiyomi/extension/pt/readmangas/ReadMangas.kt +++ b/src/pt/readmangas/src/eu/kanade/tachiyomi/extension/pt/readmangas/ReadMangas.kt @@ -26,6 +26,7 @@ import java.text.SimpleDateFormat import java.util.Date import java.util.Locale import java.util.TimeZone +import java.util.concurrent.TimeUnit class ReadMangas() : HttpSource() { @@ -40,6 +41,7 @@ class ReadMangas() : HttpSource() { private val json: Json by injectLazy() override val client = network.cloudflareClient.newBuilder() + .readTimeout(2, TimeUnit.MINUTES) .rateLimit(2) .build() @@ -176,14 +178,14 @@ class ReadMangas() : HttpSource() { val id = manga.url.substringAfterLast("#") val input = buildJsonObject { put( - "1", + "0", buildJsonObject { put( "json", buildJsonObject { put("id", id) put("page", page) - put("limit", 10) + put("limit", 50) put("sort", "desc") 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("input", input.toString()) .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> { val chapters = mutableListOf() var page = 1 do { - val response = client.newCall(this.chapterListRequest(manga, page++)).execute() + val response = tryFetchChapterPage(manga, page++) val dto = response .parseAs>>() .firstNotNullOf { it.result } @@ -215,6 +223,15 @@ class ReadMangas() : HttpSource() { 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): List { return chapters.map { SChapter.create().apply {