Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(YouTube - Hide keyword content): Do not hide flyout menu #664

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.youtube.ByteTrieSearch;
import app.revanced.integrations.youtube.StringTrieSearch;
import app.revanced.integrations.youtube.TrieSearch;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.NavigationBar;
Expand Down Expand Up @@ -59,11 +60,15 @@ final class KeywordContentFilter extends Filter {
*/
private static final String[] STRINGS_IN_EVERY_BUFFER = {
// Video playback data.
"https://i.ytimg.com/vi/", // Thumbnail url.
"sddefault.jpg", // More video sizes exist, but for most devices only these 2 are used.
"hqdefault.webp",
"googlevideo.com/initplayback?source=youtube", // Video url.
"ANDROID", // Video url parameter.
"https://i.ytimg.com/vi/", // Thumbnail url.
"mqdefault.jpg",
"hqdefault.jpg",
"sddefault.jpg",
"hq720.jpg",
"webp",
"_custom_", // Custom thumbnail set by video creator.
// Video decoders.
"OMX.ffmpeg.vp9.decoder",
"OMX.Intel.sw_vd.vp9",
Expand All @@ -75,15 +80,22 @@ final class KeywordContentFilter extends Filter {
"c2.android.av1-dav1d.decoder",
"c2.android.vp9.decoder",
"c2.mtk.sw.vp9.decoder",
// User analytics.
"https://ad.doubleclick.net/ddm/activity/",
"DEVICE_ADVERTISER_ID_FOR_CONVERSION_TRACKING",
"tag_for_child_directed_treatment", // Found in overflow menu such as 'Watch later'.
// Litho components frequently found in the buffer that belong to the path filter items.
// Analytics.
"searchR",
"browse-feed",
"FEwhat_to_watch",
"FEsubscriptions",
"search_vwc_description_transition_key",
"g-high-recZ",
// Text and litho components found in the buffer that belong to path filters.
"metadata.eml",
"thumbnail.eml",
"avatar.eml",
"overflow_button.eml",
"shorts-lockup-image",
"shorts-lockup.overlay-metadata.secondary-text",
"YouTubeSans-SemiBold",
"sans-serif"
};

/**
Expand Down Expand Up @@ -112,6 +124,20 @@ final class KeywordContentFilter extends Filter {
"video_card.eml" // Shorts that appear in a horizontal shelf.
);

/**
* Path components to not filter. Cannot filter the buffer when these are present,
* otherwise text in UI controls can be filtered as a keyword (such as using "Playlist" as a keyword).
*
* This is also a small performance improvement since
* the buffer of the parent component was already searched and passed.
*/
private final StringTrieSearch exceptions = new StringTrieSearch(
"metadata.eml",
"thumbnail.eml",
"avatar.eml",
"overflow_button.eml"
);

/**
* Threshold for {@link #filteredVideosPercentage}
* that indicates all or nearly all videos have been filtered.
Expand All @@ -121,7 +147,7 @@ final class KeywordContentFilter extends Filter {

private static final float ALL_VIDEOS_FILTERED_SAMPLE_SIZE = 50;

private static final long ALL_VIDEOS_FILTERED_TIMEOUT_MILLISECONDS = 60 * 1000; // 60 seconds
private static final long ALL_VIDEOS_FILTERED_BACKOFF_MILLISECONDS = 60 * 1000; // 60 seconds

/**
* Rolling average of how many videos were filtered by a keyword.
Expand Down Expand Up @@ -339,7 +365,7 @@ private void updateStats(boolean videoWasHidden, @Nullable String keyword) {

// A keyword is hiding everything.
// Inform the user, and temporarily turn off filtering.
timeToResumeFiltering = System.currentTimeMillis() + ALL_VIDEOS_FILTERED_TIMEOUT_MILLISECONDS;
timeToResumeFiltering = System.currentTimeMillis() + ALL_VIDEOS_FILTERED_BACKOFF_MILLISECONDS;

Logger.printDebug(() -> "Temporarily turning off filtering due to excessively broad filter: " + keyword);
Utils.showToastLong(str("revanced_hide_keyword_toast_invalid_broad", keyword));
Expand All @@ -361,6 +387,10 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff

if (!hideKeywordSettingIsActive()) return false;

if (exceptions.matches(path)) {
return false; // Do not update statistics.
}

MutableReference<String> matchRef = new MutableReference<>();
if (bufferSearch.matches(protobufBufferArray, matchRef)) {
updateStats(true, matchRef.value);
Expand Down
Loading