From ea4b073f5c21b0fea4e3922488e8bbf69cfcb421 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:22:30 -0400 Subject: [PATCH] fix(YouTube - Spoof video streams): Handle app left open for a long time (#709) --- .../spoof/requests/StreamingDataRequest.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 c86b352f..1265092f 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 @@ public class StreamingDataRequest { 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);