Temporary fix HTTP 103 in OPEX. (#13793)
This commit is contained in:
parent
8924c4a6fc
commit
6a417ef285
@ -6,7 +6,7 @@ ext {
|
||||
extName = 'One Piece Ex'
|
||||
pkgNameSuffix = 'pt.opex'
|
||||
extClass = '.OnePieceEx'
|
||||
extVersionCode = 5
|
||||
extVersionCode = 6
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
@ -13,10 +13,13 @@ import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
@ -35,6 +38,7 @@ class OnePieceEx : ParsedHttpSource() {
|
||||
override val supportsLatest = false
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
||||
.addInterceptor(::bypassHttp103Intercept)
|
||||
.rateLimit(1, 2, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
@ -175,15 +179,21 @@ class OnePieceEx : ParsedHttpSource() {
|
||||
when (mangaUrl.queryParameter("type")!!) {
|
||||
"main" -> {
|
||||
name = element.select("span").first()!!.text()
|
||||
setUrlWithoutDomain(element.select("a.online").first()!!.attr("abs:href"))
|
||||
element.selectFirst("a.online")!!.attr("abs:href")
|
||||
.substringBefore("?")
|
||||
.let { setUrlWithoutDomain(it) }
|
||||
}
|
||||
"sbs" -> {
|
||||
name = element.select("div.volume-nome h2").first()!!.text()
|
||||
setUrlWithoutDomain(element.select("header p.extra a:contains(SBS)").first()!!.attr("abs:href"))
|
||||
element.selectFirst("header p.extra a:contains(SBS)")!!.attr("abs:href")
|
||||
.substringBefore("?")
|
||||
.let { setUrlWithoutDomain(it) }
|
||||
}
|
||||
"special" -> {
|
||||
name = element.ownText()
|
||||
setUrlWithoutDomain(element.select("a.online").first()!!.attr("abs:href"))
|
||||
element.select("a.online").first()!!.attr("abs:href")
|
||||
.substringBefore("?")
|
||||
.let { setUrlWithoutDomain(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,6 +231,33 @@ class OnePieceEx : ParsedHttpSource() {
|
||||
|
||||
override fun latestUpdatesNextPageSelector() = throw UnsupportedOperationException("Not used")
|
||||
|
||||
private fun bypassHttp103Intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
|
||||
if (request.url.pathSegments[0] != "mangas") {
|
||||
return chain.proceed(request)
|
||||
}
|
||||
|
||||
val bypasserUrl = "https://translate.google.com/translate".toHttpUrl().newBuilder()
|
||||
.addQueryParameter("pto", "op")
|
||||
.addQueryParameter("u", request.url.toString())
|
||||
.build()
|
||||
|
||||
val bypasserRequest = request.newBuilder()
|
||||
.url(bypasserUrl)
|
||||
.build()
|
||||
|
||||
val bypasserResponse = chain.proceed(bypasserRequest)
|
||||
val fixedBody = bypasserResponse.body?.string().orEmpty()
|
||||
.replace("onepieceex-net.translate.goog", baseUrl.removePrefix("https://"))
|
||||
.toResponseBody(bypasserResponse.body!!.contentType())
|
||||
|
||||
return bypasserResponse.newBuilder()
|
||||
.body(fixedBody)
|
||||
.request(request)
|
||||
.build()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9," +
|
||||
"image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
|
||||
|
Loading…
x
Reference in New Issue
Block a user