imhentai overload message (#11187)

* imhentai overload message

* change to interceptor
This commit is contained in:
Basara-Hatake 2022-03-21 10:35:22 +01:00 committed by GitHub
parent 743bc0d382
commit 26b8f2c1b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'IMHentai' extName = 'IMHentai'
pkgNameSuffix = 'all.imhentai' pkgNameSuffix = 'all.imhentai'
extClass = '.IMHentaiFactory' extClass = '.IMHentaiFactory'
extVersionCode = 5 extVersionCode = 6
isNsfw = true isNsfw = true
} }

View File

@ -16,11 +16,13 @@ import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import org.jsoup.select.Elements import org.jsoup.select.Elements
import rx.Observable import rx.Observable
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.io.IOException
class IMHentai(override val lang: String, private val imhLang: String) : ParsedHttpSource() { class IMHentai(override val lang: String, private val imhLang: String) : ParsedHttpSource() {
@ -34,6 +36,23 @@ class IMHentai(override val lang: String, private val imhLang: String) : ParsedH
override val supportsLatest = true override val supportsLatest = true
override val client: OkHttpClient = network.cloudflareClient override val client: OkHttpClient = network.cloudflareClient
.newBuilder()
.addInterceptor(
fun(chain): Response {
val response = chain.proceed(chain.request())
val responseContentType = response.body!!.contentType()
val responseString = response.body!!.string()
if (responseString.contains("Overload... Please use the advanced search")) {
response.close()
throw IOException("IMHentai search is overloaded try again later")
}
return response.newBuilder()
.body(responseString.toResponseBody(responseContentType))
.build()
}
).build()
// Popular // Popular