diff --git a/composeApp/src/androidMain/kotlin/it/fast4x/rimusic/service/PlayerService.kt b/composeApp/src/androidMain/kotlin/it/fast4x/rimusic/service/PlayerService.kt index 74835fa9f..fc522d3ff 100644 --- a/composeApp/src/androidMain/kotlin/it/fast4x/rimusic/service/PlayerService.kt +++ b/composeApp/src/androidMain/kotlin/it/fast4x/rimusic/service/PlayerService.kt @@ -2039,7 +2039,6 @@ class PlayerService : InvincibleService(), is SocketTimeoutException -> throw TimeoutException() else -> throw UnknownException() } - } runBlocking(Dispatchers.IO) { diff --git a/innertube/src/main/kotlin/it/fast4x/innertube/requests/Player.kt b/innertube/src/main/kotlin/it/fast4x/innertube/requests/Player.kt index 9e06baa1a..5ea7a1ad7 100644 --- a/innertube/src/main/kotlin/it/fast4x/innertube/requests/Player.kt +++ b/innertube/src/main/kotlin/it/fast4x/innertube/requests/Player.kt @@ -21,50 +21,51 @@ suspend fun Innertube.player(body: PlayerBody) = runCatchingNonCancellable { println("mediaItem requests Player response $response") - if (response.playabilityStatus?.status == "OK") { - response - } else { - @Serializable - data class AudioStream( - val url: String, - val bitrate: Long - ) + when( response.playabilityStatus?.status ) { + "OK", "LOGIN_REQUIRED", "UNPLAYABLE" -> response + else -> { + @Serializable + data class AudioStream( + val url: String, + val bitrate: Long + ) - @Serializable - data class PipedResponse( - val audioStreams: List - ) + @Serializable + data class PipedResponse( + val audioStreams: List + ) - val safePlayerResponse = client.post(player) { - setBody( - body.copy( - //context = Context.DefaultAgeRestrictionBypass.copy( - context = Context.DefaultWeb.copy( - thirdParty = Context.ThirdParty( - embedUrl = "https://www.youtube.com/watch?v=${body.videoId}" - ) - ), + val safePlayerResponse = client.post(player) { + setBody( + body.copy( + //context = Context.DefaultAgeRestrictionBypass.copy( + context = Context.DefaultWeb.copy( + thirdParty = Context.ThirdParty( + embedUrl = "https://www.youtube.com/watch?v=${body.videoId}" + ) + ), + ) ) - ) - mask("playabilityStatus.status,playerConfig.audioConfig,streamingData.adaptiveFormats,videoDetails.videoId") - }.body() + mask("playabilityStatus.status,playerConfig.audioConfig,streamingData.adaptiveFormats,videoDetails.videoId") + }.body() - if (safePlayerResponse.playabilityStatus?.status != "OK") { - return@runCatchingNonCancellable response - } + if (safePlayerResponse.playabilityStatus?.status != "OK") { + return@runCatchingNonCancellable response + } - val audioStreams = client.get("https://watchapi.whatever.social/streams/${body.videoId}") { - contentType(ContentType.Application.Json) - }.body().audioStreams + val audioStreams = client.get("https://watchapi.whatever.social/streams/${body.videoId}") { + contentType(ContentType.Application.Json) + }.body().audioStreams - safePlayerResponse.copy( - streamingData = safePlayerResponse.streamingData?.copy( - adaptiveFormats = safePlayerResponse.streamingData.adaptiveFormats?.map { adaptiveFormat -> - adaptiveFormat.copy( - url = audioStreams.find { it.bitrate == adaptiveFormat.bitrate }?.url - ) - } + safePlayerResponse.copy( + streamingData = safePlayerResponse.streamingData?.copy( + adaptiveFormats = safePlayerResponse.streamingData.adaptiveFormats?.map { adaptiveFormat -> + adaptiveFormat.copy( + url = audioStreams.find { it.bitrate == adaptiveFormat.bitrate }?.url + ) + } + ) ) - ) + } } }