Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Client spoof): Some side effects of iOS client
Browse files Browse the repository at this point in the history
β€’ No HDR video β†’ HDR video is supported only on AV1 codec
β€’ Higher video qualities may not be available β†’ fixed
β€’ Live streams not available on Android 8.0 β†’ fixed
  • Loading branch information
inotia00 authored and anddea committed Jul 29, 2024
1 parent 5963ac1 commit 37a814a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,33 @@ public static String getClientModel(String originalClientModel) {
return originalClientModel;
}

/**
* Injection point.
*/
public static String getOsVersion(String originalOsVersion) {
if (SPOOF_CLIENT_ENABLED) {
return getSpoofClientType().osVersion;
}

return originalOsVersion;
}

/**
* Injection point.
*/
public static String getUserAgent(String originalUserAgent) {
if (SPOOF_CLIENT_ENABLED) {
ClientType clientType = getSpoofClientType();
if (clientType == ClientType.IOS) {
Logger.printDebug(() -> "Replaced: '" + originalUserAgent + "' with: '"
+ clientType.userAgent + "'");
return clientType.userAgent;
}
}

return originalUserAgent;
}

/**
* Injection point.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static app.revanced.integrations.shared.utils.StringRef.str;

import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.os.Build;

import org.json.JSONException;
Expand Down Expand Up @@ -46,7 +48,7 @@ public final class PlayerRoutes {
private static final String ANDROID_TESTSUITE_CLIENT_VERSION = "1.9";


private static final String ANDROID_UNPLUGGED_CLIENT_VERSION = "8.01.0";
private static final String ANDROID_UNPLUGGED_CLIENT_VERSION = "8.30.1";
/**
* The device machine id for the Chromecast with Google TV 4K.
*
Expand Down Expand Up @@ -74,7 +76,7 @@ public final class PlayerRoutes {
* Store page of the YouTube app</a>, in the {@code Additional details} section.
* </p>
*/
private static final String ANDROID_VR_CLIENT_VERSION = "1.56.21";
private static final String ANDROID_VR_CLIENT_VERSION = "1.58.14";

/**
* The device machine id for the Meta Quest 3, used to get opus codec with the Android VR client.
Expand Down Expand Up @@ -112,16 +114,17 @@ public final class PlayerRoutes {
* Store page of the YouTube app</a>, in the {@code What’s New} section.
* </p>
*/
private static final String IOS_CLIENT_VERSION = "19.01.1";
private static final String IOS_CLIENT_VERSION = "19.29.1";
/**
* The device machine id for the iPhone 14 Pro Max, used to get 60fps with the iOS client.
* The device machine id for the iPhone 14 Pro Max (iPhone15,3), used to get 60fps.
* The device machine id for the iPhone 15 Pro Max (iPhone16,2), used to get HDR with AV1 hardware decoding.
*
* <p>
* See <a href="https://gist.github.com/adamawolf/3048717">this GitHub Gist</a> for more
* information.
* </p>
*/
private static final String IOS_DEVICE_MODEL = "iPhone15,3";
private static final String IOS_DEVICE_MODEL = deviceHasAV1HardwareDecoding() ? "iPhone16,2" : "iPhone15,3";
private static final String IOS_OS_VERSION = "17.5.1.21F90";
private static final String IOS_USER_AGENT_VERSION = "17_5_1";
private static final String IOS_USER_AGENT = "com.google.ios.youtube/" +
Expand All @@ -136,7 +139,7 @@ public final class PlayerRoutes {
private static final String TVHTML5_SIMPLY_EMBEDDED_PLAYER_USER_AGENT = "Mozilla/5.0 (SMART-TV; LINUX; Tizen 6.5)" +
" AppleWebKit/537.36 (KHTML, like Gecko)" +
" 85.0.4183.93/6.5 TV Safari/537.36";
private static final String WEB_CLIENT_VERSION = "2.20240304.00.00";
private static final String WEB_CLIENT_VERSION = "2.20240718.01.00";
private static final String WEB_USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-G981B)" +
" AppleWebKit/537.36 (KHTML, like Gecko)" +
" Chrome/80.0.3987.162 Mobile Safari/537.36";
Expand Down Expand Up @@ -341,6 +344,30 @@ public final class PlayerRoutes {
WEB_INNER_TUBE_BODY = webInnerTubeBody.toString();
}

private static boolean deviceHasAV1HardwareDecoding() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);

for (MediaCodecInfo codecInfo : codecList.getCodecInfos()) {
if (codecInfo.isHardwareAccelerated() && !codecInfo.isEncoder()) {
String[] supportedTypes = codecInfo.getSupportedTypes();
for (String type : supportedTypes) {
if (type.equalsIgnoreCase("video/av01")) {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(type);
if (capabilities != null) {
Logger.printDebug(() -> "Device supports AV1 hardware decoding.");
return true;
}
}
}
}
}
}

Logger.printDebug(() -> "Device does not support AV1 hardware decoding.");
return false;
}

private PlayerRoutes() {
}

Expand All @@ -363,31 +390,33 @@ public static HttpURLConnection getPlayerResponseConnectionFromRoute(Route.Compi
}

public enum ClientType {
ANDROID(3, ANDROID_DEVICE_MODEL, ANDROID_CLIENT_VERSION, ANDROID_INNER_TUBE_BODY, ANDROID_USER_AGENT),
ANDROID_EMBEDDED_PLAYER(55, ANDROID_DEVICE_MODEL, ANDROID_CLIENT_VERSION, ANDROID_EMBED_INNER_TUBE_BODY, ANDROID_USER_AGENT),
ANDROID_TESTSUITE(30, ANDROID_DEVICE_MODEL, ANDROID_TESTSUITE_CLIENT_VERSION, ANDROID_TESTSUITE_INNER_TUBE_BODY, ANDROID_USER_AGENT),
ANDROID_UNPLUGGED(29, ANDROID_UNPLUGGED_DEVICE_MODEL, ANDROID_UNPLUGGED_CLIENT_VERSION, ANDROID_UNPLUGGED_INNER_TUBE_BODY, ANDROID_UNPLUGGED_USER_AGENT),
ANDROID_VR(28, ANDROID_VR_DEVICE_MODEL, ANDROID_VR_CLIENT_VERSION, ANDROID_VR_INNER_TUBE_BODY, ANDROID_VR_USER_AGENT),
IOS(5, IOS_DEVICE_MODEL, IOS_CLIENT_VERSION, IOS_INNER_TUBE_BODY, IOS_USER_AGENT),
ANDROID(3, ANDROID_DEVICE_MODEL, ANDROID_CLIENT_VERSION, ANDROID_INNER_TUBE_BODY, ANDROID_OS_RELEASE_VERSION, ANDROID_USER_AGENT),
ANDROID_EMBEDDED_PLAYER(55, ANDROID_DEVICE_MODEL, ANDROID_CLIENT_VERSION, ANDROID_EMBED_INNER_TUBE_BODY, ANDROID_OS_RELEASE_VERSION, ANDROID_USER_AGENT),
ANDROID_TESTSUITE(30, ANDROID_DEVICE_MODEL, ANDROID_TESTSUITE_CLIENT_VERSION, ANDROID_TESTSUITE_INNER_TUBE_BODY, ANDROID_OS_RELEASE_VERSION, ANDROID_USER_AGENT),
ANDROID_UNPLUGGED(29, ANDROID_UNPLUGGED_DEVICE_MODEL, ANDROID_UNPLUGGED_CLIENT_VERSION, ANDROID_UNPLUGGED_INNER_TUBE_BODY, ANDROID_UNPLUGGED_OS_RELEASE_VERSION, ANDROID_UNPLUGGED_USER_AGENT),
ANDROID_VR(28, ANDROID_VR_DEVICE_MODEL, ANDROID_VR_CLIENT_VERSION, ANDROID_VR_INNER_TUBE_BODY, ANDROID_VR_OS_RELEASE_VERSION, ANDROID_VR_USER_AGENT),
IOS(5, IOS_DEVICE_MODEL, IOS_CLIENT_VERSION, IOS_INNER_TUBE_BODY, IOS_OS_VERSION, IOS_USER_AGENT),
// No suitable model name was found for TVHTML5_SIMPLY_EMBEDDED_PLAYER. Use the model name of ANDROID.
TVHTML5_SIMPLY_EMBEDDED_PLAYER(85, ANDROID_DEVICE_MODEL, TVHTML5_SIMPLY_EMBEDDED_PLAYER_CLIENT_VERSION, TVHTML5_SIMPLY_EMBED_INNER_TUBE_BODY, TVHTML5_SIMPLY_EMBEDDED_PLAYER_USER_AGENT),
TVHTML5_SIMPLY_EMBEDDED_PLAYER(85, ANDROID_DEVICE_MODEL, TVHTML5_SIMPLY_EMBEDDED_PLAYER_CLIENT_VERSION, TVHTML5_SIMPLY_EMBED_INNER_TUBE_BODY, TVHTML5_SIMPLY_EMBEDDED_PLAYER_CLIENT_VERSION, TVHTML5_SIMPLY_EMBEDDED_PLAYER_USER_AGENT),
// No suitable model name was found for WEB. Use the model name of ANDROID.
WEB(1, ANDROID_DEVICE_MODEL, WEB_CLIENT_VERSION, WEB_INNER_TUBE_BODY, WEB_USER_AGENT);
WEB(1, ANDROID_DEVICE_MODEL, WEB_CLIENT_VERSION, WEB_INNER_TUBE_BODY, WEB_CLIENT_VERSION, WEB_USER_AGENT);

public final String friendlyName;
public final int id;
public final String model;
public final String version;
public final String innerTubeBody;
public final String osVersion;
public final String userAgent;

ClientType(int id, String model, String version,
String innerTubeBody, String userAgent) {
ClientType(int id, String model, String version, String innerTubeBody,
String osVersion, String userAgent) {
this.friendlyName = str("revanced_spoof_client_options_entry_" + name().toLowerCase());
this.id = id;
this.model = model;
this.version = version;
this.innerTubeBody = innerTubeBody;
this.osVersion = osVersion;
this.userAgent = userAgent;
}
}
Expand Down

0 comments on commit 37a814a

Please sign in to comment.