Skip to content

Commit

Permalink
feat(YouTube Music - Spoof client): Limit support version to 7.16.53 …
Browse files Browse the repository at this point in the history
…and change default client preset
  • Loading branch information
inotia00 authored and anddea committed Dec 23, 2024
1 parent ba4cd15 commit 20beb64
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import app.revanced.extension.music.patches.misc.client.AppClient.ClientType;
import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.shared.patches.BlockRequestPatch;

@SuppressWarnings("unused")
public class SpoofClientPatch extends BlockRequestPatch {
public class SpoofClientPatch {
private static final ClientType CLIENT_TYPE = Settings.SPOOF_CLIENT_TYPE.get();
public static final boolean SPOOF_CLIENT = Settings.SPOOF_CLIENT.get();

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

import android.os.Build;

import app.revanced.extension.music.settings.Settings;

public class AppClient {
private static final String CLIENT_VERSION_ANDROID_MUSIC = Settings.SPOOF_CLIENT_LEGACY.get()
? "4.27.53" // Audio codec is MP4A.
: "5.29.53"; // Audio codec is OPUS.

// Audio codec is MP4A.
private static final String CLIENT_VERSION_ANDROID_MUSIC_4_27 = "4.27.53";

// Audio codec is OPUS.
private static final String CLIENT_VERSION_ANDROID_MUSIC_5_29 = "5.29.53";

private static final String PACKAGE_NAME_ANDROID_MUSIC = "com.google.android.apps.youtube.music";
private static final String DEVICE_MODEL_ANDROID_MUSIC = Build.MODEL;
private static final String OS_VERSION_ANDROID_MUSIC = Build.VERSION.RELEASE;
private static final String USER_AGENT_ANDROID_MUSIC = "com.google.android.apps.youtube.music/" +
CLIENT_VERSION_ANDROID_MUSIC +
" (Linux; U; Android " +
OS_VERSION_ANDROID_MUSIC +
"; GB) gzip";

private static final String CLIENT_VERSION_IOS_MUSIC = Settings.SPOOF_CLIENT_LEGACY.get()
? "4.27" // Audio codec is MP4A.
: "7.31.2"; // Audio codec is OPUS.

// Audio codec is MP4A.
private static final String CLIENT_VERSION_IOS_MUSIC_6_21 = "6.21";

// Audio codec is OPUS.
private static final String CLIENT_VERSION_IOS_MUSIC_7_04 = "7.04";

private static final String PACKAGE_NAME_IOS_MUSIC = "com.google.ios.youtubemusic";
private static final String DEVICE_MODEL_IOS_MUSIC = "iPhone14,3";
private static final String OS_VERSION_IOS_MUSIC = "15.7.1.19H117";
private static final String USER_AGENT_VERSION_IOS_MUSIC = "15_7_1";
private static final String USER_AGENT_IOS_MUSIC = "com.google.ios.youtubemusic/" +
CLIENT_VERSION_IOS_MUSIC +
"(" +
DEVICE_MODEL_IOS_MUSIC +
"; U; CPU iOS " +
USER_AGENT_VERSION_IOS_MUSIC +
" like Mac OS X)";

private AppClient() {
}

private static String androidUserAgent(String clientVersion) {
return PACKAGE_NAME_ANDROID_MUSIC +
"/" +
clientVersion +
" (Linux; U; Android " +
OS_VERSION_ANDROID_MUSIC +
"; GB) gzip";
}

private static String iOSUserAgent(String clientVersion) {
return PACKAGE_NAME_IOS_MUSIC +
"/" +
clientVersion +
"(" +
DEVICE_MODEL_IOS_MUSIC +
"; U; CPU iOS " +
USER_AGENT_VERSION_IOS_MUSIC +
" like Mac OS X)";
}

public enum ClientType {
ANDROID_MUSIC(21,
Build.MODEL,
ANDROID_MUSIC_4_27(21,
DEVICE_MODEL_ANDROID_MUSIC,
OS_VERSION_ANDROID_MUSIC,
androidUserAgent(CLIENT_VERSION_ANDROID_MUSIC_4_27),
CLIENT_VERSION_ANDROID_MUSIC_4_27
),
ANDROID_MUSIC_5_29(21,
DEVICE_MODEL_ANDROID_MUSIC,
OS_VERSION_ANDROID_MUSIC,
USER_AGENT_ANDROID_MUSIC,
CLIENT_VERSION_ANDROID_MUSIC
androidUserAgent(CLIENT_VERSION_ANDROID_MUSIC_5_29),
CLIENT_VERSION_ANDROID_MUSIC_5_29
),
IOS_MUSIC_6_21(
26,
DEVICE_MODEL_IOS_MUSIC,
OS_VERSION_IOS_MUSIC,
iOSUserAgent(CLIENT_VERSION_IOS_MUSIC_6_21),
CLIENT_VERSION_IOS_MUSIC_6_21
),
IOS_MUSIC(
IOS_MUSIC_7_04(
26,
DEVICE_MODEL_IOS_MUSIC,
OS_VERSION_IOS_MUSIC,
USER_AGENT_IOS_MUSIC,
CLIENT_VERSION_IOS_MUSIC
iOSUserAgent(CLIENT_VERSION_IOS_MUSIC_7_04),
CLIENT_VERSION_IOS_MUSIC_7_04
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public class Settings extends BaseSettings {
public static final BooleanSetting DISABLE_DRC_AUDIO = new BooleanSetting("revanced_disable_drc_audio", FALSE, true);
public static final BooleanSetting ENABLE_OPUS_CODEC = new BooleanSetting("revanced_enable_opus_codec", FALSE, true);
public static final BooleanSetting SETTINGS_IMPORT_EXPORT = new BooleanSetting("revanced_extended_settings_import_export", FALSE, false);
public static final BooleanSetting SPOOF_CLIENT_LEGACY = new BooleanSetting("revanced_spoof_client_legacy", FALSE, true);
public static final EnumSetting<ClientType> SPOOF_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_client_type", ClientType.ANDROID_MUSIC, true);
public static final BooleanSetting SPOOF_CLIENT = new BooleanSetting("revanced_spoof_client", FALSE, true);
public static final EnumSetting<ClientType> SPOOF_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_client_type", ClientType.IOS_MUSIC_6_21, true);


// PreferenceScreen: Return YouTube Dislike
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ public static ClientType SpoofStreamingDataDefaultClient() {
return ClientType.IOS;
}

public static boolean SpoofClient() {
// Replace this with true If the Spoof client patch succeeds
return false;
}

public static boolean SpoofStreamingData() {
// Replace this with true If the Spoof streaming data patch succeeds
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public class BaseSettings {
public static final EnumSetting<DisplayFormat> RETURN_YOUTUBE_USERNAME_DISPLAY_FORMAT = new EnumSetting<>("revanced_return_youtube_username_display_format", DisplayFormat.USERNAME_ONLY, true);
public static final StringSetting RETURN_YOUTUBE_USERNAME_YOUTUBE_DATA_API_V3_DEVELOPER_KEY = new StringSetting("revanced_return_youtube_username_youtube_data_api_v3_developer_key", "", true, false);

// Used only in YouTube Music.
// Moved to a shared class to prevent YouTube from accessing YouTube Music's extension classes.
public static final BooleanSetting SPOOF_CLIENT = new BooleanSetting("revanced_spoof_client", FALSE, true);

public static final BooleanSetting SPOOF_STREAMING_DATA = new BooleanSetting("revanced_spoof_streaming_data", TRUE, true, "revanced_spoof_streaming_data_user_dialog_message");
public static final EnumSetting<ClientType> SPOOF_STREAMING_DATA_TYPE = new EnumSetting<>("revanced_spoof_streaming_data_type", SpoofStreamingDataDefaultClient(), true);
public static final BooleanSetting SPOOF_STREAMING_DATA_SYNC_VIDEO_LENGTH = new BooleanSetting("revanced_spoof_streaming_data_sync_video_length", TRUE, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.instructions
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patches.music.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.music.utils.compatibility.Constants
import app.revanced.patches.music.utils.extension.Constants.MISC_PATH
import app.revanced.patches.music.utils.patch.PatchList.SPOOF_CLIENT
import app.revanced.patches.music.utils.playbackSpeedBottomSheetFingerprint
import app.revanced.patches.music.utils.playservice.is_7_25_or_greater
import app.revanced.patches.music.utils.playservice.versionCheckPatch
import app.revanced.patches.music.utils.settings.CategoryType
import app.revanced.patches.music.utils.settings.ResourceUtils.updatePatchStatus
import app.revanced.patches.music.utils.settings.addPreferenceWithIntent
import app.revanced.patches.music.utils.settings.addSwitchPreference
import app.revanced.patches.music.utils.settings.settingsPatch
import app.revanced.patches.shared.blockrequest.blockRequestPatch
import app.revanced.patches.shared.createPlayerRequestBodyWithModelFingerprint
import app.revanced.patches.shared.extension.Constants.PATCHES_PATH
import app.revanced.patches.shared.indexOfModelInstruction
import app.revanced.util.findMethodOrThrow
import app.revanced.util.Utils.printWarn
import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.fingerprint.mutableClassOrThrow
Expand Down Expand Up @@ -53,14 +52,26 @@ val spoofClientPatch = bytecodePatch(
SPOOF_CLIENT.summary,
false,
) {
compatibleWith(
Constants.YOUTUBE_MUSIC_PACKAGE_NAME(
"6.20.51",
"6.29.59",
"6.42.55",
"6.51.53",
"7.16.53",
),
)

dependsOn(
settingsPatch,
blockRequestPatch
versionCheckPatch,
)

compatibleWith(COMPATIBLE_PACKAGE)

execute {
if (is_7_25_or_greater) {
printWarn("\"${SPOOF_CLIENT.title}\" is not supported in this version. Use YouTube Music 7.24.51 or earlier.")
return@execute
}

// region Get field references to be used below.

Expand Down Expand Up @@ -262,24 +273,11 @@ val spoofClientPatch = bytecodePatch(

// endregion

findMethodOrThrow("$PATCHES_PATH/PatchStatus;") {
name == "SpoofClient"
}.replaceInstruction(
0,
"const/4 v0, 0x1"
)

addSwitchPreference(
CategoryType.MISC,
"revanced_spoof_client",
"false"
)
addSwitchPreference(
CategoryType.MISC,
"revanced_spoof_client_legacy",
"false",
"revanced_spoof_client"
)
addPreferenceWithIntent(
CategoryType.MISC,
"revanced_spoof_client_type",
Expand Down
10 changes: 6 additions & 4 deletions patches/src/main/resources/music/settings/host/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
<item>4.27.53</item>
</string-array>
<string-array name="revanced_spoof_client_type_entries">
<item>@string/revanced_spoof_client_type_entry_android_music</item>
<item>@string/revanced_spoof_client_type_entry_ios_music</item>
<item>@string/revanced_spoof_client_type_entry_ios_music_6_21</item>
<item>@string/revanced_spoof_client_type_entry_android_music_5_29</item>
<item>@string/revanced_spoof_client_type_entry_android_music_4_27</item>
</string-array>
<string-array name="revanced_spoof_client_type_entry_values">
<item>ANDROID_MUSIC</item>
<item>IOS_MUSIC</item>
<item>IOS_MUSIC_6_21</item>
<item>ANDROID_MUSIC_5_29</item>
<item>ANDROID_MUSIC_4_27</item>
</string-array>
<string-array name="revanced_spoof_streaming_data_type_entries">
<item>@string/revanced_spoof_streaming_data_type_entry_android_vr</item>
Expand Down

0 comments on commit 20beb64

Please sign in to comment.