From c00a079715fd7d63f351bbf48b81da06b492b923 Mon Sep 17 00:00:00 2001 From: vfsfitvnm Date: Sun, 9 Oct 2022 15:06:02 +0200 Subject: [PATCH] Try fix #385 --- .../vfsfitvnm/vimusic/service/PlaybackExceptions.kt | 2 ++ .../it/vfsfitvnm/vimusic/service/PlayerService.kt | 4 ++++ .../vimusic/ui/screens/player/Thumbnail.kt | 2 ++ .../it/vfsfitvnm/youtubemusic/models/Context.kt | 13 +++++++++---- .../vfsfitvnm/youtubemusic/models/PlayerResponse.kt | 9 +++++++-- .../it/vfsfitvnm/youtubemusic/requests/Player.kt | 10 +++++++++- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlaybackExceptions.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlaybackExceptions.kt index 7a846be..d38c279 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlaybackExceptions.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlaybackExceptions.kt @@ -7,3 +7,5 @@ class PlayableFormatNotFoundException : PlaybackException(null, null, ERROR_CODE class UnplayableException : PlaybackException(null, null, ERROR_CODE_REMOTE_ERROR) class LoginRequiredException : PlaybackException(null, null, ERROR_CODE_REMOTE_ERROR) + +class VideoIdMismatchException : PlaybackException(null, null, ERROR_CODE_REMOTE_ERROR) diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt index 3c81098..bdf5cab 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/service/PlayerService.kt @@ -650,6 +650,10 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene val urlResult = runBlocking(Dispatchers.IO) { Innertube.player(PlayerBody(videoId = videoId)) }?.mapCatching { body -> + if (body.videoDetails?.videoId != videoId) { + throw VideoIdMismatchException() + } + when (val status = body.playabilityStatus?.status) { "OK" -> body.streamingData?.adaptiveFormats?.findLast { format -> format.itag == 251 || format.itag == 140 diff --git a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/Thumbnail.kt b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/Thumbnail.kt index 1d6d9c4..5492f91 100644 --- a/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/Thumbnail.kt +++ b/app/src/main/kotlin/it/vfsfitvnm/vimusic/ui/screens/player/Thumbnail.kt @@ -31,6 +31,7 @@ import it.vfsfitvnm.vimusic.query import it.vfsfitvnm.vimusic.service.LoginRequiredException import it.vfsfitvnm.vimusic.service.PlayableFormatNotFoundException import it.vfsfitvnm.vimusic.service.UnplayableException +import it.vfsfitvnm.vimusic.service.VideoIdMismatchException import it.vfsfitvnm.vimusic.ui.styling.Dimensions import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance import it.vfsfitvnm.vimusic.ui.styling.px @@ -159,6 +160,7 @@ fun Thumbnail( is PlayableFormatNotFoundException -> "Couldn't find a playable audio format" is UnplayableException -> "The original video source of this song has been deleted" is LoginRequiredException -> "This song cannot be played due to server restrictions" + is VideoIdMismatchException -> "The returned video id didn't match the requested one" else -> "An unknown playback error has occurred" } }, diff --git a/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/Context.kt b/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/Context.kt index 92af0e8..0e7368a 100644 --- a/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/Context.kt +++ b/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/Context.kt @@ -11,8 +11,10 @@ data class Context( data class Client( val clientName: String, val clientVersion: String, - val visitorData: String?, + val platform: String, val hl: String = "en", + val visitorData: String? = null, + val androidSdkVersion: Int? = null ) @Serializable @@ -24,7 +26,8 @@ data class Context( val DefaultWeb = Context( client = Client( clientName = "WEB_REMIX", - clientVersion = "1.20220328.01.00", + clientVersion = "1.20220918", + platform = "DESKTOP", visitorData = "CgtsZG1ySnZiQWtSbyiMjuGSBg%3D%3D" ) ) @@ -32,8 +35,9 @@ data class Context( val DefaultAndroid = Context( client = Client( clientName = "ANDROID", - clientVersion = "16.50", - visitorData = null, + clientVersion = "17.36.4", + platform = "MOBILE", + androidSdkVersion = 31, ) ) @@ -41,6 +45,7 @@ data class Context( client = Client( clientName = "TVHTML5_SIMPLY_EMBEDDED_PLAYER", clientVersion = "2.0", + platform = "TV", visitorData = null, ) ) diff --git a/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/PlayerResponse.kt b/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/PlayerResponse.kt index 18ffe4f..2122816 100644 --- a/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/PlayerResponse.kt +++ b/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/models/PlayerResponse.kt @@ -7,6 +7,7 @@ data class PlayerResponse( val playabilityStatus: PlayabilityStatus?, val playerConfig: PlayerConfig?, val streamingData: StreamingData?, + val videoDetails: VideoDetails?, ) { @Serializable data class PlayabilityStatus( @@ -19,8 +20,7 @@ data class PlayerResponse( ) { @Serializable data class AudioConfig( - val loudnessDb: Double?, - val perceptualLoudnessDb: Double? + val loudnessDb: Double? ) } @@ -43,4 +43,9 @@ data class PlayerResponse( val url: String?, ) } + + @Serializable + data class VideoDetails( + val videoId: String? + ) } diff --git a/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/requests/Player.kt b/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/requests/Player.kt index c2554fd..40dc6a7 100644 --- a/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/requests/Player.kt +++ b/innertube/src/main/kotlin/it/vfsfitvnm/youtubemusic/requests/Player.kt @@ -34,7 +34,15 @@ suspend fun Innertube.player(body: PlayerBody) = runCatchingNonCancellable { ) val safePlayerResponse = client.post(player) { - setBody(body.copy(context = Context.DefaultAgeRestrictionBypass)) + setBody( + body.copy( + context = Context.DefaultAgeRestrictionBypass.copy( + thirdParty = Context.ThirdParty( + embedUrl = "https://www.youtube.com/watch?v=${body.videoId}" + ) + ), + ) + ) mask("playabilityStatus.status,playerConfig.audioConfig,streamingData.adaptiveFormats") }.body()