youpipe: fix android_vr player request (align with PipePipe: www.youtube.com player endpoint, X-YouTube-Client-Name/Version headers, playbackContext signatureTimestamp+html5Preference)
- Commit
4698c02ed8009839cf8c5f03f75bf960670e2fab- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 04:40 UTC (3 months ago)
- Parents
7e4ab81
Diff
youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.kt
diff --git a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.kt b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.ktindex 8b41c19ed5..05c7580226 100644--- a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.kt+++ b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.kt@@ -207,9 +207,20 @@ object YoutubeStreamHelper { ): JsonObject { // ANDROID_VR returns direct stream URLs and does not require a PO Token or visitorData, // which is why it is far more reliable than the SABR (WEB) path right now.+ //+ // The request shape mirrors PipePipe's working android_vr player call:+ // - the standard www.youtube.com InnerTube player endpoint (NOT the gapis host, and+ // without the &t=/&id= params, which the gapis PO-token flow uses);+ // - X-YouTube-Client-Name (28) / X-YouTube-Client-Version headers identifying the client;+ // - a playbackContext carrying the signatureTimestamp + HTML5 preference so YouTube+ // returns HTML5-decipherable formats instead of an invalid/SABR-only response. val innertubeClientRequestInfo = InnertubeClientRequestInfo.ofAndroidVrClient() - val headers = getMobileClientHeaders(ClientsConstants.ANDROID_VR_USER_AGENT)+ val headers = mapOf(+ "User-Agent" to listOf(ClientsConstants.ANDROID_VR_USER_AGENT),+ "X-YouTube-Client-Name" to listOf(ClientsConstants.ANDROID_VR_CLIENT_ID),+ "X-YouTube-Client-Version" to listOf(ClientsConstants.ANDROID_VR_CLIENT_VERSION)+ ) val builder = prepareJsonBuilder( localization, contentCountry, innertubeClientRequestInfo, null@@ -217,10 +228,13 @@ object YoutubeStreamHelper { addVideoIdCpnAndOkChecks(builder, videoId, cpn) + addVrPlaybackContext(+ builder, YoutubeJavaScriptPlayerManager.getSignatureTimestamp(videoId)+ )+ val body = builder.done().toString().toByteArray(Charsets.UTF_8) - val url = YOUTUBEI_V1_GAPIS_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER +- "&t=" + generateTParameter() + "&id=" + videoId+ val url = YOUTUBEI_V1_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER return JsonUtils.toJsonObject( getValidJsonResponseBody(@@ -339,6 +353,18 @@ object YoutubeStreamHelper { .end() } + private fun addVrPlaybackContext(+ builder: YoutubeJsonBuilder,+ signatureTimestamp: Int+ ) {+ builder.`object`("playbackContext")+ .`object`("contentPlaybackContext")+ .value("html5Preference", "HTML5_PREF_WANTS")+ .value("signatureTimestamp", signatureTimestamp)+ .end()+ .end()+ }+ private fun addPoToken(builder: YoutubeJsonBuilder, poToken: String) { builder.`object`(SERVICE_INTEGRITY_DIMENSIONS) .value(PO_TOKEN, poToken)