Skip to content

Commit

Permalink
Fix(Lib/Voe/Chillx): Update extractors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark25 committed Aug 19, 2024
1 parent 63de50b commit 3cbd010
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES.decryptWithSalt
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.parseAs
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
Expand All @@ -27,6 +29,7 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea

// matches "[language]https://...,"
private val REGEX_SUBS by lazy { Regex("""\[(.*?)\](.*?)"?\,""") }
private const val KEY_SOURCE = "https://rowdy-avocado.github.io/multi-keys/"
}

fun videoFromUrl(url: String, referer: String, prefix: String = "Chillx - "): List<Video> {
Expand All @@ -39,7 +42,7 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea

val master = REGEX_MASTER_JS.find(body)?.groupValues?.get(1) ?: return emptyList()
val aesJson = json.decodeFromString<CryptoInfo>(master)
val key = getKey(body)
val key = fetchKey()
val decryptedScript = decryptWithSalt(aesJson.ciphertext, aesJson.salt, key)
.replace("\\n", "\n")
.replace("\\", "")
Expand Down Expand Up @@ -83,6 +86,11 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea
)
}

@OptIn(ExperimentalSerializationApi::class)
private fun fetchKey(): String {
return client.newCall(GET(KEY_SOURCE)).execute().parseAs<KeysData>().keys.get(0)
}

private fun getKey(body: String): String {
val (encrypted, pass, offset, index) = REGEX_EVAL_KEY.find(body)!!.groupValues.drop(1)
val decrypted = decryptScript(encrypted, pass, offset.toInt(), index.toInt())
Expand Down Expand Up @@ -114,4 +122,10 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea
val label: String = "",
val file: String,
)

@Serializable
data class KeysData(
@SerialName("chillx")
val keys: List<String>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class VoeExtractor(private val client: OkHttpClient) {

private val base64Regex = Regex("'.*'")

private val scriptBase64Regex = "(let|var)\\s+\\w+\\s*=\\s*'(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)';".toRegex()

@Serializable
data class VideoLinkDTO(val file: String)

Expand All @@ -36,8 +38,9 @@ class VoeExtractor(private val client: OkHttpClient) {
document = clientDdos.newCall(GET(originalUrl)).execute().asJsoup()
}

val script = document.selectFirst("script:containsData(const sources), script:containsData(var sources), script:containsData(wc0)")
?.data()
val alternativeScript = document.select("script").find { scriptBase64Regex.containsMatchIn(it.data()) }?.data()
val script = document.selectFirst("script:containsData(const sources), script:containsData(var sources), script:containsData(wc0)")?.data()
?: alternativeScript
?: return emptyList()
val playlistUrl = when {
// Layout 1
Expand All @@ -46,10 +49,11 @@ class VoeExtractor(private val client: OkHttpClient) {
if (linkRegex.matches(link)) link else String(Base64.decode(link, Base64.DEFAULT))
}
// Layout 2
script.contains("wc0") -> {
script.contains("wc0") || alternativeScript != null -> {
val base64 = base64Regex.find(script)!!.value
val decoded = Base64.decode(base64, Base64.DEFAULT).let(::String)
json.decodeFromString<VideoLinkDTO>(decoded).file

json.decodeFromString<VideoLinkDTO>(if (alternativeScript != null) decoded.reversed() else decoded).file
}
else -> return emptyList()
}
Expand Down

0 comments on commit 3cbd010

Please sign in to comment.