fix(YouTube - Spoof video streams): Use Android VR authentication if using default audio language (#4191)

This commit is contained in:
LisoUseInAIKyrios 2024-12-22 14:22:49 +04:00 committed by GitHub
parent f7d5701ad1
commit 98773cc7d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 13 deletions

View File

@ -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.
/**

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeoutException;
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 @@ import app.revanced.extension.shared.spoof.ClientType;
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<String, StreamingDataRequest> cache = Collections.synchronizedMap(
new LinkedHashMap<>(100) {
/**
@ -68,6 +74,7 @@ public class StreamingDataRequest {
});
private final String videoId;
private final Future<ByteBuffer> future;
private StreamingDataRequest(String videoId, Map<String, String> playerHeaders) {
@ -157,13 +164,21 @@ public class StreamingDataRequest {
// 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()) {

View File

@ -1298,12 +1298,11 @@ Video playback may not work"</string>
<string name="revanced_spoof_video_streams_user_dialog_message">Turning off this setting may cause video playback issues.</string>
<string name="revanced_spoof_video_streams_client_type_title">Default client</string>
<string name="revanced_spoof_video_streams_about_title">Spoofing side effects</string>
<string name="revanced_spoof_video_streams_about_summary">"• Kids videos may not play
• Audio track menu is missing
<string name="revanced_spoof_video_streams_about_summary">"• Audio track menu is missing
• Stable volume is not available
• Force original audio is not available"</string>
<string name="revanced_spoof_video_streams_language_title">Default audio stream language</string>
<string name="revanced_spoof_video_streams_language_DEFAULT">App language</string>
<string name="revanced_spoof_video_streams_language_DEFAULT">Account language</string>
<string name="revanced_spoof_video_streams_language_AR">Arabic</string>
<string name="revanced_spoof_video_streams_language_AZ">Azerbaijani</string>
<string name="revanced_spoof_video_streams_language_BG">Bulgarian</string>