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

Commit

Permalink
feat(YouTube - Spoof client): Add Show in Stats for nerds settings
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and anddea committed May 31, 2024
1 parent 3e2cf4b commit 6c5ff0c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static app.revanced.integrations.youtube.patches.misc.requests.LiveStreamRendererRequester.getLiveStreamRenderer;

import android.net.Uri;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -45,11 +46,16 @@ public class SpoofClientPatch {
private static final String UNREACHABLE_HOST_URI_STRING = "https://127.0.0.0";
private static final Uri UNREACHABLE_HOST_URI = Uri.parse(UNREACHABLE_HOST_URI_STRING);

/**
* Last spoofed client type.
*/
private static volatile ClientType lastSpoofedClientType;

/**
* Last video id loaded. Used to prevent reloading the same spec multiple times.
*/
@Nullable
private static volatile String lastPlayerResponseVideoId;
@NonNull
private static volatile String lastPlayerResponseVideoId = "";

@Nullable
private static volatile Future<LiveStreamRenderer> rendererFuture;
Expand Down Expand Up @@ -113,18 +119,22 @@ public static String blockInitPlaybackRequest(String originalUrlString) {

private static ClientType getSpoofClientType() {
if (isShortsOrClips) {
return Settings.SPOOF_CLIENT_SHORTS.get();
lastSpoofedClientType = Settings.SPOOF_CLIENT_SHORTS.get();
return lastSpoofedClientType;
}
LiveStreamRenderer renderer = getRenderer(false);
if (renderer != null) {
if (renderer.isLive) {
return Settings.SPOOF_CLIENT_LIVESTREAM.get();
lastSpoofedClientType = Settings.SPOOF_CLIENT_LIVESTREAM.get();
return lastSpoofedClientType;
}
if (!renderer.playabilityOk) {
return Settings.SPOOF_CLIENT_FALLBACK.get();
lastSpoofedClientType = Settings.SPOOF_CLIENT_FALLBACK.get();
return lastSpoofedClientType;
}
}
return Settings.SPOOF_CLIENT_GENERAL.get();
lastSpoofedClientType = Settings.SPOOF_CLIENT_GENERAL.get();
return lastSpoofedClientType;
}

/**
Expand Down Expand Up @@ -174,6 +184,23 @@ public static boolean enablePlayerGesture(boolean original) {
return SPOOF_CLIENT_ENABLED || original;
}

/**
* Injection point.
*/
public static String appendSpoofedClient(String videoFormat) {
try {
if (SPOOF_CLIENT_ENABLED && Settings.SPOOF_CLIENT_STATS_FOR_NERDS.get()
&& !TextUtils.isEmpty(videoFormat)) {
// Force LTR layout, to match the same LTR video time/length layout YouTube uses for all languages
return "\u202D" + videoFormat + String.format("\u2009(%s)", lastSpoofedClientType.friendlyName); // u202D = left to right override
}
} catch (Exception ex) {
Logger.printException(() -> "appendSpoofedClient failure", ex);
}

return videoFormat;
}

/**
* Injection point.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package app.revanced.integrations.youtube.patches.misc.requests;

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

import android.os.Build;

import org.json.JSONException;
Expand Down Expand Up @@ -372,6 +374,7 @@ public enum ClientType {
// 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);

public final String friendlyName;
public final int id;
public final String model;
public final String version;
Expand All @@ -380,6 +383,7 @@ public enum ClientType {

ClientType(int id, String model, String version,
String innerTubeBody, String userAgent) {
this.friendlyName = str("revanced_spoof_client_options_entry_" + name().toLowerCase());
this.id = id;
this.model = model;
this.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting DISABLE_QUIC_PROTOCOL = new BooleanSetting("revanced_disable_quic_protocol", FALSE, true);
public static final BooleanSetting SPOOF_FORMAT_STREAM_DATA = new BooleanSetting("revanced_spoof_format_stream_data", FALSE, true);
public static final BooleanSetting SPOOF_CLIENT = new BooleanSetting("revanced_spoof_client", FALSE, true);
public static final BooleanSetting SPOOF_CLIENT_STATS_FOR_NERDS = new BooleanSetting("revanced_spoof_client_stats_for_nerds", TRUE, parent(SPOOF_CLIENT));
public static final EnumSetting<ClientType> SPOOF_CLIENT_GENERAL = new EnumSetting<>("revanced_spoof_client_general",
ClientType.IOS);
public static final EnumSetting<ClientType> SPOOF_CLIENT_LIVESTREAM = new EnumSetting<>("revanced_spoof_client_livestream",
Expand Down

0 comments on commit 6c5ff0c

Please sign in to comment.