Skip to content

Commit

Permalink
feat(YouTube Music): Add Spoof video streams patch to fix playback (#…
Browse files Browse the repository at this point in the history
…4065)

Co-authored-by: LisoUseInAIKyrios <[email protected]>
  • Loading branch information
oSumAtrIX and LisoUseInAIKyrios authored Dec 8, 2024
1 parent 6a44e75 commit cf3116a
Show file tree
Hide file tree
Showing 19 changed files with 543 additions and 484 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package app.revanced.extension.shared.settings;

import app.revanced.extension.shared.spoof.ClientType;
import app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static app.revanced.extension.shared.settings.Setting.parent;

/**
* Settings shared across multiple apps.
*
* <p>
* To ensure this class is loaded when the UI is created, app specific setting bundles should extend
* or reference this class.
*/
Expand All @@ -16,4 +19,10 @@ public class BaseSettings {
public static final BooleanSetting DEBUG_TOAST_ON_ERROR = new BooleanSetting("revanced_debug_toast_on_error", TRUE, "revanced_debug_toast_on_error_user_dialog_message");

public static final IntegerSetting CHECK_ENVIRONMENT_WARNINGS_ISSUED = new IntegerSetting("revanced_check_environment_warnings_issued", 0, true, false);

public static final BooleanSetting SPOOF_VIDEO_STREAMS = new BooleanSetting("revanced_spoof_video_streams", TRUE, true, "revanced_spoof_video_streams_user_dialog_message");
public static final BooleanSetting SPOOF_VIDEO_STREAMS_IOS_FORCE_AVC = new BooleanSetting("revanced_spoof_video_streams_ios_force_avc", FALSE, true,
"revanced_spoof_video_streams_ios_force_avc_user_dialog_message", new SpoofVideoStreamsPatch.ForceiOSAVCAvailability());
public static final EnumSetting<ClientType> SPOOF_VIDEO_STREAMS_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_video_streams_client", ClientType.ANDROID_VR, true, parent(SPOOF_VIDEO_STREAMS));

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.revanced.extension.youtube.patches.spoof;
package app.revanced.extension.shared.spoof;

import static app.revanced.extension.youtube.patches.spoof.DeviceHardwareSupport.allowAV1;
import static app.revanced.extension.youtube.patches.spoof.DeviceHardwareSupport.allowVP9;
import static app.revanced.extension.shared.spoof.DeviceHardwareSupport.allowAV1;
import static app.revanced.extension.shared.spoof.DeviceHardwareSupport.allowVP9;

import android.os.Build;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package app.revanced.extension.youtube.patches.spoof;
package app.revanced.extension.shared.spoof;

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

import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.shared.settings.BaseSettings;

public class DeviceHardwareSupport {
public static final boolean DEVICE_HAS_HARDWARE_DECODING_VP9;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class DeviceHardwareSupport {
}

public static boolean allowVP9() {
return DEVICE_HAS_HARDWARE_DECODING_VP9 && !Settings.SPOOF_VIDEO_STREAMS_IOS_FORCE_AVC.get();
return DEVICE_HAS_HARDWARE_DECODING_VP9 && !BaseSettings.SPOOF_VIDEO_STREAMS_IOS_FORCE_AVC.get();
}

public static boolean allowAV1() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.extension.youtube.patches.spoof;
package app.revanced.extension.shared.spoof;

import android.net.Uri;

Expand All @@ -12,20 +12,12 @@
import app.revanced.extension.shared.Utils;
import app.revanced.extension.shared.settings.BaseSettings;
import app.revanced.extension.shared.settings.Setting;
import app.revanced.extension.youtube.patches.spoof.requests.StreamingDataRequest;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.shared.spoof.requests.StreamingDataRequest;
import app.revanced.extension.shared.settings.BaseSettings;

@SuppressWarnings("unused")
public class SpoofVideoStreamsPatch {
public static final class ForceiOSAVCAvailability implements Setting.Availability {
@Override
public boolean isAvailable() {
return Settings.SPOOF_VIDEO_STREAMS.get() && Settings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS;
}
}

private static final boolean SPOOF_STREAMING_DATA = Settings.SPOOF_VIDEO_STREAMS.get();

private static final boolean SPOOF_STREAMING_DATA = BaseSettings.SPOOF_VIDEO_STREAMS.get();
/**
* Any unreachable ip address. Used to intentionally fail requests.
*/
Expand Down Expand Up @@ -165,4 +157,11 @@ public static byte[] removeVideoPlaybackPostBody(Uri uri, int method, byte[] pos

return postData;
}

public static final class ForceiOSAVCAvailability implements Setting.Availability {
@Override
public boolean isAvailable() {
return BaseSettings.SPOOF_VIDEO_STREAMS.get() && BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.extension.youtube.patches.spoof.requests;
package app.revanced.extension.shared.spoof.requests;

import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -10,7 +10,7 @@
import app.revanced.extension.shared.Utils;
import app.revanced.extension.shared.requests.Requester;
import app.revanced.extension.shared.requests.Route;
import app.revanced.extension.youtube.patches.spoof.ClientType;
import app.revanced.extension.shared.spoof.ClientType;

final class PlayerRoutes {
static final Route.CompiledRoute GET_STREAMING_DATA = new Route(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.revanced.extension.youtube.patches.spoof.requests;
package app.revanced.extension.shared.spoof.requests;

import static app.revanced.extension.youtube.patches.spoof.requests.PlayerRoutes.GET_STREAMING_DATA;
import static app.revanced.extension.shared.spoof.requests.PlayerRoutes.GET_STREAMING_DATA;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -22,8 +22,7 @@
import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.shared.settings.BaseSettings;
import app.revanced.extension.youtube.patches.spoof.ClientType;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.shared.spoof.ClientType;

/**
* Video streaming data. Fetching is tied to the behavior YT uses,
Expand Down Expand Up @@ -70,7 +69,7 @@ protected boolean removeEldestEntry(Entry eldest) {

static {
ClientType[] allClientTypes = ClientType.values();
ClientType preferredClient = Settings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get();
ClientType preferredClient = BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get();

CLIENT_ORDER_TO_USE = new ClientType[allClientTypes.length];
CLIENT_ORDER_TO_USE[0] = preferredClient;
Expand Down

This file was deleted.

Loading

0 comments on commit cf3116a

Please sign in to comment.