Update AnimeKaiMegaUpExtractor.kt

This commit is contained in:
Arkai1 2025-04-12 20:02:10 +05:30 committed by GitHub
parent 367cdfcd66
commit ac7c7fed85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,45 +2,47 @@ package eu.kanade.tachiyomi.animeextension.en.animekai.extractors
import eu.kanade.tachiyomi.animeextension.en.animekai.AnimekaiDecoder import eu.kanade.tachiyomi.animeextension.en.animekai.AnimekaiDecoder
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.Headers import okhttp3.Headers
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import org.jsoup.Jsoup import org.jsoup.Jsoup
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class MegaUpExtractor { class AnimeKaiMegaUpExtractor {
private val client: OkHttpClient by injectLazy() private val client: OkHttpClient by injectLazy()
private val decoder = AnimekaiDecoder()
fun getVideoList(url: String): List<Video> { fun getVideoList(url: String): List<Video> {
val mediaUrl = url.replace("/e/", "/media/").replace("/e2/", "/media/") val mediaUrl = url.replace("/e/", "/media/").replace("/e2/", "/media/")
val encodedResult = runCatching { val encodedResult = runCatching {
val response = client.newCall(GET(mediaUrl)).execute().body?.string().orEmpty() val response = client.newCall(GET(mediaUrl)).execute().body.string()
Jsoup.parse(response).selectFirst("body")?.text()?.let { json -> Jsoup.parse(response).selectFirst("body")?.text()?.let { json ->
json.substringAfter("\"result\":\"").substringBefore("\",\"status\"") json.substringAfter("\"result\":\"").substringBefore("\",\"status\"")
} }
}.getOrNull() ?: return emptyList() }.getOrNull() ?: return emptyList()
val decryptSteps = runCatching { val decryptSteps = runCatching {
val json = client.newCall(GET(KEYS_URL)).execute().body?.string().orEmpty() val json = client.newCall(GET(KEYS_URL)).execute().body.string()
Json.decodeFromString<AnimeKaiKey>(json).megaup.decrypt Json.decodeFromString(AnimeKaiKey.serializer(), json).megaup.decrypt
}.getOrNull() ?: return emptyList() }.getOrNull() ?: return emptyList()
val decodedJson = runCatching { val decodedJson = runCatching {
decoder.decode(encodedResult, decryptSteps).replace("\\", "") AnimekaiDecoder().decode(encodedResult, decryptSteps).replace("\\", "")
}.getOrNull() ?: return emptyList() }.getOrNull() ?: return emptyList()
val m3u8Data = runCatching { val m3u8Data = runCatching {
Json.decodeFromString<M3U8>(decodedJson) Json.decodeFromString(M3U8.serializer(), decodedJson)
}.getOrNull() ?: return emptyList() }.getOrNull() ?: return emptyList()
return m3u8Data.sources.map { val videoList = mutableListOf<Video>()
Video(it.file, "MegaUp - Auto", it.file)
m3u8Data.sources.forEach { source ->
val quality = "MegaUp - Auto"
videoList.add(Video(source.file, quality, source.file))
} }
return videoList
} }
companion object { companion object {