Modern Apps git

← Modern-Apps.git

youpipe: revert playback to ANDROID_VR direct client, deprioritize SABR

Commit
cb3bd2e4af70c3236f07c9c12845c1048bcb27a9
Author
vayun-mathur <[email protected]>
When
2026-08-15 17:24 UTC (3 months ago)
Parents
e6b1d12
SABR (WEB/visitorData) is being probabilistically rejected server-side,
resulting in status-2 responses that only serve the first ~60s. Switch the
primary playback path back to the ANDROID_VR client, which returns direct
stream URLs without a PO Token and has a far lower failure rate.

- Add ANDROID_VR client (ClientsConstants, InnertubeClientRequestInfo.ofAndroidVrClient,
  YoutubeStreamHelper.getAndroidVrPlayerResponse) using the gapis player endpoint,
  no PO Token / visitorData.
- YoutubeStreamExtractor.onFetchPage now fetches ANDROID_VR instead of ANDROID.
- SABR is now a last-resort fallback: only probed/appended when the direct
  client returns no streams. SABR implementation is preserved for later.

Diff

youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/ClientsConstants.kt
diff --git a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/ClientsConstants.kt b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/ClientsConstants.ktindex 98fe8a338e..06ec7c98e6 100644--- a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/ClientsConstants.kt+++ b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/ClientsConstants.kt@@ -85,6 +85,21 @@ internal object ClientsConstants {      */     const val ANDROID_CLIENT_VERSION = "21.03.36" +    // ANDROID_VR (Meta Quest YouTube VR app) client fields.+    // This client still returns direct stream URLs without a PO Token, so it is used as the+    // primary playback client while SABR (WEB/visitorData) is being probabilistically rejected.+    const val ANDROID_VR_CLIENT_ID = "28"+    const val ANDROID_VR_CLIENT_NAME = "ANDROID_VR"+    const val ANDROID_VR_CLIENT_VERSION = "1.65.10"+    const val ANDROID_VR_DEVICE_MAKE = "Oculus"+    const val ANDROID_VR_DEVICE_MODEL = "Quest 3"+    const val ANDROID_VR_OS_NAME = "Android"+    const val ANDROID_VR_OS_VERSION = "12L"+    const val ANDROID_VR_SDK_VERSION = 32+    const val ANDROID_VR_USER_AGENT =+        "com.google.android.apps.youtube.vr.oculus/1.65.10 " ++            "(Linux; U; Android 12L; eureka-user Build/SQ3A.220605.009.A1) gzip"+     // visionOS client fields     const val VISIONOS_CLIENT_ID = "101"     const val VISIONOS_CLIENT_NAME = "VISIONOS"
youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/InnertubeClientRequestInfo.kt
diff --git a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/InnertubeClientRequestInfo.kt b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/InnertubeClientRequestInfo.ktindex 9b7b2fc9c6..4e7c438e6d 100644--- a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/InnertubeClientRequestInfo.kt+++ b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/InnertubeClientRequestInfo.kt@@ -138,6 +138,27 @@ class InnertubeClientRequestInfo private constructor(             )         } +        @JvmStatic+        fun ofAndroidVrClient(): InnertubeClientRequestInfo {+            return InnertubeClientRequestInfo(+                ClientInfo.create(+                    ClientsConstants.ANDROID_VR_CLIENT_NAME,+                    ClientsConstants.ANDROID_VR_CLIENT_VERSION,+                    ClientsConstants.ANDROID_VR_CLIENT_ID,+                    null,+                    null+                ),+                DeviceInfo.create(+                    ClientsConstants.MOBILE_CLIENT_PLATFORM,+                    ClientsConstants.ANDROID_VR_DEVICE_MAKE,+                    ClientsConstants.ANDROID_VR_DEVICE_MODEL,+                    ClientsConstants.ANDROID_VR_OS_NAME,+                    ClientsConstants.ANDROID_VR_OS_VERSION,+                    ClientsConstants.ANDROID_VR_SDK_VERSION+                )+            )+        }+         @JvmStatic         fun ofIosClient(): InnertubeClientRequestInfo {             return InnertubeClientRequestInfo(
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 51576149f4..8b41c19ed5 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@@ -197,6 +197,38 @@ object YoutubeStreamHelper {         ).getObject("playerResponse")     } +    @JvmStatic+    @Throws(IOException::class, ExtractionException::class)+    fun getAndroidVrPlayerResponse(+        contentCountry: ContentCountry,+        localization: Localization,+        videoId: String,+        cpn: String+    ): 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.+        val innertubeClientRequestInfo = InnertubeClientRequestInfo.ofAndroidVrClient()++        val headers = getMobileClientHeaders(ClientsConstants.ANDROID_VR_USER_AGENT)++        val builder = prepareJsonBuilder(+            localization, contentCountry, innertubeClientRequestInfo, null+        )++        addVideoIdCpnAndOkChecks(builder, videoId, cpn)++        val body = builder.done().toString().toByteArray(Charsets.UTF_8)++        val url = YOUTUBEI_V1_GAPIS_URL + PLAYER + "?" + DISABLE_PRETTY_PRINT_PARAMETER ++            "&t=" + generateTParameter() + "&id=" + videoId++        return JsonUtils.toJsonObject(+            getValidJsonResponseBody(+                getDownloader().postWithContentTypeJson(url, headers, body, localization)+            )+        )+    }+     @JvmStatic     @Throws(IOException::class, ExtractionException::class)     fun getIosPlayerResponse(
youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.kt
diff --git a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.kt b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.ktindex bf69a6e038..5999c332ef 100644--- a/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.kt+++ b/youpipe/extractor/src/main/kotlin/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.kt@@ -688,8 +688,12 @@ class YoutubeStreamExtractor(             ADAPTIVE_FORMATS, ItagItem.ItagType.AUDIO,             getAudioStreamBuilderHelper(), "audio"         )-        buildSabrStreamsIfNeeded()-        streams.addAll(sabrAudioStreams)+        // SABR is a last-resort fallback: only probe/append it when the ANDROID_VR direct+        // client returned no usable streams.+        if (streams.isEmpty()) {+            buildSabrStreamsIfNeeded()+            streams.addAll(sabrAudioStreams)+        }         return streams     } @@ -709,8 +713,12 @@ class YoutubeStreamExtractor(             ADAPTIVE_FORMATS, ItagItem.ItagType.VIDEO_ONLY,             getVideoStreamBuilderHelper(true), "video-only"         )-        buildSabrStreamsIfNeeded()-        streams.addAll(sabrVideoOnlyStreams)+        // SABR is a last-resort fallback: only probe/append it when the ANDROID_VR direct+        // client returned no usable streams.+        if (streams.isEmpty()) {+            buildSabrStreamsIfNeeded()+            streams.addAll(sabrVideoOnlyStreams)+        }         return streams     } @@ -852,10 +860,7 @@ class YoutubeStreamExtractor(         val poTokenProviderInstance = poTokenProvider         val noPoTokenProviderSet = poTokenProviderInstance == null -        val androidPoTokenResult = if (noPoTokenProviderSet) null-        else poTokenProviderInstance.getAndroidClientPoToken(videoId)--        fetchAndroidClient(localization, contentCountry, videoId, androidPoTokenResult)+        fetchAndroidVrClient(localization, contentCountry, videoId)          setStreamType() @@ -879,38 +884,26 @@ class YoutubeStreamExtractor(     }      @Throws(IOException::class, ExtractionException::class)-    private fun fetchAndroidClient(+    private fun fetchAndroidVrClient(         localization: Localization,         contentCountry: ContentCountry,-        videoId: String,-        androidPoTokenResult: PoTokenResult?+        videoId: String     ) {         androidCpn = generateContentPlaybackNonce() -        playerResponse = if (androidPoTokenResult == null) {-            YoutubeStreamHelper.getAndroidReelPlayerResponse(-                contentCountry, localization, videoId, androidCpn!!-            )-        } else {-            YoutubeStreamHelper.getAndroidPlayerResponse(-                contentCountry, localization, videoId, androidCpn!!,-                androidPoTokenResult-            )-        }+        playerResponse = YoutubeStreamHelper.getAndroidVrPlayerResponse(+            contentCountry, localization, videoId, androidCpn!!+        )          checkPlayabilityStatus(playerResponse!!.getObject(PLAYABILITY_STATUS).orEmptyObject())         if (isPlayerResponseNotValid(playerResponse, videoId)) {-            throw ExtractionException("ANDROID player response is not valid")+            throw ExtractionException("ANDROID_VR player response is not valid")         }          androidStreamingData = playerResponse?.getObject(STREAMING_DATA)          playerCaptionsTracklistRenderer = playerResponse?.getObject(CAPTIONS)             ?.getObject(PLAYER_CAPTIONS_TRACKLIST_RENDERER)--        if (androidPoTokenResult != null) {-            androidStreamingUrlsPoToken = androidPoTokenResult.streamingDataPoToken-        }     }      private fun fetchIosClient(