mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
add prevent option in CloudflareKiller (#808)
* add prevent option in CloudflareKiller
This commit is contained in:
parent
f5e6d98cb0
commit
f98ce0558d
2 changed files with 24 additions and 12 deletions
|
@ -28,10 +28,7 @@ open class Chillx : ExtractorApi() {
|
|||
override val name = "Chillx"
|
||||
override val mainUrl = "https://chillx.top"
|
||||
override val requiresReferer = true
|
||||
|
||||
companion object {
|
||||
private const val KEY = "tSIsE8FgpRkv3QQQ"
|
||||
}
|
||||
private var key: String? = null
|
||||
|
||||
override suspend fun getUrl(
|
||||
url: String,
|
||||
|
@ -49,7 +46,7 @@ open class Chillx : ExtractorApi() {
|
|||
)
|
||||
).text
|
||||
)?.groupValues?.get(1)
|
||||
val decrypt = cryptoAESHandler(master ?: return, KEY.toByteArray(), false)?.replace("\\", "") ?: throw ErrorLoadingException("failed to decrypt")
|
||||
val decrypt = cryptoAESHandler(master ?: return, getKey().toByteArray(), false)?.replace("\\", "") ?: throw ErrorLoadingException("failed to decrypt")
|
||||
|
||||
val source = Regex(""""?file"?:\s*"([^"]+)""").find(decrypt)?.groupValues?.get(1)
|
||||
val tracks = Regex("""tracks:\s*\[(.+)]""").find(decrypt)?.groupValues?.get(1)
|
||||
|
@ -82,6 +79,12 @@ open class Chillx : ExtractorApi() {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun getKey() = key ?: fetchKey().also { key = it }
|
||||
|
||||
private suspend fun fetchKey(): String {
|
||||
return app.get("https://raw.githubusercontent.com/Sofie99/Resources/main/chillix_key.json").parsed()
|
||||
}
|
||||
|
||||
data class Tracks(
|
||||
@JsonProperty("file") val file: String? = null,
|
||||
@JsonProperty("label") val label: String? = null,
|
||||
|
|
|
@ -17,6 +17,8 @@ import java.net.URI
|
|||
class CloudflareKiller : Interceptor {
|
||||
companion object {
|
||||
const val TAG = "CloudflareKiller"
|
||||
private val ERROR_CODES = listOf(403, 503)
|
||||
private val CLOUDFLARE_SERVERS = listOf("cloudflare-nginx", "cloudflare")
|
||||
fun parseCookieMap(cookie: String): Map<String, String> {
|
||||
return cookie.split(";").associate {
|
||||
val split = it.split("=")
|
||||
|
@ -48,15 +50,22 @@ class CloudflareKiller : Interceptor {
|
|||
|
||||
override fun intercept(chain: Interceptor.Chain): Response = runBlocking {
|
||||
val request = chain.request()
|
||||
val cookies = savedCookies[request.url.host]
|
||||
|
||||
if (cookies == null) {
|
||||
bypassCloudflare(request)?.let {
|
||||
Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}")
|
||||
return@runBlocking it
|
||||
when (val cookies = savedCookies[request.url.host]) {
|
||||
null -> {
|
||||
val response = chain.proceed(request)
|
||||
if(!(response.header("Server") in CLOUDFLARE_SERVERS && response.code in ERROR_CODES)) {
|
||||
return@runBlocking response
|
||||
} else {
|
||||
bypassCloudflare(request)?.let {
|
||||
Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}")
|
||||
return@runBlocking it
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
return@runBlocking proceed(request, cookies)
|
||||
}
|
||||
} else {
|
||||
return@runBlocking proceed(request, cookies)
|
||||
}
|
||||
|
||||
debugWarning({ true }) { "Failed cloudflare at: ${request.url}" }
|
||||
|
|
Loading…
Reference in a new issue