OnePieceEx: Fix Brotli issue (#206)
This commit is contained in:
parent
555896d9a4
commit
85f8bd3917
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'One Piece Ex'
|
extName = 'One Piece Ex'
|
||||||
pkgNameSuffix = 'pt.opex'
|
pkgNameSuffix = 'pt.opex'
|
||||||
extClass = '.OnePieceEx'
|
extClass = '.OnePieceEx'
|
||||||
extVersionCode = 6
|
extVersionCode = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -14,11 +14,9 @@ import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.Interceptor
|
|
||||||
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 rx.Observable
|
import rx.Observable
|
||||||
|
@ -37,8 +35,14 @@ class OnePieceEx : ParsedHttpSource() {
|
||||||
override val supportsLatest = false
|
override val supportsLatest = false
|
||||||
|
|
||||||
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
||||||
.addInterceptor(::bypassHttp103Intercept)
|
|
||||||
.rateLimit(1, 2, TimeUnit.SECONDS)
|
.rateLimit(1, 2, TimeUnit.SECONDS)
|
||||||
|
.apply {
|
||||||
|
val interceptors = interceptors()
|
||||||
|
val index = interceptors.indexOfFirst { "Brotli" in it.javaClass.simpleName }
|
||||||
|
if (index >= 0) {
|
||||||
|
interceptors.add(interceptors.removeAt(index))
|
||||||
|
}
|
||||||
|
}
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||||
|
@ -230,33 +234,6 @@ class OnePieceEx : ParsedHttpSource() {
|
||||||
|
|
||||||
override fun latestUpdatesNextPageSelector() = throw UnsupportedOperationException("Not used")
|
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()
|
|
||||||
.replace("onepieceex-net.translate.goog", baseUrl.removePrefix("https://"))
|
|
||||||
.toResponseBody(bypasserResponse.body.contentType())
|
|
||||||
|
|
||||||
return bypasserResponse.newBuilder()
|
|
||||||
.body(fixedBody)
|
|
||||||
.request(request)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9," +
|
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"
|
"image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
|
||||||
|
|
Loading…
Reference in New Issue