SlimeRead: Fix downloads (#3676)

whats happening with br sources
This commit is contained in:
bapeey 2024-06-22 02:29:15 -05:00 committed by Draff
parent 5e93a65f4d
commit 0088545740
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
2 changed files with 22 additions and 3 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'SlimeRead' extName = 'SlimeRead'
extClass = '.SlimeRead' extClass = '.SlimeRead'
extVersionCode = 11 extVersionCode = 12
isNsfw = true isNsfw = true
} }

View File

@ -22,8 +22,10 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.decodeFromStream
import okhttp3.HttpUrl import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
import rx.Observable import rx.Observable
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -43,6 +45,19 @@ class SlimeRead : HttpSource() {
network.cloudflareClient.newBuilder() network.cloudflareClient.newBuilder()
.rateLimitHost(baseUrl.toHttpUrl(), 2) .rateLimitHost(baseUrl.toHttpUrl(), 2)
.rateLimitHost(apiUrl.toHttpUrl(), 1) .rateLimitHost(apiUrl.toHttpUrl(), 1)
.addInterceptor { chain ->
val response = chain.proceed(chain.request())
val mime = response.headers["Content-Type"]
if (response.isSuccessful) {
if (mime == "application/octet-stream") {
val type = "image/jpeg".toMediaType()
val body = response.body.bytes().toResponseBody(type)
return@addInterceptor response.newBuilder().body(body)
.header("Content-Type", "image/jpeg").build()
}
}
response
}
.build() .build()
} }
@ -52,10 +67,14 @@ class SlimeRead : HttpSource() {
private fun getApiUrlFromPage(): String { private fun getApiUrlFromPage(): String {
val initClient = network.cloudflareClient val initClient = network.cloudflareClient
val document = initClient.newCall(GET(baseUrl, headers)).execute().asJsoup() val response = initClient.newCall(GET(baseUrl, headers)).execute()
if (!response.isSuccessful) throw Exception("HTTP error ${response.code}")
val document = response.asJsoup()
val scriptUrl = document.selectFirst("script[src*=pages/_app]")?.attr("abs:src") val scriptUrl = document.selectFirst("script[src*=pages/_app]")?.attr("abs:src")
?: throw Exception("Could not find script URL") ?: throw Exception("Could not find script URL")
val script = initClient.newCall(GET(scriptUrl, headers)).execute().body.string() val scriptResponse = initClient.newCall(GET(scriptUrl, headers)).execute()
if (!scriptResponse.isSuccessful) throw Exception("HTTP error ${scriptResponse.code}")
val script = scriptResponse.body.string()
val apiUrl = FUNCTION_REGEX.find(script)?.value?.let { function -> val apiUrl = FUNCTION_REGEX.find(script)?.value?.let { function ->
BASEURL_VAL_REGEX.find(function)?.groupValues?.get(1)?.let { baseUrlVar -> BASEURL_VAL_REGEX.find(function)?.groupValues?.get(1)?.let { baseUrlVar ->
val regex = """let.*?$baseUrlVar\s*=.*?(?=,\s*\w\s*=)""".toRegex(RegexOption.DOT_MATCHES_ALL) val regex = """let.*?$baseUrlVar\s*=.*?(?=,\s*\w\s*=)""".toRegex(RegexOption.DOT_MATCHES_ALL)