From b6da0c7c65a58f68a19b128270e9749ee0a4f365 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:03:48 -0400 Subject: [PATCH 1/3] fix(YouTube - Spoof video streams): Block init by clearing query keys --- .../patches/spoof/SpoofVideoStreamsPatch.java | 4 ++-- .../spoof/requests/StreamingDataRequest.java | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java index d3c964078f..24728a9419 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java @@ -69,9 +69,9 @@ public static String blockInitPlaybackRequest(String originalUrlString) { String path = originalUri.getPath(); if (path != null && path.contains("initplayback")) { - Logger.printDebug(() -> "Blocking 'initplayback' by returning unreachable url"); + Logger.printDebug(() -> "Blocking 'initplayback' by clearing query"); - return UNREACHABLE_HOST_URI_STRING; + return originalUri.buildUpon().clearQuery().build().toString(); } } catch (Exception ex) { Logger.printException(() -> "blockInitPlaybackRequest failure", ex); diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/requests/StreamingDataRequest.java b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/requests/StreamingDataRequest.java index c86b352f08..1265092ffd 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/requests/StreamingDataRequest.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/requests/StreamingDataRequest.java @@ -53,6 +53,12 @@ public class StreamingDataRequest { } } + private static final String[] REQUEST_HEADER_KEYS = { + "Authorization", // Available only to logged in users. + "X-GOOG-API-FORMAT-VERSION", + "X-Goog-Visitor-Id" + }; + /** * TCP connection and HTTP read timeout. */ @@ -112,10 +118,12 @@ private static HttpURLConnection send(ClientType clientType, String videoId, connection.setConnectTimeout(HTTP_TIMEOUT_MILLISECONDS); connection.setReadTimeout(HTTP_TIMEOUT_MILLISECONDS); - String authHeader = playerHeaders.get("Authorization"); - String visitorId = playerHeaders.get("X-Goog-Visitor-Id"); - connection.setRequestProperty("Authorization", authHeader); - connection.setRequestProperty("X-Goog-Visitor-Id", visitorId); + for (String key : REQUEST_HEADER_KEYS) { + String value = playerHeaders.get(key); + if (value != null) { + connection.setRequestProperty(key, value); + } + } String innerTubeBody = String.format(PlayerRoutes.createInnertubeBody(clientType), videoId); byte[] requestBody = innerTubeBody.getBytes(StandardCharsets.UTF_8); From 739e17054af7ecf29d14b33ff0ca577688e19b4d Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:14:18 -0400 Subject: [PATCH 2/3] comments --- .../youtube/patches/spoof/SpoofVideoStreamsPatch.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java index 24728a9419..96390eb507 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java @@ -69,6 +69,12 @@ public static String blockInitPlaybackRequest(String originalUrlString) { String path = originalUri.getPath(); if (path != null && path.contains("initplayback")) { + // This previously returned an unreachable URL and it seemed to work for nearly all situations, + // but an unreachable url would cause playback failure if the app changes to/from mobile + // or if the app is left open for a long period of time. + // + // Presumably the failure is caused by a side effect that does not occur right away, + // but this is only speculation and the exact reason why this fix works is is not clear. Logger.printDebug(() -> "Blocking 'initplayback' by clearing query"); return originalUri.buildUpon().clearQuery().build().toString(); From 462c833793eff91bd903c841f971c416f37483d9 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:18:16 -0400 Subject: [PATCH 3/3] fix: Use unreachable again --- .../patches/spoof/SpoofVideoStreamsPatch.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java index 96390eb507..d3c964078f 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofVideoStreamsPatch.java @@ -69,15 +69,9 @@ public static String blockInitPlaybackRequest(String originalUrlString) { String path = originalUri.getPath(); if (path != null && path.contains("initplayback")) { - // This previously returned an unreachable URL and it seemed to work for nearly all situations, - // but an unreachable url would cause playback failure if the app changes to/from mobile - // or if the app is left open for a long period of time. - // - // Presumably the failure is caused by a side effect that does not occur right away, - // but this is only speculation and the exact reason why this fix works is is not clear. - Logger.printDebug(() -> "Blocking 'initplayback' by clearing query"); - - return originalUri.buildUpon().clearQuery().build().toString(); + Logger.printDebug(() -> "Blocking 'initplayback' by returning unreachable url"); + + return UNREACHABLE_HOST_URI_STRING; } } catch (Exception ex) { Logger.printException(() -> "blockInitPlaybackRequest failure", ex);