From 0b4557b21a67b05411284bfd3da51b96f8327555 Mon Sep 17 00:00:00 2001
From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Date: Thu, 26 Dec 2024 11:09:54 +0400
Subject: [PATCH 1/3] fix(YouTube - Force original audio): If stream spoofing
to Android then show a summary text why force audio is not available
---
.../shared/spoof/SpoofVideoStreamsPatch.java | 18 ++++------
.../patches/ForceOriginalAudioPatch.java | 16 +++++++++
.../extension/youtube/settings/Settings.java | 4 +--
.../ForceOriginalAudioPreference.java | 36 +++++++++++++++++++
.../video/audio/ForceOriginalAudioPatch.kt | 5 ++-
.../resources/addresources/values/strings.xml | 1 +
6 files changed, 65 insertions(+), 15 deletions(-)
create mode 100644 extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java
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 2595ca1661..ef11885da3 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
@@ -34,6 +34,12 @@ private static boolean isPatchIncluded() {
return false; // Modified during patching.
}
+ public static boolean notSpoofingToAndroid() {
+ return !isPatchIncluded()
+ || !BaseSettings.SPOOF_VIDEO_STREAMS.get()
+ || BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS_UNPLUGGED;
+ }
+
/**
* Injection point.
* Blocks /get_watch requests by returning an unreachable URI.
@@ -206,18 +212,6 @@ public static String appendSpoofedClient(String videoFormat) {
return videoFormat;
}
- public static final class NotSpoofingAndroidAvailability implements Setting.Availability {
- @Override
- public boolean isAvailable() {
- if (SpoofVideoStreamsPatch.isPatchIncluded()) {
- return !BaseSettings.SPOOF_VIDEO_STREAMS.get()
- || BaseSettings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.IOS_UNPLUGGED;
- }
-
- return true;
- }
- }
-
public static final class AudioStreamLanguageOverrideAvailability implements Setting.Availability {
@Override
public boolean isAvailable() {
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 91b2fe67a2..7a713d4f47 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
@@ -1,6 +1,8 @@
package app.revanced.extension.youtube.patches;
import app.revanced.extension.shared.Logger;
+import app.revanced.extension.shared.settings.Setting;
+import app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch;
import app.revanced.extension.youtube.settings.Settings;
@SuppressWarnings("unused")
@@ -8,6 +10,20 @@ public class ForceOriginalAudioPatch {
private static final String DEFAULT_AUDIO_TRACKS_SUFFIX = ".4";
+ /**
+ * If the conditions to use this patch were present when the app launched.
+ */
+ public static boolean PATCH_AVAILABLE = SpoofVideoStreamsPatch.notSpoofingToAndroid();
+
+ public static final class ForceOriginalAudioAvailability implements Setting.Availability {
+ @Override
+ public boolean isAvailable() {
+ // Check conditions of launch and now. Otherwise if spoofing is changed
+ // without a restart the setting will show as available when it's not.
+ return PATCH_AVAILABLE && SpoofVideoStreamsPatch.notSpoofingToAndroid();
+ }
+ }
+
/**
* Injection point.
*/
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 2d0eeef27a..765f03f9ad 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,8 +7,8 @@
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.NotSpoofingAndroidAvailability;
import static app.revanced.extension.youtube.patches.ChangeStartPagePatch.StartPage;
+import static app.revanced.extension.youtube.patches.ForceOriginalAudioPatch.ForceOriginalAudioAvailability;
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHideExpandCloseAvailability;
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerHorizontalDragAvailability;
import static app.revanced.extension.youtube.patches.MiniplayerPatch.MiniplayerType;
@@ -54,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, new NotSpoofingAndroidAvailability());
+ public static final BooleanSetting FORCE_ORIGINAL_AUDIO = new BooleanSetting("revanced_force_original_audio", FALSE, new ForceOriginalAudioAvailability());
// Ads
public static final BooleanSetting HIDE_BUTTONED_ADS = new BooleanSetting("revanced_hide_buttoned_ads", TRUE);
diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java
new file mode 100644
index 0000000000..b97f65fa6f
--- /dev/null
+++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java
@@ -0,0 +1,36 @@
+package app.revanced.extension.youtube.settings.preference;
+
+import static app.revanced.extension.shared.StringRef.str;
+
+import android.content.Context;
+import android.preference.SwitchPreference;
+import android.util.AttributeSet;
+
+import app.revanced.extension.youtube.patches.ForceOriginalAudioPatch;
+
+@SuppressWarnings({"deprecation", "unused"})
+public class ForceOriginalAudioPreference extends SwitchPreference {
+
+ {
+ if (!ForceOriginalAudioPatch.PATCH_AVAILABLE) {
+ // Show why force audio is not available.
+ String summary = str("revanced_force_original_audio_not_available");
+ setSummary(summary);
+ setSummaryOn(summary);
+ setSummaryOff(summary);
+ }
+ }
+
+ public ForceOriginalAudioPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+ public ForceOriginalAudioPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+ public ForceOriginalAudioPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+ public ForceOriginalAudioPreference(Context context) {
+ super(context);
+ }
+}
diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt
index 4a4f00ecf9..2c9cebe8ca 100644
--- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt
@@ -57,7 +57,10 @@ val forceOriginalAudioPatch = bytecodePatch(
addResources("youtube", "video.audio.forceOriginalAudioPatch")
PreferenceScreen.VIDEO.addPreferences(
- SwitchPreference("revanced_force_original_audio")
+ SwitchPreference(
+ key = "revanced_force_original_audio",
+ tag = "app.revanced.extension.youtube.settings.preference.ForceOriginalAudioPreference"
+ )
)
fun Method.firstFormatStreamingModelCall(
diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml
index cc2e0a6c19..c1cf8587b9 100644
--- a/patches/src/main/resources/addresources/values/strings.xml
+++ b/patches/src/main/resources/addresources/values/strings.xml
@@ -1246,6 +1246,7 @@ Enabling this can unlock higher video qualities"
Force original audio
Using original audio
Using default audio
+ To use this feature change stream spoofing to iOS client type
From 81df3ab41367c884cec566f13a88289762e2df88 Mon Sep 17 00:00:00 2001
From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Date: Thu, 26 Dec 2024 11:14:13 +0400
Subject: [PATCH 2/3] refactor
---
...ce.java => ForceOriginalAudioSwitchPreference.java} | 10 +++++-----
.../youtube/video/audio/ForceOriginalAudioPatch.kt | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
rename extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/{ForceOriginalAudioPreference.java => ForceOriginalAudioSwitchPreference.java} (65%)
diff --git a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioSwitchPreference.java
similarity index 65%
rename from extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java
rename to extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioSwitchPreference.java
index b97f65fa6f..6a8c3af364 100644
--- a/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioPreference.java
+++ b/extensions/youtube/src/main/java/app/revanced/extension/youtube/settings/preference/ForceOriginalAudioSwitchPreference.java
@@ -9,7 +9,7 @@
import app.revanced.extension.youtube.patches.ForceOriginalAudioPatch;
@SuppressWarnings({"deprecation", "unused"})
-public class ForceOriginalAudioPreference extends SwitchPreference {
+public class ForceOriginalAudioSwitchPreference extends SwitchPreference {
{
if (!ForceOriginalAudioPatch.PATCH_AVAILABLE) {
@@ -21,16 +21,16 @@ public class ForceOriginalAudioPreference extends SwitchPreference {
}
}
- public ForceOriginalAudioPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ public ForceOriginalAudioSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
- public ForceOriginalAudioPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ public ForceOriginalAudioSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
- public ForceOriginalAudioPreference(Context context, AttributeSet attrs) {
+ public ForceOriginalAudioSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
- public ForceOriginalAudioPreference(Context context) {
+ public ForceOriginalAudioSwitchPreference(Context context) {
super(context);
}
}
diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt
index 2c9cebe8ca..80b91f139f 100644
--- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt
+++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt
@@ -59,7 +59,7 @@ val forceOriginalAudioPatch = bytecodePatch(
PreferenceScreen.VIDEO.addPreferences(
SwitchPreference(
key = "revanced_force_original_audio",
- tag = "app.revanced.extension.youtube.settings.preference.ForceOriginalAudioPreference"
+ tag = "app.revanced.extension.youtube.settings.preference.ForceOriginalAudioSwitchPreference"
)
)
From 179030b55b09ec810d22963a5a86c54a05ae4c28 Mon Sep 17 00:00:00 2001
From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Date: Thu, 26 Dec 2024 13:57:39 +0400
Subject: [PATCH 3/3] adjust text
---
patches/src/main/resources/addresources/values/strings.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml
index c1cf8587b9..83737d8c11 100644
--- a/patches/src/main/resources/addresources/values/strings.xml
+++ b/patches/src/main/resources/addresources/values/strings.xml
@@ -1246,7 +1246,7 @@ Enabling this can unlock higher video qualities"
Force original audio
Using original audio
Using default audio
- To use this feature change stream spoofing to iOS client type
+ To use this feature, change stream spoofing to iOS client type