From 98773cc7d46e5c9c7715b82c8006f1ccbcc5443c Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sun, 22 Dec 2024 14:22:49 +0400 Subject: [PATCH] fix(YouTube - Spoof video streams): Use Android VR authentication if using default audio language (#4191) --- .../extension/shared/spoof/ClientType.java | 9 --------- .../spoof/requests/StreamingDataRequest.java | 17 ++++++++++++++++- .../resources/addresources/values/strings.xml | 5 ++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java index 8df70412c9..14240a7677 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java @@ -33,15 +33,6 @@ public enum ClientType { "com.google.android.apps.youtube.unplugged/8.49.0 (Linux; U; Android 14; GB) gzip", "34", "8.49.0", - true), // Requires login. - ANDROID_CREATOR( - 14, - "ANDROID_CREATOR", - "Android", - "11", - "com.google.android.apps.youtube.creator/24.45.100 (Linux; U; Android 11) gzip", - "30", - "24.45.100", true); // Requires login. /** diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/StreamingDataRequest.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/StreamingDataRequest.java index 9020457e16..67f687b79f 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/StreamingDataRequest.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/StreamingDataRequest.java @@ -22,6 +22,7 @@ import app.revanced.extension.shared.Logger; import app.revanced.extension.shared.Utils; import app.revanced.extension.shared.settings.BaseSettings; +import app.revanced.extension.shared.spoof.AudioStreamLanguage; import app.revanced.extension.shared.spoof.ClientType; /** @@ -36,20 +37,25 @@ public class StreamingDataRequest { private static final ClientType[] CLIENT_ORDER_TO_USE = ClientType.values(); + private static final String AUTHORIZATION_HEADER = "Authorization"; + private static final String[] REQUEST_HEADER_KEYS = { AUTHORIZATION_HEADER, // Available only to logged-in users. "X-GOOG-API-FORMAT-VERSION", "X-Goog-Visitor-Id" }; + /** * TCP connection and HTTP read timeout. */ private static final int HTTP_TIMEOUT_MILLISECONDS = 10 * 1000; + /** * Any arbitrarily large value, but must be at least twice {@link #HTTP_TIMEOUT_MILLISECONDS} */ private static final int MAX_MILLISECONDS_TO_WAIT_FOR_FETCH = 20 * 1000; + private static final Map cache = Collections.synchronizedMap( new LinkedHashMap<>(100) { /** @@ -68,6 +74,7 @@ protected boolean removeEldestEntry(Entry eldest) { }); private final String videoId; + private final Future future; private StreamingDataRequest(String videoId, Map playerHeaders) { @@ -157,13 +164,21 @@ private static ByteBuffer fetch(String videoId, Map playerHeader // Show an error if the last client type fails, or if the debug is enabled then show for all attempts. final boolean showErrorToast = (++i == CLIENT_ORDER_TO_USE.length) || debugEnabled; + if (clientType == ClientType.ANDROID_VR_NO_AUTH + && BaseSettings.SPOOF_VIDEO_STREAMS_LANGUAGE.get() == AudioStreamLanguage.DEFAULT) { + // Only use no auth Android VR if a non default audio language is selected. + continue; + } + HttpURLConnection connection = send(clientType, videoId, playerHeaders, showErrorToast); if (connection != null) { try { // gzip encoding doesn't response with content length (-1), // but empty response body does. if (connection.getContentLength() == 0) { - Logger.printDebug(() -> "Received empty response for client: " + clientType); + if (BaseSettings.DEBUG.get()) { + Logger.printException(() -> "Ignoring empty client response: " + clientType); + } } else { try (InputStream inputStream = new BufferedInputStream(connection.getInputStream()); ByteArrayOutputStream baos = new ByteArrayOutputStream()) { diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 412d7dbb79..97de323558 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -1298,12 +1298,11 @@ Video playback may not work" Turning off this setting may cause video playback issues. Default client Spoofing side effects - "• Kids videos may not play -• Audio track menu is missing + "• Audio track menu is missing • Stable volume is not available • Force original audio is not available" Default audio stream language - App language + Account language Arabic Azerbaijani Bulgarian