2024-01-01 16:33:20 +01:00
|
|
|
package app.revanced.integrations.youtube.patches.components;
|
2023-05-10 01:04:38 +02:00
|
|
|
|
2023-09-28 01:28:34 +02:00
|
|
|
import android.os.Build;
|
2023-05-10 01:04:38 +02:00
|
|
|
import android.view.View;
|
2023-08-01 19:05:31 +02:00
|
|
|
import androidx.annotation.Nullable;
|
2023-09-28 01:28:34 +02:00
|
|
|
import androidx.annotation.RequiresApi;
|
2024-01-01 16:33:20 +01:00
|
|
|
|
|
|
|
import app.revanced.integrations.youtube.settings.Settings;
|
2023-05-10 02:14:51 +02:00
|
|
|
import com.google.android.libraries.youtube.rendering.ui.pivotbar.PivotBar;
|
|
|
|
|
2024-01-01 16:33:20 +01:00
|
|
|
import static app.revanced.integrations.shared.Utils.hideViewBy1dpUnderCondition;
|
|
|
|
import static app.revanced.integrations.shared.Utils.hideViewUnderCondition;
|
2023-05-10 01:04:38 +02:00
|
|
|
|
2023-12-12 23:40:28 +01:00
|
|
|
@SuppressWarnings("unused")
|
2023-09-28 01:28:34 +02:00
|
|
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
2023-05-10 01:04:38 +02:00
|
|
|
public final class ShortsFilter extends Filter {
|
2023-08-01 19:05:31 +02:00
|
|
|
public static PivotBar pivotBar; // Set by patch.
|
2023-09-28 01:28:34 +02:00
|
|
|
private final String REEL_CHANNEL_BAR_PATH = "reel_channel_bar.eml";
|
2023-08-01 19:05:31 +02:00
|
|
|
|
2024-02-28 12:11:47 +01:00
|
|
|
private final StringFilterGroup shortsCompactFeedVideoPath;
|
|
|
|
private final ByteArrayFilterGroup shortsCompactFeedVideoBuffer;
|
|
|
|
|
2023-08-01 19:05:31 +02:00
|
|
|
private final StringFilterGroup channelBar;
|
2024-03-26 01:51:26 +01:00
|
|
|
private final StringFilterGroup fullVideoLinkLabel;
|
|
|
|
private final StringFilterGroup videoTitle;
|
2023-10-05 03:41:52 +02:00
|
|
|
private final StringFilterGroup subscribeButton;
|
2023-10-05 18:48:53 +02:00
|
|
|
private final StringFilterGroup subscribeButtonPaused;
|
2023-08-01 19:05:31 +02:00
|
|
|
private final StringFilterGroup soundButton;
|
|
|
|
private final StringFilterGroup infoPanel;
|
2024-03-26 01:52:41 +01:00
|
|
|
private final StringFilterGroup joinButton;
|
2023-09-28 01:28:34 +02:00
|
|
|
private final StringFilterGroup shelfHeader;
|
|
|
|
|
2024-03-26 01:50:40 +01:00
|
|
|
private final StringFilterGroup actionBar;
|
2023-09-28 01:28:34 +02:00
|
|
|
private final ByteArrayFilterGroupList videoActionButtonGroupList = new ByteArrayFilterGroupList();
|
2023-05-10 01:04:38 +02:00
|
|
|
|
|
|
|
public ShortsFilter() {
|
2023-08-27 21:40:07 +02:00
|
|
|
var shorts = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS,
|
2023-08-27 21:40:07 +02:00
|
|
|
"shorts_shelf",
|
|
|
|
"inline_shorts",
|
|
|
|
"shorts_grid",
|
|
|
|
"shorts_video_cell",
|
|
|
|
"shorts_pivot_item"
|
|
|
|
);
|
2023-09-28 01:28:34 +02:00
|
|
|
// Feed Shorts shelf header.
|
2023-08-27 21:40:07 +02:00
|
|
|
// Use a different filter group for this pattern, as it requires an additional check after matching.
|
2023-09-28 01:28:34 +02:00
|
|
|
shelfHeader = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS,
|
2023-08-27 21:40:07 +02:00
|
|
|
"shelf_header.eml"
|
|
|
|
);
|
|
|
|
|
2023-09-28 01:28:34 +02:00
|
|
|
// Home / subscription feed components.
|
|
|
|
var thanksButton = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_THANKS_BUTTON,
|
2023-09-28 01:28:34 +02:00
|
|
|
"suggested_action"
|
|
|
|
);
|
|
|
|
|
2023-12-12 23:40:28 +01:00
|
|
|
addIdentifierCallbacks(shorts, shelfHeader, thanksButton);
|
2023-08-27 21:40:07 +02:00
|
|
|
|
2024-02-28 12:11:47 +01:00
|
|
|
// Shorts that appear in the feed/search when the device is using tablet layout.
|
|
|
|
shortsCompactFeedVideoPath = new StringFilterGroup(Settings.HIDE_SHORTS,
|
|
|
|
"compact_video.eml");
|
|
|
|
// Filter out items that use the 'frame0' thumbnail.
|
|
|
|
// This is a valid thumbnail for both regular videos and Shorts,
|
|
|
|
// but it appears these thumbnails are used only for Shorts.
|
|
|
|
shortsCompactFeedVideoBuffer = new ByteArrayFilterGroup(Settings.HIDE_SHORTS,
|
|
|
|
"/frame0.jpg");
|
|
|
|
|
2023-08-27 21:40:07 +02:00
|
|
|
// Shorts player components.
|
2024-03-26 01:52:41 +01:00
|
|
|
joinButton = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_JOIN_BUTTON,
|
2023-08-27 21:40:07 +02:00
|
|
|
"sponsor_button"
|
|
|
|
);
|
2023-10-05 03:41:52 +02:00
|
|
|
|
|
|
|
subscribeButton = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_SUBSCRIBE_BUTTON,
|
2023-10-05 18:48:53 +02:00
|
|
|
"subscribe_button"
|
|
|
|
);
|
|
|
|
|
|
|
|
subscribeButtonPaused = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_SUBSCRIBE_BUTTON_PAUSED,
|
2023-10-02 00:50:18 +02:00
|
|
|
"shorts_paused_state"
|
2023-08-27 21:40:07 +02:00
|
|
|
);
|
2023-09-28 01:28:34 +02:00
|
|
|
|
2023-08-01 19:05:31 +02:00
|
|
|
channelBar = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_CHANNEL_BAR,
|
2023-08-01 19:05:31 +02:00
|
|
|
REEL_CHANNEL_BAR_PATH
|
|
|
|
);
|
2023-10-05 03:41:52 +02:00
|
|
|
|
2024-03-26 01:51:26 +01:00
|
|
|
fullVideoLinkLabel = new StringFilterGroup(
|
|
|
|
Settings.HIDE_SHORTS_FULL_VIDEO_LINK_LABEL,
|
|
|
|
"reel_multi_format_link"
|
|
|
|
);
|
|
|
|
|
|
|
|
videoTitle = new StringFilterGroup(
|
|
|
|
Settings.HIDE_SHORTS_VIDEO_TITLE,
|
|
|
|
"shorts_video_title_item"
|
|
|
|
);
|
|
|
|
|
2023-08-01 19:05:31 +02:00
|
|
|
soundButton = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_SOUND_BUTTON,
|
2023-08-01 19:05:31 +02:00
|
|
|
"reel_pivot_button"
|
|
|
|
);
|
2023-09-28 01:28:34 +02:00
|
|
|
|
2023-08-01 19:05:31 +02:00
|
|
|
infoPanel = new StringFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_INFO_PANEL,
|
2023-08-01 19:05:31 +02:00
|
|
|
"shorts_info_panel_overview"
|
|
|
|
);
|
2023-09-28 01:28:34 +02:00
|
|
|
|
2024-03-26 01:50:40 +01:00
|
|
|
actionBar = new StringFilterGroup(
|
2023-09-28 01:28:34 +02:00
|
|
|
null,
|
2024-03-26 01:50:40 +01:00
|
|
|
"shorts_action_bar"
|
2023-09-28 01:28:34 +02:00
|
|
|
);
|
|
|
|
|
2023-12-12 23:40:28 +01:00
|
|
|
addPathCallbacks(
|
2024-02-28 12:11:47 +01:00
|
|
|
shortsCompactFeedVideoPath,
|
2023-10-06 12:37:50 +02:00
|
|
|
joinButton, subscribeButton, subscribeButtonPaused,
|
2024-03-26 01:51:26 +01:00
|
|
|
channelBar, fullVideoLinkLabel, videoTitle, soundButton,
|
|
|
|
infoPanel, actionBar
|
2024-03-26 01:50:40 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
var shortsLikeButton = new ByteArrayFilterGroup(
|
|
|
|
Settings.HIDE_SHORTS_LIKE_BUTTON,
|
|
|
|
"shorts_like_button"
|
|
|
|
);
|
|
|
|
|
|
|
|
var shortsDislikeButton = new ByteArrayFilterGroup(
|
|
|
|
Settings.HIDE_SHORTS_DISLIKE_BUTTON,
|
|
|
|
"shorts_dislike_button"
|
2023-09-28 01:28:34 +02:00
|
|
|
);
|
|
|
|
|
2023-12-12 23:40:28 +01:00
|
|
|
var shortsCommentButton = new ByteArrayFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_COMMENTS_BUTTON,
|
2023-09-28 01:28:34 +02:00
|
|
|
"reel_comment_button"
|
|
|
|
);
|
|
|
|
|
2023-12-12 23:40:28 +01:00
|
|
|
var shortsShareButton = new ByteArrayFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_SHARE_BUTTON,
|
2023-09-28 01:28:34 +02:00
|
|
|
"reel_share_button"
|
|
|
|
);
|
|
|
|
|
2023-12-12 23:40:28 +01:00
|
|
|
var shortsRemixButton = new ByteArrayFilterGroup(
|
2024-01-01 16:33:20 +01:00
|
|
|
Settings.HIDE_SHORTS_REMIX_BUTTON,
|
2023-09-28 01:28:34 +02:00
|
|
|
"reel_remix_button"
|
|
|
|
);
|
|
|
|
|
2024-03-26 01:50:40 +01:00
|
|
|
videoActionButtonGroupList.addAll(
|
|
|
|
shortsLikeButton,
|
|
|
|
shortsDislikeButton,
|
|
|
|
shortsCommentButton,
|
|
|
|
shortsShareButton,
|
|
|
|
shortsRemixButton
|
|
|
|
);
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-08-27 21:40:07 +02:00
|
|
|
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
|
2023-12-12 23:40:28 +01:00
|
|
|
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
|
|
|
|
if (contentType == FilterContentType.PATH) {
|
2023-08-27 21:40:07 +02:00
|
|
|
// Always filter if matched.
|
2023-10-05 03:41:52 +02:00
|
|
|
if (matchedGroup == soundButton ||
|
|
|
|
matchedGroup == infoPanel ||
|
|
|
|
matchedGroup == channelBar ||
|
2024-03-26 01:51:26 +01:00
|
|
|
matchedGroup == fullVideoLinkLabel ||
|
|
|
|
matchedGroup == videoTitle ||
|
2023-10-05 18:48:53 +02:00
|
|
|
matchedGroup == subscribeButtonPaused
|
2023-12-12 23:40:28 +01:00
|
|
|
) return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
|
2023-09-28 01:28:34 +02:00
|
|
|
|
2024-02-28 12:11:47 +01:00
|
|
|
if (matchedGroup == shortsCompactFeedVideoPath) {
|
|
|
|
if (contentIndex == 0 && shortsCompactFeedVideoBuffer.check(protobufBufferArray).isFiltered()) {
|
|
|
|
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-03-26 01:50:40 +01:00
|
|
|
// Video action buttons (like, dislike, comment, share, remix) have the same path.
|
|
|
|
if (matchedGroup == actionBar) {
|
2023-10-08 21:08:29 +02:00
|
|
|
if (videoActionButtonGroupList.check(protobufBufferArray).isFiltered()) return super.isFiltered(
|
2023-12-12 23:40:28 +01:00
|
|
|
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
|
2023-10-08 21:08:29 +02:00
|
|
|
);
|
2023-09-28 01:28:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-08-27 21:40:07 +02:00
|
|
|
|
|
|
|
// Filter other path groups from pathFilterGroupList, only when reelChannelBar is visible
|
|
|
|
// to avoid false positives.
|
2024-03-26 01:52:41 +01:00
|
|
|
if (matchedGroup == subscribeButton ||
|
|
|
|
matchedGroup == joinButton
|
|
|
|
) {
|
2024-02-28 12:11:47 +01:00
|
|
|
if (path.startsWith(REEL_CHANNEL_BAR_PATH)) return super.isFiltered(
|
2023-12-12 23:40:28 +01:00
|
|
|
identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex
|
2023-10-08 21:08:29 +02:00
|
|
|
);
|
2024-02-28 12:11:47 +01:00
|
|
|
}
|
2023-10-08 21:08:29 +02:00
|
|
|
|
|
|
|
return false;
|
2023-09-28 01:28:34 +02:00
|
|
|
} else if (matchedGroup == shelfHeader) {
|
2023-08-27 21:40:07 +02:00
|
|
|
// Because the header is used in watch history and possibly other places, check for the index,
|
|
|
|
// which is 0 when the shelf header is used for Shorts.
|
2023-12-12 23:40:28 +01:00
|
|
|
if (contentIndex != 0) return false;
|
2023-08-01 19:05:31 +02:00
|
|
|
}
|
2023-05-27 09:47:58 +02:00
|
|
|
|
2023-08-27 21:40:07 +02:00
|
|
|
// Super class handles logging.
|
2023-12-12 23:40:28 +01:00
|
|
|
return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex);
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void hideShortsShelf(final View shortsShelfView) {
|
2024-01-01 16:33:20 +01:00
|
|
|
hideViewBy1dpUnderCondition(Settings.HIDE_SHORTS, shortsShelfView);
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|
|
|
|
|
2023-09-28 01:28:34 +02:00
|
|
|
// region Hide the buttons in older versions of YouTube. New versions use Litho.
|
2023-05-10 01:04:38 +02:00
|
|
|
|
|
|
|
public static void hideShortsCommentsButton(final View commentsButtonView) {
|
2024-01-01 16:33:20 +01:00
|
|
|
hideViewUnderCondition(Settings.HIDE_SHORTS_COMMENTS_BUTTON, commentsButtonView);
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void hideShortsRemixButton(final View remixButtonView) {
|
2024-01-01 16:33:20 +01:00
|
|
|
hideViewUnderCondition(Settings.HIDE_SHORTS_REMIX_BUTTON, remixButtonView);
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void hideShortsShareButton(final View shareButtonView) {
|
2024-01-01 16:33:20 +01:00
|
|
|
hideViewUnderCondition(Settings.HIDE_SHORTS_SHARE_BUTTON, shareButtonView);
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|
2023-05-10 02:14:51 +02:00
|
|
|
|
2023-09-28 01:28:34 +02:00
|
|
|
// endregion
|
|
|
|
|
2023-05-10 02:14:51 +02:00
|
|
|
public static void hideNavigationBar() {
|
2024-01-01 16:33:20 +01:00
|
|
|
if (!Settings.HIDE_SHORTS_NAVIGATION_BAR.get()) return;
|
2023-05-10 02:14:51 +02:00
|
|
|
if (pivotBar == null) return;
|
|
|
|
|
|
|
|
pivotBar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static View hideNavigationBar(final View navigationBarView) {
|
2024-01-01 16:33:20 +01:00
|
|
|
if (Settings.HIDE_SHORTS_NAVIGATION_BAR.get())
|
2023-05-10 02:14:51 +02:00
|
|
|
return null; // Hides the navigation bar.
|
|
|
|
|
|
|
|
return navigationBarView;
|
|
|
|
}
|
2023-05-10 01:04:38 +02:00
|
|
|
}
|