From 52b80a4821f12c2fd66df9adf3f381558ff32902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20Gia=20B=E1=BA=A3o?= <70064328+YT-Advanced@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:27:51 +0700 Subject: [PATCH 1/3] refactor(YouTube - Spoof Streaming Data): Remove `Force AVC` settings --- .../patches/misc/client/AppClient.java | 18 ++----- .../misc/client/DeviceHardwareSupport.java | 54 ------------------- .../extension/youtube/settings/Settings.java | 2 - .../video/playback/VideoPlaybackPatch.kt | 2 +- .../youtube/settings/host/values/strings.xml | 6 --- .../youtube/settings/xml/revanced_prefs.xml | 1 - 6 files changed, 5 insertions(+), 78 deletions(-) delete mode 100644 extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/DeviceHardwareSupport.java diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/AppClient.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/AppClient.java index 79f72f997a..6c84464f18 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/AppClient.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/AppClient.java @@ -24,7 +24,6 @@ public class AppClient { private static final String CLIENT_VERSION_IOS = "19.47.7"; private static final String DEVICE_MAKE_IOS = "Apple"; /** - * The device machine id for the iPhone XS Max (iPhone11,4), used to get 60fps. * The device machine id for the iPhone 16 Pro Max (iPhone17,2), used to get HDR with AV1 hardware decoding. * *

@@ -32,20 +31,11 @@ public class AppClient { * information. *

*/ - private static final String DEVICE_MODEL_IOS = DeviceHardwareSupport.allowAV1() - ? "iPhone17,2" - : "iPhone11,4"; + private static final String DEVICE_MODEL_IOS = "iPhone17,2" private static final String OS_NAME_IOS = "iOS"; - /** - * The minimum supported OS version for the iOS YouTube client is iOS 14.0. - * Using an invalid OS version will use the AVC codec. - */ - private static final String OS_VERSION_IOS = DeviceHardwareSupport.allowVP9() - ? "18.1.1.22B91" - : "13.7.17H35"; - private static final String USER_AGENT_VERSION_IOS = DeviceHardwareSupport.allowVP9() - ? "18_1_1" - : "13_7"; + private static final String OS_VERSION_IOS = "18.1.1.22B91" + private static final String USER_AGENT_VERSION_IOS = "18_1_1" + private static final String USER_AGENT_IOS = "com.google.ios.youtube/" + CLIENT_VERSION_IOS + "(" + diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/DeviceHardwareSupport.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/DeviceHardwareSupport.java deleted file mode 100644 index 91ffd5aae5..0000000000 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/client/DeviceHardwareSupport.java +++ /dev/null @@ -1,54 +0,0 @@ -package app.revanced.extension.youtube.patches.misc.client; - -import static app.revanced.extension.shared.utils.Utils.isSDKAbove; - -import android.media.MediaCodecInfo; -import android.media.MediaCodecList; - -import app.revanced.extension.shared.utils.Logger; -import app.revanced.extension.youtube.settings.Settings; - -public class DeviceHardwareSupport { - private static final boolean DEVICE_HAS_HARDWARE_DECODING_VP9; - private static final boolean DEVICE_HAS_HARDWARE_DECODING_AV1; - - static { - boolean vp9found = false; - boolean av1found = false; - MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS); - final boolean deviceIsAndroidTenOrLater = isSDKAbove(29); - - for (MediaCodecInfo codecInfo : codecList.getCodecInfos()) { - final boolean isHardwareAccelerated = deviceIsAndroidTenOrLater - ? codecInfo.isHardwareAccelerated() - : !codecInfo.getName().startsWith("OMX.google"); // Software decoder. - if (isHardwareAccelerated && !codecInfo.isEncoder()) { - for (String type : codecInfo.getSupportedTypes()) { - if (type.equalsIgnoreCase("video/x-vnd.on2.vp9")) { - vp9found = true; - } else if (type.equalsIgnoreCase("video/av01")) { - av1found = true; - } - } - } - } - - DEVICE_HAS_HARDWARE_DECODING_VP9 = vp9found; - DEVICE_HAS_HARDWARE_DECODING_AV1 = av1found; - - Logger.printDebug(() -> DEVICE_HAS_HARDWARE_DECODING_AV1 - ? "Device supports AV1 hardware decoding\n" - : "Device does not support AV1 hardware decoding\n" - + (DEVICE_HAS_HARDWARE_DECODING_VP9 - ? "Device supports VP9 hardware decoding" - : "Device does not support VP9 hardware decoding")); - } - - public static boolean allowVP9() { - return DEVICE_HAS_HARDWARE_DECODING_VP9 && !Settings.SPOOF_STREAMING_DATA_IOS_FORCE_AVC.get(); - } - - public static boolean allowAV1() { - return allowVP9() && DEVICE_HAS_HARDWARE_DECODING_AV1; - } -} diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java index bdb78aaa51..5cd1d3d6a4 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -545,8 +545,6 @@ public class Settings extends BaseSettings { // PreferenceScreen: Miscellaneous - Spoof streaming data // The order of the settings should not be changed otherwise the app may crash 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 BooleanSetting SPOOF_STREAMING_DATA_IOS_FORCE_AVC = new BooleanSetting("revanced_spoof_streaming_data_ios_force_avc", FALSE, true, - "revanced_spoof_streaming_data_ios_force_avc_user_dialog_message", new SpoofStreamingDataPatch.iOSAvailability()); public static final BooleanSetting SPOOF_STREAMING_DATA_IOS_SKIP_LIVESTREAM_PLAYBACK = new BooleanSetting("revanced_spoof_streaming_data_ios_skip_livestream_playback", TRUE, true, new SpoofStreamingDataPatch.iOSAvailability()); public static final EnumSetting SPOOF_STREAMING_DATA_TYPE = new EnumSetting<>("revanced_spoof_streaming_data_type", ClientType.IOS, true, parent(SPOOF_STREAMING_DATA)); public static final BooleanSetting SPOOF_STREAMING_DATA_STATS_FOR_NERDS = new BooleanSetting("revanced_spoof_streaming_data_stats_for_nerds", TRUE, parent(SPOOF_STREAMING_DATA)); diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt index d081d3bde0..e090c58ecf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt @@ -315,7 +315,7 @@ val videoPlaybackPatch = bytecodePatch( // region patch for disable VP9 codec - vp9CapabilityFingerprint.methodOrThrow().apply { + vp9CapabilityFingerprint.methodOrThrow(hdrCapabilityFingerprint).apply { addInstructionsWithLabels( 0, """ invoke-static {}, $EXTENSION_VP9_CODEC_CLASS_DESCRIPTOR->disableVP9Codec()Z diff --git a/patches/src/main/resources/youtube/settings/host/values/strings.xml b/patches/src/main/resources/youtube/settings/host/values/strings.xml index e73453db69..55974d3b0e 100644 --- a/patches/src/main/resources/youtube/settings/host/values/strings.xml +++ b/patches/src/main/resources/youtube/settings/host/values/strings.xml @@ -1846,12 +1846,6 @@ Tap on the continue button and disable battery optimizations." • Stable volume is not available." "• Audio track menu is missing. • Stable volume is not available." - Force iOS AVC (H.264) - iOS video codec is AVC (H.264). - iOS video codec is AVC (H.264), VP9, or AV1. - "Enabling this might improve battery life and fix playback stuttering. - -AVC (H.264) has a maximum resolution of 1080p, and video playback will use more internet data than VP9 or AV1." Skip iOS livestream playback iOS client is not used for livestream playback. iOS client is used for livestream playback. diff --git a/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml index 46657daca5..6d949e3285 100644 --- a/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml +++ b/patches/src/main/resources/youtube/settings/xml/revanced_prefs.xml @@ -735,7 +735,6 @@ - SETTINGS: SPOOF_STREAMING_DATA --> From 77bcf85b9a5bb089e814a2dc97cd85ebb5befcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20Gia=20B=E1=BA=A3o?= <70064328+YT-Advanced@users.noreply.github.com> Date: Fri, 13 Dec 2024 21:04:39 +0700 Subject: [PATCH 2/3] Add missing header --- .../extension/youtube/patches/misc/requests/PlayerRoutes.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/requests/PlayerRoutes.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/requests/PlayerRoutes.java index 22032119ae..5a7f87c94d 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/requests/PlayerRoutes.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/misc/requests/PlayerRoutes.java @@ -92,6 +92,8 @@ static HttpURLConnection getPlayerResponseConnectionFromRoute(Route.CompiledRout connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("User-Agent", clientType.userAgent); + connection.setRequestProperty("X-YouTube-Client-Name", clientType.id); + connection.setRequestProperty("X-YouTube-Client-Version", clientType.clientVersion); connection.setUseCaches(false); connection.setDoOutput(true); @@ -100,4 +102,4 @@ static HttpURLConnection getPlayerResponseConnectionFromRoute(Route.CompiledRout connection.setReadTimeout(CONNECTION_TIMEOUT_MILLISECONDS); return connection; } -} \ No newline at end of file +} From 2dc82b4c29b4cd46607c77c9e1b0f6ebb5c5b13c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20Gia=20B=E1=BA=A3o?= <70064328+YT-Advanced@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:39:03 +0700 Subject: [PATCH 3/3] Apply code suggestion --- .../patches/youtube/video/playback/VideoPlaybackPatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt index e090c58ecf..d081d3bde0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt @@ -315,7 +315,7 @@ val videoPlaybackPatch = bytecodePatch( // region patch for disable VP9 codec - vp9CapabilityFingerprint.methodOrThrow(hdrCapabilityFingerprint).apply { + vp9CapabilityFingerprint.methodOrThrow().apply { addInstructionsWithLabels( 0, """ invoke-static {}, $EXTENSION_VP9_CODEC_CLASS_DESCRIPTOR->disableVP9Codec()Z