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

Commit

Permalink
feat(YouTube - Hide layout components): Add an option to hide videos …
Browse files Browse the repository at this point in the history
…with views greater than specified value
  • Loading branch information
anddea committed May 5, 2024
1 parent f4b6939 commit 14d4756
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public LayoutComponentsFilter() {
);

videoWithContext = new StringFilterGroup(
SettingsEnum.HIDE_VIDEO_WITH_VIEW,
null,
"video_with_context"
);

Expand Down Expand Up @@ -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)
Expand All @@ -234,17 +234,28 @@ 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()) {
String numString = Objects.requireNonNull(matcher.group(1));
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down

0 comments on commit 14d4756

Please sign in to comment.