diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/BaseSettings.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/BaseSettings.java index ad1741d9d9..4669e999a1 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/BaseSettings.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/settings/BaseSettings.java @@ -22,9 +22,9 @@ public class BaseSettings { 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 EnumSetting SPOOF_VIDEO_STREAMS_LANGUAGE = new EnumSetting<>("revanced_spoof_video_streams_language", AudioStreamLanguage.DEFAULT, new SpoofiOSAvailability()); + public static final EnumSetting SPOOF_VIDEO_STREAMS_LANGUAGE = new EnumSetting<>("revanced_spoof_video_streams_language", AudioStreamLanguage.DEFAULT, parent(SPOOF_VIDEO_STREAMS)); 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 SpoofiOSAvailability()); - public static final EnumSetting SPOOF_VIDEO_STREAMS_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_video_streams_client", ClientType.ANDROID_VR, true, parent(SPOOF_VIDEO_STREAMS)); + public static final EnumSetting SPOOF_VIDEO_STREAMS_CLIENT_TYPE = new EnumSetting<>("revanced_spoof_video_streams_client_type", ClientType.IOS, true, parent(SPOOF_VIDEO_STREAMS)); } diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java index b29dce4318..032d420ec4 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/ClientType.java @@ -16,8 +16,8 @@ public enum ClientType { "com.google.android.apps.youtube.vr.oculus/1.56.21 (Linux; U; Android 12; GB) gzip", "32", // Android 12.1 "1.56.21", - true, - false), + true + ), // Specific for kids videos. IOS(5, "IOS", @@ -39,8 +39,7 @@ public enum ClientType { // but 17.40 is the last version that supports iOS 13. ? "17.40.5" : "19.47.7", - false, - true + false ); private static boolean forceAVC() { @@ -87,11 +86,6 @@ private static boolean forceAVC() { */ public final boolean canLogin; - /** - * If a language code should be used. - */ - public final boolean useLanguageCode; - ClientType(int id, String clientName, String deviceModel, @@ -99,8 +93,7 @@ private static boolean forceAVC() { String userAgent, @Nullable String androidSdkVersion, String clientVersion, - boolean canLogin, - boolean useLanguageCode) { + boolean canLogin) { this.id = id; this.clientName = clientName; this.deviceModel = deviceModel; @@ -109,6 +102,5 @@ private static boolean forceAVC() { this.androidSdkVersion = androidSdkVersion; this.clientVersion = clientVersion; this.canLogin = canLogin; - this.useLanguageCode = useLanguageCode; } } diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java index 8e480c40ee..fe3d684bb5 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java @@ -10,6 +10,7 @@ import app.revanced.extension.shared.Logger; import app.revanced.extension.shared.Utils; import app.revanced.extension.shared.settings.BaseSettings; +import app.revanced.extension.shared.settings.EnumSetting; import app.revanced.extension.shared.settings.Setting; import app.revanced.extension.shared.spoof.requests.StreamingDataRequest; @@ -26,6 +27,27 @@ public class SpoofVideoStreamsPatch { 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); + /** + * @return If this patch was included during patching. + */ + private static boolean isPatchIncluded() { + return false; // Modified during patching. + } + + public static final class NotSpoofingAndroidVrAvailability implements Setting.Availability { + @Override + public boolean isAvailable() { + if (SpoofVideoStreamsPatch.isPatchIncluded()) { + EnumSetting clientType = BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE; + return clientType.isAvailable() && clientType.get() != ClientType.ANDROID_VR; + } + + return true; + } + } + + + /** * Injection point. * Blocks /get_watch requests by returning an unreachable URI. diff --git a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/PlayerRoutes.java b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/PlayerRoutes.java index 5da5628e0b..9832a08a7f 100644 --- a/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/PlayerRoutes.java +++ b/extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/requests/PlayerRoutes.java @@ -37,9 +37,7 @@ static String createInnertubeBody(ClientType clientType) { JSONObject context = new JSONObject(); JSONObject client = new JSONObject(); - if (clientType.useLanguageCode) { - client.put("hl", BaseSettings.SPOOF_VIDEO_STREAMS_LANGUAGE.get().getIso639_1()); - } + client.put("hl", BaseSettings.SPOOF_VIDEO_STREAMS_LANGUAGE.get().getIso639_1()); client.put("clientName", clientType.clientName); client.put("clientVersion", clientType.clientVersion); client.put("deviceModel", clientType.deviceModel); diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/ForceOriginalAudioPatch.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/ForceOriginalAudioPatch.java index 049f3d25f7..91b2fe67a2 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/ForceOriginalAudioPatch.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/ForceOriginalAudioPatch.java @@ -34,8 +34,8 @@ public static boolean isDefaultAudioStream(boolean isDefault, String audioTrackI return isOriginal; } catch (Exception ex) { Logger.printException(() -> "isDefaultAudioStream failure", ex); - } - return isDefault; + return isDefault; + } } } diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 92b9ba8432..c2995dd34f 100644 --- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -7,6 +7,7 @@ import static app.revanced.extension.shared.settings.Setting.migrateOldSettingToNew; import static app.revanced.extension.shared.settings.Setting.parent; import static app.revanced.extension.shared.settings.Setting.parentsAny; +import static app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.NotSpoofingAndroidVrAvailability; import static app.revanced.extension.youtube.patches.ChangeStartPagePatch.StartPage; import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHideExpandCloseAvailability; import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHorizontalDragAvailability; @@ -53,7 +54,7 @@ public class Settings extends BaseSettings { public static final StringSetting CUSTOM_PLAYBACK_SPEEDS = new StringSetting("revanced_custom_playback_speeds", "0.25\n0.5\n0.75\n0.9\n0.95\n1.0\n1.05\n1.1\n1.25\n1.5\n1.75\n2.0\n3.0\n4.0\n5.0", true); // Audio - public static final BooleanSetting FORCE_ORIGINAL_AUDIO = new BooleanSetting("revanced_force_original_audio", FALSE); + public static final BooleanSetting FORCE_ORIGINAL_AUDIO = new BooleanSetting("revanced_force_original_audio", FALSE, new NotSpoofingAndroidVrAvailability()); // Ads public static final BooleanSetting HIDE_BUTTONED_ADS = new BooleanSetting("revanced_hide_buttoned_ads", TRUE); diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt index 0c82935360..c4a581c52a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt @@ -121,3 +121,12 @@ internal val hlsCurrentTimeFingerprint = fingerprint { HLS_CURRENT_TIME_FEATURE_FLAG } } + +internal val patchIncludedExtensionMethodFingerprint = fingerprint { + accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC) + returns("Z") + parameters() + custom { method, classDef -> + classDef.type == EXTENSION_CLASS_DESCRIPTOR && method.name == "isPatchIncluded" + } +} diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt index 004443ed15..417873c709 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/SpoofVideoStreamsPatch.kt @@ -13,6 +13,7 @@ import app.revanced.patches.all.misc.resources.addResourcesPatch import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.insertFeatureFlagBooleanOverride +import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.MutableMethodImplementation @@ -39,6 +40,12 @@ fun spoofVideoStreamsPatch( dependsOn(addResourcesPatch) execute { + // region Enable extension helper method used by other patches + + patchIncludedExtensionMethodFingerprint.method.returnEarly(true) + + // endregion + // region Block /initplayback requests to fall back to /get_watch requests. val moveUriStringIndex = buildInitPlaybackRequestFingerprint.patternMatch!!.startIndex diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/spoof/SpoofVideoStreamsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/spoof/SpoofVideoStreamsPatch.kt index 45bdfc0c89..fa53200bf5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/spoof/SpoofVideoStreamsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/spoof/SpoofVideoStreamsPatch.kt @@ -37,7 +37,7 @@ val spoofVideoStreamsPatch = spoofVideoStreamsPatch({ preferences = setOf( SwitchPreference("revanced_spoof_video_streams"), ListPreference( - "revanced_spoof_video_streams_client", + "revanced_spoof_video_streams_client_type", summaryKey = null, ), ListPreference( @@ -45,8 +45,8 @@ val spoofVideoStreamsPatch = spoofVideoStreamsPatch({ summaryKey = null ), SwitchPreference("revanced_spoof_video_streams_ios_force_avc"), - // Preference requires a title but the actual text is chosen at runtime. NonInteractivePreference( + // Requires a key and title but the actual text is chosen at runtime. key = "revanced_spoof_video_streams_about_android_vr", tag = "app.revanced.extension.youtube.settings.preference.SpoofStreamingDataSideEffectsPreference" ), diff --git a/patches/src/main/resources/addresources/values/arrays.xml b/patches/src/main/resources/addresources/values/arrays.xml index b11c1f9c35..3ce8ff5e39 100644 --- a/patches/src/main/resources/addresources/values/arrays.xml +++ b/patches/src/main/resources/addresources/values/arrays.xml @@ -1,12 +1,12 @@ - + Android VR iOS - + ANDROID_VR IOS diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index f7f95f6e5a..dc826d49b9 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -1296,7 +1296,7 @@ Enabling this can unlock higher video qualities" Video playback may not work" Turning off this setting may cause video playback issues. - Default client + Default client Force AVC (H.264) Video codec is forced to AVC (H.264) Video codec is determined automatically @@ -1309,7 +1309,8 @@ AVC has a maximum resolution of 1080p, Opus audio codec is not available, and vi Android VR spoofing side effects "• Kids videos may not play • Audio track menu is missing -• Stable volume is not available" +• Stable volume is not available +• Force original audio is not available" Default audio stream language App language Arabic