diff --git a/locales/en-US.json b/locales/en-US.json index 5b2ef8d0e..2931113b2 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -104,6 +104,7 @@ "preferences_captions_label": "Default captions: ", "Fallback captions: ": "Fallback captions: ", "preferences_related_videos_label": "Show related videos: ", + "preferences_filter_short_videos_label": "Hide Shorts / videos under 1 minute: ", "preferences_annotations_label": "Show annotations by default: ", "preferences_extend_desc_label": "Automatically extend video description: ", "preferences_vr_mode_label": "Interactive 360 degree videos (requires WebGL): ", diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 7853d9a3b..5220a9615 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -48,6 +48,7 @@ struct ConfigPreferences property unseen_only : Bool = false property video_loop : Bool = false property extend_desc : Bool = false + property filter_short_videos : Bool = false property volume : Int32 = 100 property vr_mode : Bool = true property show_nick : Bool = true diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr index 11e6f1719..f42629816 100644 --- a/src/invidious/routes/search.cr +++ b/src/invidious/routes/search.cr @@ -63,6 +63,10 @@ module Invidious::Routes::Search else items = query.process end + + if preferences.filter_short_videos + items = items.reject { |item| item.is_a?(SearchVideo) && item.as(SearchVideo).length_seconds < 60 } + end rescue ex : ChannelSearchException return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.") rescue ex diff --git a/src/invidious/search/processors.cr b/src/invidious/search/processors.cr index ecf9aeb31..32df2fb40 100644 --- a/src/invidious/search/processors.cr +++ b/src/invidious/search/processors.cr @@ -39,7 +39,7 @@ module Invidious::Search def subscriptions(query : Query, user : Invidious::User) : Array(ChannelVideo) view_name = "subscriptions_#{sha256(user.email)}" - return PG_DB.query_all(" + videos = PG_DB.query_all(" SELECT id,title,published,updated,ucid,author,length_seconds FROM ( SELECT *, @@ -51,6 +51,12 @@ module Invidious::Search query.text, (query.page - 1) * 20, as: ChannelVideo ) + + if user.preferences.filter_short_videos + videos = videos.reject { |v| v.length_seconds < 60 } + end + + return videos end end end diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index df195dd69..0a5277b23 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -54,6 +54,7 @@ struct Preferences property unseen_only : Bool = CONFIG.default_user_preferences.unseen_only property video_loop : Bool = CONFIG.default_user_preferences.video_loop property extend_desc : Bool = CONFIG.default_user_preferences.extend_desc + property filter_short_videos : Bool = CONFIG.default_user_preferences.filter_short_videos property volume : Int32 = CONFIG.default_user_preferences.volume property save_player_pos : Bool = CONFIG.default_user_preferences.save_player_pos property default_playlist : String? = nil diff --git a/src/invidious/users.cr b/src/invidious/users.cr index 65566d207..ee98be25c 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -102,5 +102,10 @@ def get_subscription_feed(user, max_results = 40, page = 1) videos = videos - notifications end + if user.preferences.filter_short_videos + videos = videos.reject { |v| v.length_seconds < 60 } + notifications = notifications.reject { |v| v.length_seconds < 60 } + end + return videos, notifications end diff --git a/src/invidious/views/user/preferences.ecr b/src/invidious/views/user/preferences.ecr index 703423c04..c52d4dfd2 100644 --- a/src/invidious/views/user/preferences.ecr +++ b/src/invidious/views/user/preferences.ecr @@ -106,6 +106,11 @@ checked<% end %>> +