Fixed Chillx subtitles (#931)

* Fixed subtitles tracks for Chillx.kt

* Update Chillx.kt
This commit is contained in:
Sarlay 2024-02-15 20:41:34 +00:00 committed by GitHub
parent eea6e13346
commit 8d318ca84a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<List<Tracks>>("[$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 {