Kemono: retry when fetching posts (#958)

* Kemono: retry when fetching posts

* stricter rate limit
This commit is contained in:
stevenyomi 2024-02-04 01:32:03 +08:00 committed by GitHub
parent f5ff8563c1
commit 73a690dbdb
2 changed files with 14 additions and 3 deletions

View File

@ -37,7 +37,7 @@ open class Kemono(
) : HttpSource(), ConfigurableSource { ) : HttpSource(), ConfigurableSource {
override val supportsLatest = true override val supportsLatest = true
override val client = network.client.newBuilder().rateLimit(2).build() override val client = network.client.newBuilder().rateLimit(1).build()
override fun headersBuilder() = super.headersBuilder() override fun headersBuilder() = super.headersBuilder()
.add("Referer", "$baseUrl/") .add("Referer", "$baseUrl/")
@ -163,7 +163,7 @@ open class Kemono(
val result = ArrayList<SChapter>() val result = ArrayList<SChapter>()
while (offset < maxPosts && hasNextPage) { while (offset < maxPosts && hasNextPage) {
val request = GET("$baseUrl/$apiPath${manga.url}?limit=$POST_PAGE_SIZE&o=$offset", headers) val request = GET("$baseUrl/$apiPath${manga.url}?limit=$POST_PAGE_SIZE&o=$offset", headers)
val page: List<KemonoPostDto> = client.newCall(request).execute().parseAs() val page: List<KemonoPostDto> = retry(request).parseAs()
page.forEach { post -> if (post.images.isNotEmpty()) result.add(post.toSChapter()) } page.forEach { post -> if (post.images.isNotEmpty()) result.add(post.toSChapter()) }
offset += POST_PAGE_SIZE offset += POST_PAGE_SIZE
hasNextPage = page.size == POST_PAGE_SIZE hasNextPage = page.size == POST_PAGE_SIZE
@ -171,6 +171,17 @@ open class Kemono(
result result
} }
private fun retry(request: Request): Response {
var code = 0
repeat(3) {
val response = client.newCall(request).execute()
if (response.isSuccessful) return response
response.close()
code = response.code
}
throw Exception("HTTP error $code")
}
override fun chapterListParse(response: Response) = throw UnsupportedOperationException() override fun chapterListParse(response: Response) = throw UnsupportedOperationException()
override fun pageListRequest(chapter: SChapter): Request = override fun pageListRequest(chapter: SChapter): Request =

View File

@ -9,7 +9,7 @@ class KemonoGenerator : ThemeSourceGenerator {
override val themePkg = "kemono" override val themePkg = "kemono"
override val baseVersionCode = 9 override val baseVersionCode = 10
override val sources = listOf( override val sources = listOf(
SingleLang("Kemono", "https://kemono.su", "all", isNsfw = true), SingleLang("Kemono", "https://kemono.su", "all", isNsfw = true),