add prevent option in CloudflareKiller (#808)

* add prevent option in CloudflareKiller
This commit is contained in:
Sofie 2023-12-15 21:34:58 +07:00 committed by GitHub
parent f5e6d98cb0
commit f98ce0558d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View file

@ -28,10 +28,7 @@ open class Chillx : ExtractorApi() {
override val name = "Chillx" override val name = "Chillx"
override val mainUrl = "https://chillx.top" override val mainUrl = "https://chillx.top"
override val requiresReferer = true override val requiresReferer = true
private var key: String? = null
companion object {
private const val KEY = "tSIsE8FgpRkv3QQQ"
}
override suspend fun getUrl( override suspend fun getUrl(
url: String, url: String,
@ -49,7 +46,7 @@ open class Chillx : ExtractorApi() {
) )
).text ).text
)?.groupValues?.get(1) )?.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 source = Regex(""""?file"?:\s*"([^"]+)""").find(decrypt)?.groupValues?.get(1)
val tracks = Regex("""tracks:\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( data class Tracks(
@JsonProperty("file") val file: String? = null, @JsonProperty("file") val file: String? = null,
@JsonProperty("label") val label: String? = null, @JsonProperty("label") val label: String? = null,

View file

@ -17,6 +17,8 @@ import java.net.URI
class CloudflareKiller : Interceptor { class CloudflareKiller : Interceptor {
companion object { companion object {
const val TAG = "CloudflareKiller" 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> { fun parseCookieMap(cookie: String): Map<String, String> {
return cookie.split(";").associate { return cookie.split(";").associate {
val split = it.split("=") val split = it.split("=")
@ -48,16 +50,23 @@ class CloudflareKiller : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response = runBlocking { override fun intercept(chain: Interceptor.Chain): Response = runBlocking {
val request = chain.request() val request = chain.request()
val cookies = savedCookies[request.url.host]
if (cookies == null) { 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 { bypassCloudflare(request)?.let {
Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}") Log.d(TAG, "Succeeded bypassing cloudflare: ${request.url}")
return@runBlocking it return@runBlocking it
} }
} else { }
}
else -> {
return@runBlocking proceed(request, cookies) return@runBlocking proceed(request, cookies)
} }
}
debugWarning({ true }) { "Failed cloudflare at: ${request.url}" } debugWarning({ true }) { "Failed cloudflare at: ${request.url}" }
return@runBlocking chain.proceed(request) return@runBlocking chain.proceed(request)