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

Commit

Permalink
fix: Remove client type spoofing and use only stream replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Aug 26, 2024
1 parent 9b1e84b commit 0817016
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.shared.settings.Setting;
import app.revanced.integrations.youtube.patches.BackgroundPlaybackPatch;
import app.revanced.integrations.youtube.patches.spoof.requests.StreamingDataRequester;
import app.revanced.integrations.youtube.settings.Settings;

@SuppressWarnings("unused")
public class SpoofClientPatch {
private static final boolean SPOOF_CLIENT = Settings.SPOOF_CLIENT.get();
private static final SpoofClientStrategy SPOOF_STRATEGY = Settings.SPOOF_CLIENT_STRATEGY.get();
@Nullable
private static final ClientType SPOOF_CLIENT_TYPE = SPOOF_CLIENT ? SPOOF_STRATEGY.clientType : null;
private static final boolean SPOOF_STREAM = SPOOF_CLIENT && SPOOF_STRATEGY == SpoofClientStrategy.REPLACE_STREAMS;

/**
* Any unreachable ip address. Used to intentionally fail requests.
Expand Down Expand Up @@ -88,70 +82,8 @@ public static String blockInitPlaybackRequest(String originalUrlString) {
/**
* Injection point.
*/
public static boolean isClientTypeSpoofingEnabled() {
return SPOOF_CLIENT_TYPE != null;
}

/**
* Injection point.
*/
public static boolean isSpoofStreamEnabled() {
return SPOOF_STREAM;
}

/**
* Injection point.
*/
public static int getClientTypeId(int originalClientTypeId) {
return SPOOF_CLIENT_TYPE != null ? SPOOF_CLIENT_TYPE.id : originalClientTypeId;
}

/**
* Injection point.
*/
public static String getClientVersion(String originalClientVersion) {
return SPOOF_CLIENT_TYPE != null ? SPOOF_CLIENT_TYPE.appVersion : originalClientVersion;
}

/**
* Injection point.
*/
public static String getClientModel(String originalClientModel) {
return SPOOF_CLIENT_TYPE != null ? SPOOF_CLIENT_TYPE.model : 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 SPOOF_CLIENT_TYPE != null ? SPOOF_CLIENT_TYPE.osVersion : originalOsVersion;
}

/**
* Injection point.
*/
public static boolean enablePlayerGesture(boolean original) {
return SPOOF_CLIENT && SPOOF_STRATEGY.enablePlayerGesture || original;
}

/**
* Injection point.
* When spoofing the client to iOS, the playback speed menu is missing from the player response.
* Return true to force create the playback speed menu.
*/
public static boolean forceCreatePlaybackSpeedMenu(boolean original) {
return SPOOF_CLIENT && SPOOF_STRATEGY.forceCreatePlaybackSpeedMenu || original;
}

/**
* Injection point.
* When spoofing the client to iOS, background audio only playback of livestreams fails.
* Return true to force enable audio background play.
*/
public static boolean overrideBackgroundAudioPlayback() {
return SPOOF_CLIENT && SPOOF_STRATEGY.overrideBackgroundAudioPlayback
&& BackgroundPlaybackPatch.playbackIsNotShort();
public static boolean isSpoofingEnabled() {
return SPOOF_CLIENT;
}

/**
Expand All @@ -163,14 +95,8 @@ public static ExperimentalUrlRequest overrideUserAgent(ExperimentalUrlRequest.Bu
Uri uri = Uri.parse(url);
String path = uri.getPath();
if (path != null && path.contains("player") && !path.contains("heartbeat")) {
if (SPOOF_CLIENT_TYPE != null) {
Logger.printDebug(() -> "Overriding user agent for /player call");
builder.addHeader("User-Agent", SPOOF_CLIENT_TYPE.userAgent);
} else {
// Spoof stream.
String videoId = uri.getQueryParameter("id");
currentVideoStream = StreamingDataRequester.fetch(videoId, playerHeaders);
}
String videoId = uri.getQueryParameter("id");
currentVideoStream = StreamingDataRequester.fetch(videoId, playerHeaders);
}
}

Expand All @@ -184,7 +110,7 @@ public static ExperimentalUrlRequest overrideUserAgent(ExperimentalUrlRequest.Bu
*/
@Nullable
public static ByteBuffer getStreamingData(String videoId) {
if (SPOOF_STREAM) {
if (SPOOF_CLIENT) {
try {
Utils.verifyOffMainThread();

Expand Down Expand Up @@ -217,7 +143,7 @@ public static ByteBuffer getStreamingData(String videoId) {
* Called after {@link #getStreamingData(String)}.
*/
public static byte[] removeVideoPlaybackPostBody(Uri uri, int method, byte[] postData) {
if (SPOOF_STREAM) {
if (SPOOF_CLIENT) {
try {
final int methodPost = 2;
if (method == methodPost) {
Expand All @@ -235,44 +161,4 @@ public static byte[] removeVideoPlaybackPostBody(Uri uri, int method, byte[] pos

return postData;
}

public enum SpoofClientStrategy {
REPLACE_STREAMS(null,
false,
false,
false),
CLIENT_IOS(ClientType.IOS,
true,
true,
true),
CLIENT_ANDROID_VR(ClientType.ANDROID_VR,
false,
false,
false);

private final ClientType clientType;
private final boolean forceCreatePlaybackSpeedMenu;
private final boolean overrideBackgroundAudioPlayback;
private final boolean enablePlayerGesture;

SpoofClientStrategy(ClientType clientType,
boolean forceCreatePlaybackSpeedMenu,
boolean overrideBackgroundAudioPlayback,
boolean enablePlayerGesture) {
this.clientType = clientType;
this.forceCreatePlaybackSpeedMenu = forceCreatePlaybackSpeedMenu;
this.overrideBackgroundAudioPlayback = overrideBackgroundAudioPlayback;
this.enablePlayerGesture = enablePlayerGesture;
}
}

public static final class ForceAVCAvailability implements Setting.Availability {
@Override
public boolean isAvailable() {
if (!Settings.SPOOF_CLIENT.get()) return false;

SpoofClientStrategy strategy = Settings.SPOOF_CLIENT_STRATEGY.get();
return strategy == SpoofClientStrategy.CLIENT_IOS || strategy == SpoofClientStrategy.REPLACE_STREAMS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static app.revanced.integrations.youtube.patches.spoof.requests.StoryboardRendererRequester.getStoryboardRenderer;

/** @noinspection unused*/
@Deprecated
@Deprecated // Patch is obsolete and no longer works.
public class SpoofSignaturePatch {
/**
* Parameter (also used by
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package app.revanced.integrations.youtube.patches.spoof.requests;

import app.revanced.integrations.youtube.patches.spoof.ClientType;
import app.revanced.integrations.youtube.requests.Requester;
import app.revanced.integrations.youtube.requests.Route;
import app.revanced.integrations.shared.Logger;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.HttpURLConnection;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.youtube.patches.spoof.ClientType;
import app.revanced.integrations.youtube.requests.Requester;
import app.revanced.integrations.youtube.requests.Route;

final class PlayerRoutes {
private static final String YT_API_URL = "https://youtubei.googleapis.com/youtubei/v1/";

@Deprecated
static final Route.CompiledRoute GET_STORYBOARD_SPEC_RENDERER = new Route(
Route.Method.POST,
"player" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static app.revanced.integrations.youtube.patches.MiniplayerPatch.MiniplayerType;
import static app.revanced.integrations.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_1;
import static app.revanced.integrations.youtube.patches.MiniplayerPatch.MiniplayerType.MODERN_3;
import static app.revanced.integrations.youtube.patches.spoof.SpoofClientPatch.SpoofClientStrategy;
import static app.revanced.integrations.youtube.sponsorblock.objects.CategoryBehaviour.*;

import java.util.Arrays;
Expand All @@ -21,7 +20,6 @@
import app.revanced.integrations.youtube.patches.AlternativeThumbnailsPatch.ThumbnailOption;
import app.revanced.integrations.youtube.patches.AlternativeThumbnailsPatch.ThumbnailStillTime;
import app.revanced.integrations.youtube.patches.spoof.SpoofAppVersionPatch;
import app.revanced.integrations.youtube.patches.spoof.SpoofClientPatch;
import app.revanced.integrations.youtube.sponsorblock.SponsorBlockSettings;

@SuppressWarnings("deprecation")
Expand Down Expand Up @@ -257,8 +255,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting ANNOUNCEMENTS = new BooleanSetting("revanced_announcements", TRUE);
public static final BooleanSetting SPOOF_CLIENT = new BooleanSetting("revanced_spoof_client", TRUE, true,"revanced_spoof_client_user_dialog_message");
public static final BooleanSetting SPOOF_CLIENT_FORCE_AVC = new BooleanSetting("revanced_spoof_client_force_avc", FALSE, true,
"revanced_spoof_client_force_avc_user_dialog_message", new SpoofClientPatch.ForceAVCAvailability());
public static final EnumSetting<SpoofClientStrategy> SPOOF_CLIENT_STRATEGY = new EnumSetting<>("revanced_spoof_client_strategy", SpoofClientStrategy.REPLACE_STREAMS, true, parent(SPOOF_CLIENT));
"revanced_spoof_client_force_avc_user_dialog_message", parent(SPOOF_CLIENT));
@Deprecated
public static final StringSetting DEPRECATED_ANNOUNCEMENT_LAST_HASH = new StringSetting("revanced_announcement_last_hash", "");
public static final IntegerSetting ANNOUNCEMENT_LAST_ID = new IntegerSetting("revanced_announcement_last_id", -1);
Expand Down

0 comments on commit 0817016

Please sign in to comment.