From 7aa8b2db52260c3b5fc6aebbbc8693fe55032872 Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:24:18 -0500 Subject: [PATCH] handle parameters at the end of urls --- .../ani/dantotsu/parsers/AniyomiAdapter.kt | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt b/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt index 58944e04..5fe3441c 100644 --- a/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt +++ b/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt @@ -10,6 +10,8 @@ import eu.kanade.tachiyomi.animesource.model.AnimesPage import eu.kanade.tachiyomi.animesource.model.SAnime import eu.kanade.tachiyomi.animesource.model.Track import eu.kanade.tachiyomi.animesource.model.Video +import java.net.URL +import java.net.URLDecoder class AniyomiAdapter { fun aniyomiToAnimeParser(extension: AnimeExtension.Installed): DynamicAnimeParser { @@ -151,12 +153,39 @@ class VideoServerPassthrough : VideoExtractor{ val result = regex.find(aniVideo.quality) val number = result?.value?.toInt() ?: 0 val videoUrl = aniVideo.videoUrl ?: throw Exception("Video URL is null") + val urlObj = URL(videoUrl) + val path = urlObj.path + val query = urlObj.query - val format = when { - videoUrl.endsWith(".mp4", ignoreCase = true) || videoUrl.endsWith(".mkv", ignoreCase = true) -> VideoType.CONTAINER - videoUrl.endsWith(".m3u8", ignoreCase = true) -> VideoType.M3U8 - videoUrl.endsWith(".mpd", ignoreCase = true) -> VideoType.DASH - else -> throw Exception("Unknown video format") + + var format = when { + path.endsWith(".mp4", ignoreCase = true) || videoUrl.endsWith(".mkv", ignoreCase = true) -> VideoType.CONTAINER + path.endsWith(".m3u8", ignoreCase = true) -> VideoType.M3U8 + path.endsWith(".mpd", ignoreCase = true) -> VideoType.DASH + else -> null + } + if (format == null) { + val queryPairs: List> = query.split("&").map { + val idx = it.indexOf("=") + val key = URLDecoder.decode(it.substring(0, idx), "UTF-8") + val value = URLDecoder.decode(it.substring(idx + 1), "UTF-8") + Pair(key, value) + } + + // Assume the file is named under the "file" query parameter + val fileName = queryPairs.find { it.first == "file" }?.second ?: "" + + format = when { + fileName.endsWith(".mp4", ignoreCase = true) || fileName.endsWith(".mkv", ignoreCase = true) -> VideoType.CONTAINER + fileName.endsWith(".m3u8", ignoreCase = true) -> VideoType.M3U8 + fileName.endsWith(".mpd", ignoreCase = true) -> VideoType.DASH + else -> null + } + } + // If the format is still undetermined, log an error or handle it appropriately + if (format == null) { + logger("Unknown video format: $videoUrl") + throw Exception("Unknown video format") } val headersMap: Map = aniVideo.headers?.toMultimap()?.mapValues { it.value.joinToString() } ?: mapOf()