mirror of
https://github.com/keiyoushi/extensions-source.git
synced 2024-11-22 02:12:42 +01:00
Kemono: retry when fetching posts (#958)
* Kemono: retry when fetching posts * stricter rate limit
This commit is contained in:
parent
f5ff8563c1
commit
73a690dbdb
@ -37,7 +37,7 @@ open class Kemono(
|
||||
) : HttpSource(), ConfigurableSource {
|
||||
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()
|
||||
.add("Referer", "$baseUrl/")
|
||||
@ -163,7 +163,7 @@ open class Kemono(
|
||||
val result = ArrayList<SChapter>()
|
||||
while (offset < maxPosts && hasNextPage) {
|
||||
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()) }
|
||||
offset += POST_PAGE_SIZE
|
||||
hasNextPage = page.size == POST_PAGE_SIZE
|
||||
@ -171,6 +171,17 @@ open class Kemono(
|
||||
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 pageListRequest(chapter: SChapter): Request =
|
||||
|
@ -9,7 +9,7 @@ class KemonoGenerator : ThemeSourceGenerator {
|
||||
|
||||
override val themePkg = "kemono"
|
||||
|
||||
override val baseVersionCode = 9
|
||||
override val baseVersionCode = 10
|
||||
|
||||
override val sources = listOf(
|
||||
SingleLang("Kemono", "https://kemono.su", "all", isNsfw = true),
|
||||
|
Loading…
Reference in New Issue
Block a user