From c5e5474bf6153d8927f95e3c857b1a99e0ed29f3 Mon Sep 17 00:00:00 2001 From: gechoto <124326167+gechoto@users.noreply.github.com> Date: Tue, 24 Dec 2024 03:18:00 +0100 Subject: [PATCH] PlayerResponse: move findUrl function because we don't need the videoId --- .../zionhuang/music/playback/DownloadUtil.kt | 2 +- .../zionhuang/music/playback/MusicService.kt | 2 +- .../models/response/PlayerResponse.kt | 34 +++++++++---------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt b/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt index 17b71aa17..c7ff5b67e 100644 --- a/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt +++ b/app/src/main/java/com/zionhuang/music/playback/DownloadUtil.kt @@ -108,7 +108,7 @@ class DownloadUtil @Inject constructor( ) } - val streamUrl = playerResponse.findUrl(format.itag) + val streamUrl = format.findUrl() songUrlCache[mediaId] = streamUrl!! to playerResponse.streamingData!!.expiresInSeconds * 1000L dataSpec.withUri(streamUrl.toUri()) diff --git a/app/src/main/java/com/zionhuang/music/playback/MusicService.kt b/app/src/main/java/com/zionhuang/music/playback/MusicService.kt index 29c55a51e..20695bba9 100644 --- a/app/src/main/java/com/zionhuang/music/playback/MusicService.kt +++ b/app/src/main/java/com/zionhuang/music/playback/MusicService.kt @@ -691,7 +691,7 @@ class MusicService : MediaLibraryService(), } scope.launch(Dispatchers.IO) { recoverSong(mediaId, playerResponse) } - val streamUrl = playerResponse.findUrl(format.itag) + val streamUrl = format.findUrl() songUrlCache[mediaId] = streamUrl!! to playerResponse.streamingData!!.expiresInSeconds * 1000L dataSpec.withUri(streamUrl.toUri()).subrange(dataSpec.uriPositionOffset, CHUNK_LENGTH) diff --git a/innertube/src/main/java/com/zionhuang/innertube/models/response/PlayerResponse.kt b/innertube/src/main/java/com/zionhuang/innertube/models/response/PlayerResponse.kt index eab7bc573..87fa1ac80 100644 --- a/innertube/src/main/java/com/zionhuang/innertube/models/response/PlayerResponse.kt +++ b/innertube/src/main/java/com/zionhuang/innertube/models/response/PlayerResponse.kt @@ -64,6 +64,22 @@ data class PlayerResponse( ) { val isAudio: Boolean get() = width == null + + fun findUrl(): String? { + this.url?.let { + return it + } + this.signatureCipher?.let { signatureCipher -> + val params = parseQueryString(signatureCipher) + val obfuscatedSignature = params["s"] ?: return null + val signatureParam = params["sp"] ?: return null + val url = params["url"]?.let { URLBuilder(it) } ?: return null + url.parameters[signatureParam] = YoutubeJavaScriptPlayerManager.deobfuscateSignature("", obfuscatedSignature) + val streamUrl = YoutubeJavaScriptPlayerManager.getUrlWithThrottlingParameterDeobfuscated("", url.toString()) + return streamUrl + } + return null + } } } @@ -78,22 +94,4 @@ data class PlayerResponse( val viewCount: String, val thumbnail: Thumbnails, ) - - fun findUrl(itag: Int): String? { - this.streamingData?.adaptiveFormats?.find { it.itag == itag }?.let { format -> - format.url?.let { - return it - } - format.signatureCipher?.let { signatureCipher -> - val params = parseQueryString(signatureCipher) - val obfuscatedSignature = params["s"] ?: return null - val signatureParam = params["sp"] ?: return null - val url = params["url"]?.let { URLBuilder(it) } ?: return null - url.parameters[signatureParam] = YoutubeJavaScriptPlayerManager.deobfuscateSignature("", obfuscatedSignature) - val streamUrl = YoutubeJavaScriptPlayerManager.getUrlWithThrottlingParameterDeobfuscated("", url.toString()) - return streamUrl - } - } - return null - } } \ No newline at end of file