From 8d318ca84ac6a714ac9532aaa3eac14a1eb57dcc Mon Sep 17 00:00:00 2001 From: Sarlay <60151189+Sarlay@users.noreply.github.com> Date: Thu, 15 Feb 2024 20:41:34 +0000 Subject: [PATCH] Fixed Chillx subtitles (#931) * Fixed subtitles tracks for Chillx.kt * Update Chillx.kt --- .../cloudstream3/extractors/Chillx.kt | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt index 68d543d3..f03a5525 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/Chillx.kt @@ -49,8 +49,23 @@ open class Chillx : ExtractorApi() { 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) + val subtitles = Regex("""subtitle"?:\s*"([^"]+)""").find(decrypt)?.groupValues?.get(1) + val subtitlePattern = """\[(.*?)\](https?://[^\s,]+)""".toRegex() + val matches = subtitlePattern.findAll(subtitles ?: "") + val languageUrlPairs = matches.map { matchResult -> + val (language, url) = matchResult.destructured + decodeUnicodeEscape(language) to url + }.toList() + + languageUrlPairs.forEach{ (name, file) -> + subtitleCallback.invoke( + SubtitleFile( + name, + file + ) + ) + } // required val headers = mapOf( "Accept" to "*/*", @@ -67,18 +82,15 @@ open class Chillx : ExtractorApi() { "$mainUrl/", headers = headers ).forEach(callback) - - AppUtils.tryParseJson>("[$tracks]") - ?.filter { it.kind == "captions" }?.map { track -> - subtitleCallback.invoke( - SubtitleFile( - track.label ?: "", - track.file ?: return@map null - ) - ) - } } - + + private fun decodeUnicodeEscape(input: String): String { + val regex = Regex("u([0-9a-fA-F]{4})") + return regex.replace(input) { + it.groupValues[1].toInt(16).toChar().toString() + } + } + suspend fun getKey() = key ?: fetchKey().also { key = it } private suspend fun fetchKey(): String {