Skip to content

Commit a2fe3af

Browse files
author
LisoUseInAIKyrios
committed
refactor(YouTube - Litho filter): Simplify debug logging code
1 parent 6ef6504 commit a2fe3af

File tree

11 files changed

+71
-121
lines changed

11 files changed

+71
-121
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/AdsFilter.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ public AdsFilter() {
177177
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
178178
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
179179
if (matchedGroup == playerShoppingShelf) {
180-
if (contentIndex == 0 && playerShoppingShelfBuffer.check(protobufBufferArray).isFiltered()) {
181-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
182-
}
183-
return false;
180+
return contentIndex == 0 && playerShoppingShelfBuffer.check(protobufBufferArray).isFiltered();
184181
}
185182

186183
// Check for the index because of likelihood of false positives.
@@ -198,13 +195,10 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
198195
}
199196

200197
if (matchedGroup == channelProfile) {
201-
if (visitStoreButton.check(protobufBufferArray).isFiltered()) {
202-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
203-
}
204-
return false;
198+
return visitStoreButton.check(protobufBufferArray).isFiltered();
205199
}
206200

207-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
201+
return true;
208202
}
209203

210204
/**

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/ButtonsFilter.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,23 @@ private boolean isEveryFilterGroupEnabled() {
9999
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
100100
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
101101
if (matchedGroup == likeSubscribeGlow) {
102-
if ((path.startsWith(VIDEO_ACTION_BAR_PATH_PREFIX) || path.startsWith(COMPACT_CHANNEL_BAR_PATH_PREFIX))
103-
&& path.contains(ANIMATED_VECTOR_TYPE_PATH)) {
104-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
105-
}
106-
107-
return false;
102+
return (path.startsWith(VIDEO_ACTION_BAR_PATH_PREFIX) || path.startsWith(COMPACT_CHANNEL_BAR_PATH_PREFIX))
103+
&& path.contains(ANIMATED_VECTOR_TYPE_PATH);
108104
}
109105

110106
// If the current matched group is the action bar group,
111107
// in case every filter group is enabled, hide the action bar.
112108
if (matchedGroup == actionBarGroup) {
113-
if (!isEveryFilterGroupEnabled()) {
114-
return false;
115-
}
116-
} else if (matchedGroup == bufferFilterPathGroup) {
109+
return isEveryFilterGroupEnabled();
110+
}
111+
112+
if (matchedGroup == bufferFilterPathGroup) {
117113
// Make sure the current path is the right one
118114
// to avoid false positives.
119-
if (!path.startsWith(VIDEO_ACTION_BAR_PATH)) return false;
120-
121-
// In case the group list has no match, return false.
122-
if (!bufferButtonsGroupList.check(protobufBufferArray).isFiltered()) return false;
115+
return path.startsWith(VIDEO_ACTION_BAR_PATH)
116+
&& bufferButtonsGroupList.check(protobufBufferArray).isFiltered();
123117
}
124118

125-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
119+
return true;
126120
}
127121
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/CommentsFilter.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,15 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
8888
if (matchedGroup == commentComposer) {
8989
// To completely hide the emoji buttons (and leave no empty space), the timestamp button is
9090
// also hidden because the buffer is exactly the same and there's no way selectively hide.
91-
if (contentIndex == 0
91+
return contentIndex == 0
9292
&& path.endsWith(TIMESTAMP_OR_EMOJI_BUTTONS_ENDS_WITH_PATH)
93-
&& emojiPickerBufferGroup.check(protobufBufferArray).isFiltered()) {
94-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
95-
}
96-
97-
return false;
93+
&& emojiPickerBufferGroup.check(protobufBufferArray).isFiltered();
9894
}
9995

10096
if (matchedGroup == filterChipBar) {
101-
if (aiCommentsSummary.check(protobufBufferArray).isFiltered()) {
102-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
103-
}
104-
return false;
97+
return aiCommentsSummary.check(protobufBufferArray).isFiltered();
10598
}
10699

107-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
100+
return true;
108101
}
109102
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/CustomFilter.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
153153
if (custom.startsWith && contentIndex != 0) {
154154
return false;
155155
}
156-
if (custom.bufferSearch != null && !custom.bufferSearch.matches(protobufBufferArray)) {
157-
return false;
156+
157+
if (custom.bufferSearch == null) {
158+
return true; // No buffer filter, only path filtering.
158159
}
159-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
160+
161+
return custom.bufferSearch.matches(protobufBufferArray);
160162
}
161163
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/DescriptionComponentsFilter.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,9 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
9494
if (exceptions.matches(path)) return false;
9595

9696
if (matchedGroup == macroMarkersCarousel) {
97-
if (contentIndex == 0 && macroMarkersCarouselGroupList.check(protobufBufferArray).isFiltered()) {
98-
return super.isFiltered(path, identifier, protobufBufferArray, matchedGroup, contentType, contentIndex);
99-
}
100-
101-
return false;
97+
return contentIndex == 0 && macroMarkersCarouselGroupList.check(protobufBufferArray).isFiltered();
10298
}
10399

104-
return super.isFiltered(path, identifier, protobufBufferArray, matchedGroup, contentType, contentIndex);
100+
return true;
105101
}
106102
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/Filter.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import java.util.Arrays;
77
import java.util.List;
88

9-
import app.revanced.extension.shared.Logger;
10-
import app.revanced.extension.shared.settings.BaseSettings;
11-
129
/**
1310
* Filters litho based components.
1411
*
@@ -62,10 +59,7 @@ protected final void addPathCallbacks(StringFilterGroup... groups) {
6259
* Called after an enabled filter has been matched.
6360
* Default implementation is to always filter the matched component and log the action.
6461
* Subclasses can perform additional or different checks if needed.
65-
* <p>
66-
* If the content is to be filtered, subclasses should always
67-
* call this method (and never return a plain 'true').
68-
* That way the logs will always show when a component was filtered and which filter hide it.
62+
*
6963
* <p>
7064
* Method is called off the main thread.
7165
*
@@ -76,14 +70,6 @@ protected final void addPathCallbacks(StringFilterGroup... groups) {
7670
*/
7771
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
7872
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
79-
if (BaseSettings.DEBUG.get()) {
80-
String filterSimpleName = getClass().getSimpleName();
81-
if (contentType == FilterContentType.IDENTIFIER) {
82-
Logger.printDebug(() -> filterSimpleName + " Filtered identifier: " + identifier);
83-
} else {
84-
Logger.printDebug(() -> filterSimpleName + " Filtered path: " + path);
85-
}
86-
}
8773
return true;
8874
}
8975
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/KeywordContentFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
576576
MutableReference<String> matchRef = new MutableReference<>();
577577
if (bufferSearch.matches(protobufBufferArray, matchRef)) {
578578
updateStats(true, matchRef.value);
579-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
579+
return true;
580580
}
581581

582582
updateStats(false, null);

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/LayoutComponentsFilter.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,43 +286,29 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
286286
// From 2025, the medical information panel is no longer shown in the search results.
287287
// Therefore, this identifier does not filter when the search bar is activated.
288288
if (matchedGroup == singleItemInformationPanel) {
289-
if (PlayerType.getCurrent().isMaximizedOrFullscreen() || !NavigationBar.isSearchBarActive()) {
290-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
291-
}
292-
293-
return false;
289+
return PlayerType.getCurrent().isMaximizedOrFullscreen() || !NavigationBar.isSearchBarActive();
294290
}
295291

296292
// The groups are excluded from the filter due to the exceptions list below.
297293
// Filter them separately here.
298-
if (matchedGroup == notifyMe || matchedGroup == inFeedSurvey || matchedGroup == expandableMetadata)
299-
{
300-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
294+
if (matchedGroup == notifyMe || matchedGroup == inFeedSurvey || matchedGroup == expandableMetadata) {
295+
return true;
301296
}
302297

303298
if (exceptions.matches(path)) return false; // Exceptions are not filtered.
304299

305300
if (matchedGroup == compactChannelBarInner) {
306-
if (compactChannelBarInnerButton.check(path).isFiltered()) {
307-
// The filter may be broad, but in the context of a compactChannelBarInnerButton,
308-
// it's safe to assume that the button is the only thing that should be hidden.
309-
if (joinMembershipButton.check(protobufBufferArray).isFiltered()) {
310-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
311-
}
312-
}
313-
314-
return false;
301+
return compactChannelBarInnerButton.check(path).isFiltered()
302+
// The filter may be broad, but in the context of a compactChannelBarInnerButton,
303+
// it's safe to assume that the button is the only thing that should be hidden.
304+
&& joinMembershipButton.check(protobufBufferArray).isFiltered();
315305
}
316306

317307
if (matchedGroup == horizontalShelves) {
318-
if (contentIndex == 0 && hideShelves()) {
319-
return super.isFiltered(path, identifier, protobufBufferArray, matchedGroup, contentType, contentIndex);
320-
}
321-
322-
return false;
308+
return contentIndex == 0 && hideShelves();
323309
}
324310

325-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
311+
return true;
326312
}
327313

328314
/**

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/LithoFilterPatch.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88

99
import app.revanced.extension.shared.Logger;
10+
import app.revanced.extension.shared.settings.BaseSettings;
1011
import app.revanced.extension.youtube.StringTrieSearch;
1112
import app.revanced.extension.youtube.settings.Settings;
1213

@@ -114,12 +115,29 @@ private static void filterUsingCallbacks(StringTrieSearch pathSearchTree,
114115
if (!group.includeInSearch()) {
115116
continue;
116117
}
118+
117119
for (String pattern : group.filters) {
118-
pathSearchTree.addPattern(pattern, (textSearched, matchedStartIndex, matchedLength, callbackParameter) -> {
120+
String filterSimpleName = filter.getClass().getSimpleName();
121+
122+
pathSearchTree.addPattern(pattern, (textSearched, matchedStartIndex,
123+
matchedLength, callbackParameter) -> {
119124
if (!group.isEnabled()) return false;
125+
120126
LithoFilterParameters parameters = (LithoFilterParameters) callbackParameter;
121-
return filter.isFiltered(parameters.identifier, parameters.path, parameters.protoBuffer,
122-
group, type, matchedStartIndex);
127+
final boolean isFiltered = filter.isFiltered(parameters.identifier,
128+
parameters.path, parameters.protoBuffer, group, type, matchedStartIndex);
129+
130+
if (isFiltered && BaseSettings.DEBUG.get()) {
131+
if (type == Filter.FilterContentType.IDENTIFIER) {
132+
Logger.printDebug(() -> "Filtered " + filterSimpleName
133+
+ " identifier: " + parameters.identifier);
134+
} else {
135+
Logger.printDebug(() -> "Filtered " + filterSimpleName
136+
+ " path: " + parameters.path);
137+
}
138+
}
139+
140+
return isFiltered;
123141
}
124142
);
125143
}

extensions/youtube/src/main/java/app/revanced/extension/youtube/patches/components/PlayerFlyoutMenuItemsFilter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public PlayerFlyoutMenuItemsFilter() {
9999
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
100100
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
101101
if (matchedGroup == videoQualityMenuFooter) {
102-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
102+
return true;
103103
}
104104

105105
if (contentIndex != 0) {
@@ -111,11 +111,6 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
111111
return false;
112112
}
113113

114-
if (flyoutFilterGroupList.check(protobufBufferArray).isFiltered()) {
115-
// Super class handles logging.
116-
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
117-
}
118-
119-
return false;
114+
return flyoutFilterGroupList.check(protobufBufferArray).isFiltered();
120115
}
121116
}

0 commit comments

Comments
 (0)