From da6eb85185debc79e3fd089732f81756c7b9d1c6 Mon Sep 17 00:00:00 2001 From: Dark25 Date: Wed, 18 Sep 2024 20:48:18 +0200 Subject: [PATCH] Fix(lib/ChillxExtractor): Update extractor --- .../lib/chillxextractor/ChillxExtractor.kt | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/chillx-extractor/src/main/java/eu/kanade/tachiyomi/lib/chillxextractor/ChillxExtractor.kt b/lib/chillx-extractor/src/main/java/eu/kanade/tachiyomi/lib/chillxextractor/ChillxExtractor.kt index daa73bfff0..2e4d7f821c 100644 --- a/lib/chillx-extractor/src/main/java/eu/kanade/tachiyomi/lib/chillxextractor/ChillxExtractor.kt +++ b/lib/chillx-extractor/src/main/java/eu/kanade/tachiyomi/lib/chillxextractor/ChillxExtractor.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.lib.chillxextractor import eu.kanade.tachiyomi.animesource.model.Track import eu.kanade.tachiyomi.animesource.model.Video -import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES.decryptWithSalt +import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.util.parseAs @@ -13,17 +13,18 @@ import kotlinx.serialization.json.Json import okhttp3.Headers import okhttp3.OkHttpClient import uy.kohesive.injekt.injectLazy +import java.net.URI class ChillxExtractor(private val client: OkHttpClient, private val headers: Headers) { private val json: Json by injectLazy() private val playlistUtils by lazy { PlaylistUtils(client, headers) } companion object { - private val REGEX_MASTER_JS by lazy { Regex("""\s*=\s*'([^']+)""") } - private val REGEX_SOURCES by lazy { Regex("""sources:\s*\[\{"file":"([^"]+)""") } - private val REGEX_FILE by lazy { Regex("""file: ?"([^"]+)"""") } - private val REGEX_SOURCE by lazy { Regex("""source = ?"([^"]+)"""") } - private val REGEX_SUBS by lazy { Regex("""\[(.*?)\](https?://[^\s,]+)""") } + private val REGEX_MASTER_JS = Regex("""\s*=\s*'([^']+)""") + private val REGEX_SOURCES = Regex("""sources:\s*\[\{"file":"([^"]+)""") + private val REGEX_FILE = Regex("""file: ?"([^"]+)"""") + private val REGEX_SOURCE = Regex("""source = ?"([^"]+)"""") + private val REGEX_SUBS = Regex("""\[(.*?)\](https?://[^\s,]+)""") private const val KEY_SOURCE = "https://raw.githubusercontent.com/Rowdy-Avocado/multi-keys/keys/index.html" } @@ -38,7 +39,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(master) val key = fetchKey() ?: throw ErrorLoadingException("Unable to get key") - val decryptedScript = decryptWithSalt(aesJson.ciphertext, aesJson.salt, key) + val decryptedScript = CryptoAES.decryptWithSalt(aesJson.ciphertext, aesJson.salt, key) .replace("\\n", "\n") .replace("\\", "") @@ -74,18 +75,24 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea } } + private fun String.getHost(): String { + return fixTitle(URI(this).host.substringBeforeLast(".").substringAfterLast(".")) + } + + private fun fixTitle(title: String): String { + return title.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() } + } + @Serializable data class CryptoInfo( - @SerialName("ct") - val ciphertext: String, - @SerialName("s") - val salt: String, + @SerialName("ct") val ciphertext: String, + @SerialName("s") val salt: String, ) @Serializable data class KeysData( - @SerialName("chillx") - val keys: List + @SerialName("chillx") val keys: List ) } + class ErrorLoadingException(message: String) : Exception(message)