Skip to content

Commit b7026b7

Browse files
author
LisoUseInAIKyrios
committed
fix(YouTube - Force original audio): Show UI setting summary if spoofing to Android Studio
1 parent fa4f422 commit b7026b7

File tree

50 files changed

+129
-98
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+129
-98
lines changed

extensions/music/src/main/java/app/revanced/extension/music/patches/spoof/SpoofVideoStreamsPatch.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.List;
99

1010
import app.revanced.extension.shared.spoof.ClientType;
11-
import app.revanced.extension.shared.spoof.requests.StreamingDataRequest;
1211

1312
@SuppressWarnings("unused")
1413
public class SpoofVideoStreamsPatch {
@@ -23,8 +22,7 @@ public static void setClientOrderToUse() {
2322
VISIONOS
2423
);
2524

26-
ClientType client = SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get();
27-
app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.setPreferredClient(client);
28-
StreamingDataRequest.setClientOrderToUse(availableClients, client);
25+
app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.setClientsToUse(
26+
availableClients, SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get());
2927
}
3028
}

extensions/shared/library/src/main/java/app/revanced/extension/shared/TrieSearch.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import java.util.List;
88
import java.util.Objects;
99

10-
/**Searches for a group of different patterns using a trie (prefix tree).
10+
/**
11+
* Searches for a group of different patterns using a trie (prefix tree).
1112
* Can significantly speed up searching for multiple patterns.
1213
*/
1314
public abstract class TrieSearch<T> {
@@ -55,11 +56,13 @@ boolean matches(TrieNode<T> enclosingNode, // Used only for the get character me
5556
if (searchTextLength - searchTextIndex < patternLength - patternStartIndex) {
5657
return false; // Remaining search text is shorter than the remaining leaf pattern and they cannot match.
5758
}
59+
5860
for (int i = searchTextIndex, j = patternStartIndex; j < patternLength; i++, j++) {
5961
if (enclosingNode.getCharValue(searchText, i) != enclosingNode.getCharValue(pattern, j)) {
6062
return false;
6163
}
6264
}
65+
6366
return callback == null || callback.patternMatched(searchText,
6467
searchTextIndex - patternStartIndex, patternLength, callbackParameter);
6568
}
@@ -143,6 +146,7 @@ private void addPattern(T pattern, int patternIndex, int patternLength,
143146
endOfPatternCallback.add(callback);
144147
return;
145148
}
149+
146150
if (leaf != null) {
147151
// Reached end of the graph and a leaf exist.
148152
// Recursively call back into this method and push the existing leaf down 1 level.
@@ -157,6 +161,7 @@ private void addPattern(T pattern, int patternIndex, int patternLength,
157161
leaf = new TrieCompressedPath<>(pattern, patternIndex, patternLength, callback);
158162
return;
159163
}
164+
160165
final char character = getCharValue(pattern, patternIndex);
161166
final int arrayIndex = hashIndexForTableSize(children.length, character);
162167
TrieNode<T> child = children[arrayIndex];
@@ -181,6 +186,7 @@ private void expandChildArray(TrieNode<T> child) {
181186
//noinspection unchecked
182187
TrieNode<T>[] replacement = new TrieNode[replacementArraySize];
183188
addNodeToArray(replacement, child);
189+
184190
boolean collision = false;
185191
for (TrieNode<T> existingChild : children) {
186192
if (existingChild != null) {
@@ -193,6 +199,7 @@ private void expandChildArray(TrieNode<T> child) {
193199
if (collision) {
194200
continue;
195201
}
202+
196203
children = replacement;
197204
return;
198205
}
@@ -232,6 +239,7 @@ private static <T> boolean matches(final TrieNode<T> startNode, final T searchTe
232239
if (leaf != null && leaf.matches(startNode, searchText, searchTextEndIndex, searchTextIndex, callbackParameter)) {
233240
return true; // Leaf exists and it matched the search text.
234241
}
242+
235243
List<TriePatternMatchedCallback<T>> endOfPatternCallback = node.endOfPatternCallback;
236244
if (endOfPatternCallback != null) {
237245
final int matchStartIndex = searchTextIndex - currentMatchLength;
@@ -244,6 +252,7 @@ private static <T> boolean matches(final TrieNode<T> startNode, final T searchTe
244252
}
245253
}
246254
}
255+
247256
TrieNode<T>[] children = node.children;
248257
if (children == null) {
249258
return false; // Reached a graph end point and there's no further patterns to search.
@@ -276,9 +285,11 @@ private int estimatedNumberOfPointersUsed() {
276285
if (leaf != null) {
277286
numberOfPointers += 4; // Number of fields in leaf node.
278287
}
288+
279289
if (endOfPatternCallback != null) {
280290
numberOfPointers += endOfPatternCallback.size();
281291
}
292+
282293
if (children != null) {
283294
numberOfPointers += children.length;
284295
for (TrieNode<T> child : children) {

extensions/shared/library/src/main/java/app/revanced/extension/shared/spoof/SpoofVideoStreamsPatch.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import androidx.annotation.Nullable;
77

88
import java.nio.ByteBuffer;
9+
import java.util.List;
910
import java.util.Map;
1011
import java.util.Objects;
1112

@@ -43,7 +44,7 @@ public class SpoofVideoStreamsPatch {
4344
/**
4445
* @return If this patch was included during patching.
4546
*/
46-
private static boolean isPatchIncluded() {
47+
public static boolean isPatchIncluded() {
4748
return false; // Modified during patching.
4849
}
4950

@@ -60,8 +61,9 @@ public static void setLanguageOverride(@Nullable AppLanguage language) {
6061
languageOverride = language;
6162
}
6263

63-
public static void setPreferredClient(ClientType client) {
64+
public static void setClientsToUse(List<ClientType> availableClients, ClientType client) {
6465
preferredClient = Objects.requireNonNull(client);
66+
StreamingDataRequest.setClientOrderToUse(availableClients, client);
6567
}
6668

6769
public static boolean spoofingToClientWithNoMultiAudioStreams() {

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/spoof/SpoofVideoStreamsPatch.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010

1111
import app.revanced.extension.shared.spoof.ClientType;
12-
import app.revanced.extension.shared.spoof.requests.StreamingDataRequest;
1312
import app.revanced.extension.youtube.settings.Settings;
1413

1514
@SuppressWarnings("unused")
@@ -27,8 +26,7 @@ public static void setClientOrderToUse() {
2726
IPADOS
2827
);
2928

30-
ClientType client = Settings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get();
31-
app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.setPreferredClient(client);
32-
StreamingDataRequest.setClientOrderToUse(availableClients, client);
29+
app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch.setClientsToUse(
30+
availableClients, Settings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get());
3331
}
3432
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package app.revanced.extension.youtube.settings.preference;
2+
3+
import static app.revanced.extension.shared.StringRef.str;
4+
5+
import android.content.Context;
6+
import android.preference.SwitchPreference;
7+
import android.util.AttributeSet;
8+
9+
import app.revanced.extension.shared.spoof.ClientType;
10+
import app.revanced.extension.shared.spoof.SpoofVideoStreamsPatch;
11+
import app.revanced.extension.youtube.settings.Settings;
12+
13+
@SuppressWarnings({"deprecation", "unused"})
14+
public class ForceOriginalAudioSwitchPreference extends SwitchPreference {
15+
16+
// Spoof stream patch is not included, or is not currently spoofing to Android Studio.
17+
private static final boolean available = !SpoofVideoStreamsPatch.isPatchIncluded()
18+
|| !(Settings.SPOOF_VIDEO_STREAMS.get()
19+
&& Settings.SPOOF_VIDEO_STREAMS_CLIENT_TYPE.get() == ClientType.ANDROID_CREATOR);
20+
21+
{
22+
if (!available) {
23+
// Show why force audio is not available.
24+
String summary = str("revanced_force_original_audio_not_available");
25+
super.setSummary(summary);
26+
super.setSummaryOn(summary);
27+
super.setSummaryOff(summary);
28+
super.setEnabled(false);
29+
}
30+
}
31+
32+
public ForceOriginalAudioSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
33+
super(context, attrs, defStyleAttr, defStyleRes);
34+
}
35+
public ForceOriginalAudioSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
36+
super(context, attrs, defStyleAttr);
37+
}
38+
public ForceOriginalAudioSwitchPreference(Context context, AttributeSet attrs) {
39+
super(context, attrs);
40+
}
41+
public ForceOriginalAudioSwitchPreference(Context context) {
42+
super(context);
43+
}
44+
45+
@Override
46+
public void setEnabled(boolean enabled) {
47+
if (!available) {
48+
return;
49+
}
50+
51+
super.setEnabled(enabled);
52+
}
53+
54+
@Override
55+
public void setSummary(CharSequence summary) {
56+
if (!available) {
57+
return;
58+
}
59+
60+
super.setSummary(summary);
61+
}
62+
}
63+

patches/src/main/kotlin/app/revanced/patches/shared/misc/spoof/Fingerprints.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ internal val nerdsStatsVideoFormatBuilderFingerprint = fingerprint {
150150
}
151151

152152
internal val patchIncludedExtensionMethodFingerprint = fingerprint {
153-
accessFlags(AccessFlags.PRIVATE, AccessFlags.STATIC)
154153
returns("Z")
155154
parameters()
156155
custom { method, classDef ->

patches/src/main/kotlin/app/revanced/patches/youtube/video/audio/ForceOriginalAudioPatch.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ val forceOriginalAudioPatch = bytecodePatch(
5757
addResources("youtube", "video.audio.forceOriginalAudioPatch")
5858

5959
PreferenceScreen.VIDEO.addPreferences(
60-
SwitchPreference("revanced_force_original_audio")
60+
SwitchPreference(
61+
key = "revanced_force_original_audio",
62+
tag = "app.revanced.extension.youtube.settings.preference.ForceOriginalAudioSwitchPreference"
63+
)
6164
)
6265

6366
mainActivityOnCreateFingerprint.method.addInstruction(

patches/src/main/resources/addresources/values-ar-rSA/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,7 @@ Second \"item\" text"</string>
14761476
<string name="revanced_force_original_audio_title">فرض لغة الصوت الأصلية</string>
14771477
<string name="revanced_force_original_audio_summary_on">استخدام لغة الصوت الأصلية</string>
14781478
<string name="revanced_force_original_audio_summary_off">استخدام الصوت الافتراضي</string>
1479-
<!-- 'Spoof video streams' should be the same translation used for 'revanced_spoof_video_streams_screen_title'. -->
1480-
<string name="revanced_force_original_audio_not_available">لاستخدام هذه الميزة، غيّر \'Spoof Video Streams\' إلى iOS TV</string>
1479+
14811480
</patch>
14821481
<patch id="video.quality.rememberVideoQualityPatch">
14831482
<!-- Translations should use the same text as 'revanced_custom_playback_speeds_auto'. -->

patches/src/main/resources/addresources/values-az-rAZ/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,7 @@ Bunu aktivləşdirmə daha yüksək video keyfiyyətləri əngəlin silə bilər
14721472
<string name="revanced_force_original_audio_title">Orijinal səs dilini zorla</string>
14731473
<string name="revanced_force_original_audio_summary_on">Orijinal səs dilini istifadə</string>
14741474
<string name="revanced_force_original_audio_summary_off">İlkin səs istifadəsi</string>
1475-
<!-- 'Spoof video streams' should be the same translation used for 'revanced_spoof_video_streams_screen_title'. -->
1476-
<string name="revanced_force_original_audio_not_available">Bu xüsusiyyəti istifadə etmək üçün \"Saxta video yayımların\" iOS TV-yə dəyiş</string>
1475+
14771476
</patch>
14781477
<patch id="video.quality.rememberVideoQualityPatch">
14791478
<!-- Translations should use the same text as 'revanced_custom_playback_speeds_auto'. -->

patches/src/main/resources/addresources/values-be-rBY/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,8 +1477,7 @@ Second \"item\" text"</string>
14771477
<string name="revanced_force_original_audio_title">Вымушаная арыгінальная мова аўдыё</string>
14781478
<string name="revanced_force_original_audio_summary_on">Выкарыстоўваць арыгінальную мову аўдыя</string>
14791479
<string name="revanced_force_original_audio_summary_off">Выкарыстанне аўдыё па змаўчанні</string>
1480-
<!-- 'Spoof video streams' should be the same translation used for 'revanced_spoof_video_streams_screen_title'. -->
1481-
<string name="revanced_force_original_audio_not_available">Каб выкарыстоўваць гэту функцыю, змяніце параметр \"Падрабляць відэаструмені\" на iOS TV</string>
1480+
14821481
</patch>
14831482
<patch id="video.quality.rememberVideoQualityPatch">
14841483
<!-- Translations should use the same text as 'revanced_custom_playback_speeds_auto'. -->

0 commit comments

Comments
 (0)