Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Client Spoof): Restore missing high qualities by spoofi…
Browse files Browse the repository at this point in the history
…ng the iOS client user agent (#668)

Co-authored-by: LisoUseInAIKyrios <[email protected]>
Co-authored-by: oSumAtrIX <[email protected]>
  • Loading branch information
3 people authored Jul 28, 2024
1 parent ab0093f commit fbf629f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import android.os.Build;
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.youtube.settings.Settings;
import org.chromium.net.ExperimentalUrlRequest;

@SuppressWarnings("unused")
public class SpoofClientPatch {
private static final boolean SPOOF_CLIENT_ENABLED = Settings.SPOOF_CLIENT.get();
private static final ClientType SPOOF_CLIENT_TYPE = Settings.SPOOF_CLIENT_USE_IOS.get() ? ClientType.IOS : ClientType.ANDROID_VR;
private static final boolean SPOOFING_TO_IOS = SPOOF_CLIENT_ENABLED && SPOOF_CLIENT_TYPE == ClientType.IOS;

/**
* Any unreachable ip address. Used to intentionally fail requests.
Expand Down Expand Up @@ -52,7 +54,7 @@ public static Uri blockGetWatchRequest(Uri playerRequestUri) {

/**
* Injection point.
*
* <p>
* Blocks /initplayback requests.
*/
public static String blockInitPlaybackRequest(String originalUrlString) {
Expand All @@ -78,33 +80,29 @@ public static String blockInitPlaybackRequest(String originalUrlString) {
* Injection point.
*/
public static int getClientTypeId(int originalClientTypeId) {
if (SPOOF_CLIENT_ENABLED) {
return SPOOF_CLIENT_TYPE.id;
}

return originalClientTypeId;
return SPOOF_CLIENT_ENABLED ? SPOOF_CLIENT_TYPE.id : originalClientTypeId;
}

/**
* Injection point.
*/
public static String getClientVersion(String originalClientVersion) {
if (SPOOF_CLIENT_ENABLED) {
return SPOOF_CLIENT_TYPE.version;
}

return originalClientVersion;
return SPOOF_CLIENT_ENABLED ? SPOOF_CLIENT_TYPE.version : originalClientVersion;
}

/**
* Injection point.
*/
public static String getClientModel(String originalClientModel) {
if (SPOOF_CLIENT_ENABLED) {
return SPOOF_CLIENT_TYPE.model;
}
return SPOOF_CLIENT_ENABLED ? SPOOF_CLIENT_TYPE.model : originalClientModel;
}

return originalClientModel;
/**
* Injection point.
* Fix video qualities missing, if spoofing to iOS by using the correct client OS version.
*/
public static String getOsVersion(String originalOsVersion) {
return SPOOFING_TO_IOS ? ClientType.IOS.osVersion : originalOsVersion;
}

/**
Expand All @@ -127,11 +125,23 @@ public static boolean isClientSpoofingEnabled() {
* Return true to force create the playback speed menu.
*/
public static boolean forceCreatePlaybackSpeedMenu(boolean original) {
if (SPOOF_CLIENT_ENABLED && SPOOF_CLIENT_TYPE == ClientType.IOS) {
return true;
return SPOOFING_TO_IOS || original;
}


/**
* Injection point.
* Fix video qualities missing, if spoofing to iOS by using the correct iOS user-agent.
*/
public static ExperimentalUrlRequest overrideUserAgent(ExperimentalUrlRequest.Builder builder, String url) {
if (SPOOFING_TO_IOS) {
String path = Uri.parse(url).getPath();
if (path != null && path.contains("player")) {
return builder.addHeader("User-Agent", ClientType.IOS.userAgent).build();
}
}

return original;
return builder.build();
}

/**
Expand All @@ -149,15 +159,25 @@ public static Uri overrideTrackingUrl(Uri trackingUrl) {

private enum ClientType {
// https://dumps.tadiphone.dev/dumps/oculus/eureka
ANDROID_VR(28, "Quest 3", "1.56.21"),
ANDROID_VR(28,
"Quest 3",
"1.56.21",
"12",
"com.google.android.apps.youtube.vr.oculus/1.56.21 (Linux; U; Android 12; GB) gzip"
),
// 11,4 = iPhone XS Max.
// 16,2 = iPhone 15 Pro Max.
// Since the 15 supports AV1 hardware decoding, only spoof that device if this
// Android device also has hardware decoding.
//
// Version number should be a valid iOS release.
// https://www.ipa4fun.com/history/185230
IOS(5, deviceHasAV1HardwareDecoding() ? "iPhone16,2" : "iPhone11,4", "19.10.7");
IOS(5,
deviceHasAV1HardwareDecoding() ? "iPhone16,2" : "iPhone11,4",
"19.10.7",
"17.5.1.21F90",
"com.google.ios.youtube/19.10.7 (iPhone; U; CPU iOS 17_5_1 like Mac OS X)"
);

/**
* YouTube
Expand All @@ -175,10 +195,22 @@ private enum ClientType {
*/
final String version;

ClientType(int id, String model, String version) {
/**
* Device OS version.
*/
final String osVersion;

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

ClientType(int id, String model, String version, String osVersion, String userAgent) {
this.id = id;
this.model = model;
this.version = version;
this.osVersion = osVersion;
this.userAgent = userAgent;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.chromium.net;

public abstract class ExperimentalUrlRequest {
public abstract class Builder {
public abstract ExperimentalUrlRequest.Builder addHeader(String name, String value);
public abstract ExperimentalUrlRequest build();
}
}

0 comments on commit fbf629f

Please sign in to comment.