From c95fa2be77a088311d0e667fd088a147c325939e Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Sun, 21 Feb 2021 15:01:44 -0300 Subject: [PATCH] Change chapter list API endpoint at Tsuki. (#5951) --- src/pt/tsukimangas/build.gradle | 2 +- .../extension/pt/tsukimangas/TsukiMangas.kt | 33 ++++--------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/pt/tsukimangas/build.gradle b/src/pt/tsukimangas/build.gradle index 93b9b9499..c23975904 100644 --- a/src/pt/tsukimangas/build.gradle +++ b/src/pt/tsukimangas/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Tsuki Mangás' pkgNameSuffix = 'pt.tsukimangas' extClass = '.TsukiMangas' - extVersionCode = 10 + extVersionCode = 11 libVersion = '1.2' } diff --git a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt index d151c59c4..e1487e7c2 100644 --- a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt +++ b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt @@ -39,10 +39,8 @@ class TsukiMangas : HttpSource() { override val supportsLatest = true - private val rateLimitInterceptor = RateLimitInterceptor(100, 1, TimeUnit.MINUTES) - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .addInterceptor(rateLimitInterceptor) + .addInterceptor(RateLimitInterceptor(3, 1, TimeUnit.SECONDS)) .build() override fun headersBuilder(): Headers.Builder = Headers.Builder() @@ -183,39 +181,22 @@ class TsukiMangas : HttpSource() { } } - override fun chapterListRequest(manga: SManga): Request = chapterListRequestPaginated(manga.url, 1) - - private fun chapterListRequestPaginated(mangaUrl: String, page: Int): Request { - val mangaId = mangaUrl.substringAfter("obra/").substringBefore("/") + override fun chapterListRequest(manga: SManga): Request { + val mangaId = manga.url.substringAfter("obra/").substringBefore("/") val newHeaders = headersBuilder() - .set("Referer", baseUrl + mangaUrl) + .set("Referer", baseUrl + manga.url) .build() - return GET("$baseUrl/api/v2/chapters?manga_id=$mangaId&order=desc&page=$page", newHeaders) + return GET("$baseUrl/api/v2/chapters/$mangaId/all", newHeaders) } override fun chapterListParse(response: Response): List { - var result = response.asJson().obj - val mangaUrl = response.request().header("Referer")!!.substringAfter(baseUrl) - var page = 2 - val lastPage = result["lastPage"].int - val chapters = result["data"].array + return response.asJson().array .flatMap { chapterListItemParse(it.obj, mangaUrl) } - .toMutableList() - - while (page <= lastPage) { - val newRequest = chapterListRequestPaginated(mangaUrl, page++) - result = client.newCall(newRequest).execute().asJson().obj - - chapters += result["data"].array - .flatMap { chapterListItemParse(it.obj, mangaUrl) } - .toMutableList() - } - - return chapters + .reversed() } private fun chapterListItemParse(obj: JsonObject, mangaUrl: String): List {