From 90af3b1d6836e8756b74062c399795e475f6c6f8 Mon Sep 17 00:00:00 2001 From: Dark25 Date: Mon, 13 Jan 2025 18:34:51 +0100 Subject: [PATCH] Update StreamWishExtractor --- .../StreamWishExtractor.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/streamwish-extractor/src/main/java/eu/kanade/tachiyomi/lib/streamwishextractor/StreamWishExtractor.kt b/lib/streamwish-extractor/src/main/java/eu/kanade/tachiyomi/lib/streamwishextractor/StreamWishExtractor.kt index 5d79a57786..d5d7eceedf 100644 --- a/lib/streamwish-extractor/src/main/java/eu/kanade/tachiyomi/lib/streamwishextractor/StreamWishExtractor.kt +++ b/lib/streamwish-extractor/src/main/java/eu/kanade/tachiyomi/lib/streamwishextractor/StreamWishExtractor.kt @@ -1,15 +1,20 @@ package eu.kanade.tachiyomi.lib.streamwishextractor import dev.datlag.jsunpacker.JsUnpacker +import eu.kanade.tachiyomi.animesource.model.Track import eu.kanade.tachiyomi.animesource.model.Video import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.util.asJsoup +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationException +import kotlinx.serialization.json.Json import okhttp3.Headers import okhttp3.OkHttpClient class StreamWishExtractor(private val client: OkHttpClient, private val headers: Headers) { private val playlistUtils by lazy { PlaylistUtils(client, headers) } + private val json = Json { isLenient = true; ignoreUnknownKeys = true } fun videosFromUrl(url: String, prefix: String) = videosFromUrl(url) { "$prefix - $it" } @@ -32,7 +37,9 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers: ?.takeIf(String::isNotBlank) ?: return emptyList() - return playlistUtils.extractFromHls(masterUrl, url, videoNameGen = videoNameGen) + val subtitleList = extractSubtitles(scriptBody) + + return playlistUtils.extractFromHls(masterUrl, url, videoNameGen = videoNameGen, subtitleList = subtitleList) } private fun getEmbedUrl(url: String): String { @@ -43,4 +50,21 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers: url } } + + private fun extractSubtitles(script: String): List { + return try { + val subtitleStr = script + .substringAfter("tracks") + .substringAfter("[") + .substringBefore("]") + json.decodeFromString>("[$subtitleStr]") + .filter { it.kind.equals("captions", true) } + .map { Track(it.file, it.label ?: "") } + } catch (e: SerializationException) { + emptyList() + } + } + + @Serializable + private data class TrackDto(val file: String, val kind: String, val label: String? = null) }