Skip to content

Commit

Permalink
fix: Remove questionable parameters, use actual user-agent as constru…
Browse files Browse the repository at this point in the history
…cted by the spoofed client
  • Loading branch information
LisoUseInAIKyrios committed Jan 17, 2025
1 parent 32474c2 commit 7f5ca5f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.annotation.Nullable;

import java.util.Locale;
import java.util.Objects;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.settings.BaseSettings;
Expand All @@ -17,13 +18,13 @@ public enum ClientType {
"com.google.android.apps.youtube.vr.oculus",
"Oculus",
"Quest 3",
"Qualcomm;SXR2230P",
null,
"Android",
"12",
"32", // Android 12.1
// Android 12.1
"32",
"SQ3A.220605.009.A1",
"1.56.21",
"1.61.48",
"132.0.6808.3",
false,
"Android VR No auth"
),
Expand All @@ -35,13 +36,12 @@ public enum ClientType {
"com.google.android.apps.youtube.unplugged",
"Google",
"Google TV Streamer",
"Mediatek;MT8696",
"244336107",
"Android",
"14",
"34",
"UTT3.240625.001.K5",
"8.49.0",
"132.0.6808.3",
true,
"Android TV"
),
Expand All @@ -54,13 +54,12 @@ public enum ClientType {
"com.google.android.apps.youtube.creator",
"Google",
"Pixel 9 Pro Fold",
"Google;Tensor G4",
"244738035",
"Android",
"15",
"35",
"AP3A.241005.015.A2",
"23.47.101",
"132.0.6779.0",
true,
"Android Creator"
),
Expand All @@ -70,13 +69,12 @@ public enum ClientType {
ANDROID_VR_NO_AUTH.packageName,
ANDROID_VR_NO_AUTH.deviceMake,
ANDROID_VR_NO_AUTH.deviceModel,
ANDROID_VR_NO_AUTH.chipset,
ANDROID_VR_NO_AUTH.gmscoreVersionCode,
ANDROID_VR_NO_AUTH.osName,
ANDROID_VR_NO_AUTH.osVersion,
ANDROID_VR_NO_AUTH.androidSdkVersion,
ANDROID_VR_NO_AUTH.buildId,
ANDROID_VR_NO_AUTH.clientVersion,
ANDROID_VR_NO_AUTH.cronetVersion,
true,
"Android VR"
),
Expand All @@ -86,24 +84,26 @@ public enum ClientType {
"com.google.ios.youtubeunplugged",
"Apple",
forceAVC()
? "iPhone12,5" // 11 Pro Max (last device with iOS 13)
: "iPhone16,2", // 15 Pro Max
null,
null,
// 11 Pro Max (last device with iOS 13)
? "iPhone12,5"
// 15 Pro Max
: "iPhone16,2",
"iOS",
// iOS 13 and earlier uses only AVC. 14+ adds VP9 and AV1.
// Some newer versions can also force AVC,
// but 6.45 is the last version that supports iOS 13.
forceAVC()
? "13.7.17H35" // Last release of iOS 13.
// Last release of iOS 13.
? "13.7.17H35"
: "18.2.22C152",
null,
null,
// Version number should be a valid iOS release.
// https://www.ipa4fun.com/history/152043/
// Some newer versions can also force AVC,
// but 6.45 is the last version that supports iOS 13.
forceAVC()
? "6.45"
: "8.49",
null,
true,
forceAVC()
? "iOS TV Force AVC"
Expand All @@ -127,6 +127,11 @@ private static boolean forceAVC() {
*/
public final String packageName;

/**
* Player user-agent.
*/
public final String userAgent;

/**
* Device model, equivalent to {@link Build#MANUFACTURER} (System property: ro.product.vendor.manufacturer)
*/
Expand All @@ -137,20 +142,6 @@ private static boolean forceAVC() {
*/
public final String deviceModel;

/**
* Android chipset.
* Field is null if not applicable.
*/
@Nullable
public final String chipset;

/**
* GmsCore versionCode.
* Field is null if not applicable.
*/
@Nullable
public final String gmscoreVersionCode; // JSON field does not use 'gmsCore' casing.

/**
* Device OS name.
*/
Expand All @@ -161,11 +152,6 @@ private static boolean forceAVC() {
*/
public final String osVersion;

/**
* Player user-agent.
*/
public final String userAgent;

/**
* Android SDK version, equivalent to {@link Build.VERSION#SDK} (System property: ro.build.version.sdk)
* Field is null if not applicable.
Expand All @@ -185,6 +171,13 @@ private static boolean forceAVC() {
*/
public final String clientVersion;

/**
* Cronet release version, as found in decompiled client apk.
* Field is null if not applicable.
*/
@Nullable
public final String cronetVersion;

/**
* If the client can access the API logged in.
*/
Expand All @@ -201,44 +194,43 @@ private static boolean forceAVC() {
String packageName,
String deviceMake,
String deviceModel,
@Nullable String chipset,
@Nullable String gmscoreVersionCode,
String osName,
String osVersion,
String osName, String osVersion,
@Nullable String androidSdkVersion,
@Nullable String buildId,
String clientVersion,
@Nullable String cronetVersion,
boolean canLogin,
String friendlyName) {
this.id = id;
this.clientName = clientName;
this.packageName = packageName;
this.deviceMake = deviceMake;
this.deviceModel = deviceModel;
this.chipset = chipset;
this.gmscoreVersionCode = gmscoreVersionCode;
this.osName = osName;
this.osVersion = osVersion;
this.androidSdkVersion = androidSdkVersion;
this.buildId = buildId;
this.clientVersion = clientVersion;
this.cronetVersion = cronetVersion;
this.canLogin = canLogin;
this.friendlyName = friendlyName;

Locale defaultLocale = Locale.getDefault();
if (androidSdkVersion != null) {
// https://whatmyuseragent.com/apps/youtube
this.userAgent = packageName + "/" + clientVersion + "(Linux; U; Android " + osVersion + "; "
+ defaultLocale + "; " + deviceModel + " " + "Build/" + buildId + ") gzip";
} else {
// https://github.com/mitmproxy/mitmproxy/issues/4836
if (androidSdkVersion == null) {
// Convert version from '18.2.22C152' into '18_2_22'
String userAgentOsVersion = osVersion
.replaceAll("(\\d+\\.\\d+\\.\\d+).*", "$1")
.replace(".", "_");
this.userAgent = packageName + "/" + clientVersion + "(" + deviceModel + "; U; CPU " +
userAgentOsVersion + " like Mac OS X; " + defaultLocale + ")";
// https://github.com/mitmproxy/mitmproxy/issues/4836
this.userAgent = packageName + "/" + clientVersion + " (" + deviceModel + "; U; CPU iOS "
+ userAgentOsVersion + " like Mac OS X; " + defaultLocale + ")";
} else {
Objects.requireNonNull(buildId);
Objects.requireNonNull(cronetVersion);
this.userAgent = packageName + "/" + clientVersion + " (Linux; U; Android " + osVersion + "; "
+ defaultLocale + "; " + deviceModel + "; Build/" + buildId + "; Cronet/" + cronetVersion +")";
}
Logger.printDebug(() -> "user agent: " + this.userAgent);
this.clientVersion = clientVersion;
this.canLogin = canLogin;
this.friendlyName = friendlyName;
Logger.printDebug(() -> "userAgent: " + this.userAgent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.requests.Requester;
Expand Down Expand Up @@ -57,18 +55,9 @@ static String createInnertubeBody(ClientType clientType, String videoId) {
client.put("osVersion", clientType.osVersion);
if (clientType.androidSdkVersion != null) {
client.put("androidSdkVersion", clientType.androidSdkVersion);
if (clientType.gmscoreVersionCode != null) {
client.put("gmscoreVersionCode", clientType.gmscoreVersionCode);
}
if (clientType.chipset != null) {
client.put("chipset", clientType.chipset);
}
}
client.put("hl", streamLocale.getLanguage());
client.put("gl", streamLocale.getCountry());
TimeZone zone = TimeZone.getDefault();
client.put("timeZone", zone.getID());
client.put("utcOffsetMinutes", zone.getOffset(new Date().getTime()) / 60000);
context.put("client", client);

innerTubeBody.put("context", context);
Expand Down

0 comments on commit 7f5ca5f

Please sign in to comment.