Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
fix: Detect some keywords that will always hide all videos
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Mar 19, 2024
1 parent 9937185 commit 34c4b4c
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* appear outside the filtered components so they are not caught.
* - Keywords are case sensitive, but some casing variation is manually added.
* (ie: "mr beast" automatically filters "Mr Beast" and "MR BEAST").
* - Keywords present in the layout or video data cannot be used as filters, otherwise all videos
* will always be hidden. This patch checks for some words a user might enter,
* but some keywords will still hide all videos.
*/
@SuppressWarnings("unused")
@RequiresApi(api = Build.VERSION_CODES.N)
Expand All @@ -44,6 +47,23 @@ final class KeywordContentFilter extends Filter {
*/
private static final int MINIMUM_KEYWORD_LENGTH = 3;

/**
* Words found in the buffer for every video that the user might enter as a keyword.
* This list is not exhaustive and can be updated as needed.
*
* Words must be lowercase.
*/
private static final String[] COMMON_WORDS_IN_EVERY_VIDEO_BUFFER = {
// Video playback url
"google",
"youtube",
"android",
// Video decoders
"decoder",
"ffmpeg",
"intel"
};

/**
* Substrings that are always first in the path.
*/
Expand Down Expand Up @@ -138,7 +158,14 @@ private synchronized void parseKeywords() { // Must be synchronized since Litho
Utils.showToastLong(str("revanced_hide_keyword_toast_invalid_length", MINIMUM_KEYWORD_LENGTH, phrase));
continue;
}
keywords.add(phrase);

// Check if the phrase will cause every video to be hidden.
// This is not an exhaustive check.
String lowerCase = phrase.toLowerCase();
if (Utils.containsAny(lowerCase, COMMON_WORDS_IN_EVERY_VIDEO_BUFFER)) {
Utils.showToastLong(str("revanced_hide_keyword_toast_invalid_common", phrase));
continue;
}

// Add common casing that might appear.
//
Expand All @@ -150,7 +177,8 @@ private synchronized void parseKeywords() { // Must be synchronized since Litho
// not allow comparing two different byte arrays using simple plain array indexes.
//
// Instead add all common case variations of the words.
keywords.add(phrase.toLowerCase());
keywords.add(phrase);
keywords.add(lowerCase);
keywords.add(titleCaseFirstWordOnly(phrase));
keywords.add(capitalizeAllFirstLetters(phrase));
keywords.add(phrase.toUpperCase());
Expand Down

0 comments on commit 34c4b4c

Please sign in to comment.