From 0053aa0a46503cea7a5e8aae308cf1bdc9865b9d Mon Sep 17 00:00:00 2001 From: sphinxrave <62570796+sphinxrave@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:51:14 -0700 Subject: [PATCH] hiding long streams! --- packages/react/src/hooks/useVideoFilter.ts | 33 +++++++++++++++++++ packages/react/src/locales/en/ui.yml | 2 ++ .../react/src/routes/settings/homepage.tsx | 19 +++++++++++ packages/react/src/store/settings.ts | 14 ++++++++ packages/react/src/types/channel.d.ts | 2 ++ packages/react/src/types/video.d.ts | 2 +- 6 files changed, 71 insertions(+), 1 deletion(-) diff --git a/packages/react/src/hooks/useVideoFilter.ts b/packages/react/src/hooks/useVideoFilter.ts index a80fc5687..1549d7216 100644 --- a/packages/react/src/hooks/useVideoFilter.ts +++ b/packages/react/src/hooks/useVideoFilter.ts @@ -13,6 +13,10 @@ function filterDeadStreams(video: VideoBase, now: dayjs.Dayjs) { ); } +function filterLongVideos(video: VideoBase) { + return video.duration <= 24 * 60 * 60; // 24 hours in seconds +} + type PageContext = "org" | "favorites" | "search" | "watch" | "channel"; export function useVideoFilter( @@ -22,6 +26,7 @@ export function useVideoFilter( overrides?: Partial<{ hideCollabStreams: boolean; filterDeadStreams: boolean; + filterLongVideos: boolean; ignoredTopics: string[]; }>, ) { @@ -47,6 +52,8 @@ export function useVideoFilter( const shouldFilterDeadStreams = type === "stream_schedule" && (overrides?.filterDeadStreams ?? settings.filterDeadStreams); + const shouldFilterLongVideos = + overrides?.filterLongVideos ?? settings.filterLongStreams; const now = shouldFilterDeadStreams ? dayjs() : null; const filteredVideos = videos.filter((video) => { @@ -79,12 +86,38 @@ export function useVideoFilter( keep = keep && filterDeadStreams(video, now); } + // Filter long videos + if (shouldFilterLongVideos) { + keep = keep && filterLongVideos(video); + } + // Filter ignored topics const ignoredTopics = overrides?.ignoredTopics ?? settings.ignoredTopics; if (ignoredTopics.length > 0) { keep = keep && !ignoredTopics.includes(video.topic_id ?? "_N_A"); } + // filter clips whose channels and uploaders are all irrelevant to current context + const videoMentions = (video as Partial