mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fixed Chillx subtitles (#931)
* Fixed subtitles tracks for Chillx.kt * Update Chillx.kt
This commit is contained in:
parent
eea6e13346
commit
8d318ca84a
1 changed files with 24 additions and 12 deletions
|
@ -49,8 +49,23 @@ open class Chillx : ExtractorApi() {
|
||||||
val decrypt = cryptoAESHandler(master ?: return, getKey().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 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
|
// required
|
||||||
val headers = mapOf(
|
val headers = mapOf(
|
||||||
"Accept" to "*/*",
|
"Accept" to "*/*",
|
||||||
|
@ -67,16 +82,13 @@ open class Chillx : ExtractorApi() {
|
||||||
"$mainUrl/",
|
"$mainUrl/",
|
||||||
headers = headers
|
headers = headers
|
||||||
).forEach(callback)
|
).forEach(callback)
|
||||||
|
}
|
||||||
|
|
||||||
AppUtils.tryParseJson<List<Tracks>>("[$tracks]")
|
private fun decodeUnicodeEscape(input: String): String {
|
||||||
?.filter { it.kind == "captions" }?.map { track ->
|
val regex = Regex("u([0-9a-fA-F]{4})")
|
||||||
subtitleCallback.invoke(
|
return regex.replace(input) {
|
||||||
SubtitleFile(
|
it.groupValues[1].toInt(16).toChar().toString()
|
||||||
track.label ?: "",
|
}
|
||||||
track.file ?: return@map null
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getKey() = key ?: fetchKey().also { key = it }
|
suspend fun getKey() = key ?: fetchKey().also { key = it }
|
||||||
|
|
Loading…
Reference in a new issue