From 14d475637680a913a8b706cc92785b2abb857d4f Mon Sep 17 00:00:00 2001 From: Aaron Veil <70171475+anddea@users.noreply.github.com> Date: Sun, 5 May 2024 16:10:10 +0300 Subject: [PATCH] feat(YouTube - Hide layout components): Add an option to hide videos with views greater than specified value --- .../components/LayoutComponentsFilter.java | 19 +++++++++++++++---- .../youtube/settings/SettingsEnum.java | 3 ++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java index d9dcad5d47..15c656d2ac 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java @@ -105,7 +105,7 @@ public LayoutComponentsFilter() { ); videoWithContext = new StringFilterGroup( - SettingsEnum.HIDE_VIDEO_WITH_VIEW, + null, "video_with_context" ); @@ -209,7 +209,7 @@ boolean isFiltered(String path, @Nullable String identifier, String allValue, by if (matchedGroup == videoWithContext) { String protobufString = new String(protobufBufferArray); - return isLowViewsVideo(protobufString); + return hideVideos(protobufString); } if (matchedGroup == homeVideoWithContext) @@ -234,9 +234,20 @@ boolean isFiltered(String path, @Nullable String identifier, String allValue, by return super.isFiltered(path, identifier, allValue, protobufBufferArray, matchedList, matchedGroup, matchedIndex); } - private boolean isLowViewsVideo(String protobufString) { + + private boolean hideVideos(String protobufString) { + if (SettingsEnum.HIDE_VIDEO_WITH_VIEW.getBoolean()) + return hideVideoBasedOnViews(protobufString); + + return false; + } + + private boolean hideVideoBasedOnViews(String protobufString) { Pattern[] viewCountPatterns = getViewCountPatterns(); + long lessThan = SettingsEnum.HIDE_VIDEO_WITH_LESS_THAN_VIEW_NUM.getLong(); + long greaterThan = SettingsEnum.HIDE_VIDEO_WITH_GREATER_THAN_VIEW_NUM.getLong(); + for (Pattern pattern : viewCountPatterns) { Matcher matcher = pattern.matcher(protobufString); if (matcher.find()) { @@ -244,7 +255,7 @@ private boolean isLowViewsVideo(String protobufString) { double num = parseNumber(numString); String multiplierKey = matcher.group(2); long multiplierValue = getMultiplierValue(multiplierKey); - return num * multiplierValue < SettingsEnum.HIDE_VIDEO_WITH_VIEW_NUM.getLong(); + return num * multiplierValue < lessThan || num * multiplierValue > greaterThan; } } diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/SettingsEnum.java b/app/src/main/java/app/revanced/integrations/youtube/settings/SettingsEnum.java index d60706dcf6..aa6089ae94 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/SettingsEnum.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/SettingsEnum.java @@ -218,7 +218,8 @@ public enum SettingsEnum { HIDE_HOME_FEED_MEMBERSHIP_VIDEO("revanced_hide_home_feed_membership_video", BOOLEAN, FALSE, true), HIDE_VIDEO_WITH_GRAY_DESCRIPTION("revanced_hide_video_with_gray_description", BOOLEAN, FALSE, true), HIDE_VIDEO_WITH_VIEW("revanced_hide_video_with_view", BOOLEAN, FALSE), - HIDE_VIDEO_WITH_VIEW_NUM("revanced_hide_video_with_view_num", LONG, 1000L, parents(HIDE_VIDEO_WITH_VIEW)), + HIDE_VIDEO_WITH_LESS_THAN_VIEW_NUM("revanced_hide_video_with_less_than_views_num", LONG, 1000L, parents(HIDE_VIDEO_WITH_VIEW)), + HIDE_VIDEO_WITH_GREATER_THAN_VIEW_NUM("revanced_hide_video_with_greater_than_views_num", LONG, 1_000_000_000_000L, parents(HIDE_VIDEO_WITH_VIEW)), HIDE_VIDEO_WITH_VIEW_NUM_KEYS("revanced_hide_video_with_low_view_num_multiplier", STRING, str("revanced_hide_video_with_low_view_num_multiplier_value"), parents(HIDE_VIDEO_WITH_VIEW)), HIDE_VIDEO_WITH_LOW_VIEW_OLD("revanced_hide_video_with_low_view_old", BOOLEAN, FALSE),