Feat(lib/ChillxExtractor): Update extractor and add extractor to Hikari

This commit is contained in:
Dark25 2024-09-18 20:56:29 +02:00
parent 3e7022d2bd
commit 8b11adcfad
3 changed files with 26 additions and 18 deletions

View file

@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.lib.chillxextractor
import eu.kanade.tachiyomi.animesource.model.Track import eu.kanade.tachiyomi.animesource.model.Track
import eu.kanade.tachiyomi.animesource.model.Video 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.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.parseAs import eu.kanade.tachiyomi.util.parseAs
@ -13,17 +13,18 @@ import kotlinx.serialization.json.Json
import okhttp3.Headers import okhttp3.Headers
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.net.URI
class ChillxExtractor(private val client: OkHttpClient, private val headers: Headers) { class ChillxExtractor(private val client: OkHttpClient, private val headers: Headers) {
private val json: Json by injectLazy() private val json: Json by injectLazy()
private val playlistUtils by lazy { PlaylistUtils(client, headers) } private val playlistUtils by lazy { PlaylistUtils(client, headers) }
companion object { companion object {
private val REGEX_MASTER_JS by lazy { Regex("""\s*=\s*'([^']+)""") } private val REGEX_MASTER_JS = Regex("""\s*=\s*'([^']+)""")
private val REGEX_SOURCES by lazy { Regex("""sources:\s*\[\{"file":"([^"]+)""") } private val REGEX_SOURCES = Regex("""sources:\s*\[\{"file":"([^"]+)""")
private val REGEX_FILE by lazy { Regex("""file: ?"([^"]+)"""") } private val REGEX_FILE = Regex("""file: ?"([^"]+)"""")
private val REGEX_SOURCE by lazy { Regex("""source = ?"([^"]+)"""") } private val REGEX_SOURCE = Regex("""source = ?"([^"]+)"""")
private val REGEX_SUBS by lazy { Regex("""\[(.*?)\](https?://[^\s,]+)""") } private val REGEX_SUBS = Regex("""\[(.*?)\](https?://[^\s,]+)""")
private const val KEY_SOURCE = "https://raw.githubusercontent.com/Rowdy-Avocado/multi-keys/keys/index.html" 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 master = REGEX_MASTER_JS.find(body)?.groupValues?.get(1) ?: return emptyList()
val aesJson = json.decodeFromString<CryptoInfo>(master) val aesJson = json.decodeFromString<CryptoInfo>(master)
val key = fetchKey() ?: throw ErrorLoadingException("Unable to get key") 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("\\n", "\n")
.replace("\\", "") .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 @Serializable
data class CryptoInfo( data class CryptoInfo(
@SerialName("ct") @SerialName("ct") val ciphertext: String,
val ciphertext: String, @SerialName("s") val salt: String,
@SerialName("s")
val salt: String,
) )
@Serializable @Serializable
data class KeysData( data class KeysData(
@SerialName("chillx") @SerialName("chillx") val keys: List<String>
val keys: List<String>
) )
} }
class ErrorLoadingException(message: String) : Exception(message) class ErrorLoadingException(message: String) : Exception(message)

View file

@ -1,7 +1,7 @@
ext { ext {
extName = 'Hikari' extName = 'Hikari'
extClass = '.Hikari' extClass = '.Hikari'
extVersionCode = 7 extVersionCode = 8
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"
@ -9,4 +9,5 @@ apply from: "$rootDir/common.gradle"
dependencies { dependencies {
implementation(project(':lib:filemoon-extractor')) implementation(project(':lib:filemoon-extractor'))
implementation(project(':lib:vidhide-extractor')) implementation(project(':lib:vidhide-extractor'))
implementation(project(':lib:chillx-extractor'))
} }

View file

@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.lib.filemoonextractor.FilemoonExtractor import eu.kanade.tachiyomi.lib.filemoonextractor.FilemoonExtractor
import eu.kanade.tachiyomi.lib.vidhideextractor.VidHideExtractor import eu.kanade.tachiyomi.lib.vidhideextractor.VidHideExtractor
import eu.kanade.tachiyomi.lib.chillxextractor.ChillxExtractor
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
import eu.kanade.tachiyomi.util.parseAs import eu.kanade.tachiyomi.util.parseAs
@ -218,6 +219,7 @@ class Hikari : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
private val filemoonExtractor by lazy { FilemoonExtractor(client) } private val filemoonExtractor by lazy { FilemoonExtractor(client) }
private val vidHideExtractor by lazy { VidHideExtractor(client, headers) } private val vidHideExtractor by lazy { VidHideExtractor(client, headers) }
private val chillxExtractor by lazy { ChillxExtractor(client, headers) }
private val embedRegex = Regex("""getEmbed\(\s*(\d+)\s*,\s*(\d+)\s*,\s*'(\d+)'""") private val embedRegex = Regex("""getEmbed\(\s*(\d+)\s*,\s*(\d+)\s*,\s*'(\d+)'""")
override fun videoListRequest(episode: SEpisode): Request { override fun videoListRequest(episode: SEpisode): Request {
@ -336,10 +338,8 @@ class Hikari : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
private fun getVideosFromEmbed(embedUrl: String, name: String): List<Video> = when { private fun getVideosFromEmbed(embedUrl: String, name: String): List<Video> = when {
name.contains("vidhide", true) -> vidHideExtractor.videosFromUrl(embedUrl, videoNameGen = { s -> "$name - $s" }) name.contains("vidhide", true) -> vidHideExtractor.videosFromUrl(embedUrl, videoNameGen = { s -> "$name - $s" })
embedUrl.contains("filemoon", true) -> { embedUrl.contains("filemoon", true) -> filemoonExtractor.videosFromUrl(embedUrl, prefix = "$name - ", headers = headers)
filemoonExtractor.videosFromUrl(embedUrl, prefix = "$name - ", headers = headers) else -> chillxExtractor.videoFromUrl(embedUrl, referer = baseUrl, prefix = "$name - ")
}
else -> emptyList()
} }
override fun videoListSelector() = ".server-item:has(a[onclick~=getEmbed])" override fun videoListSelector() = ".server-item:has(a[onclick~=getEmbed])"