From 3730d4e8241cc393a8c4b1d7fb8dd47d3a443def Mon Sep 17 00:00:00 2001 From: girst Date: Wed, 26 Apr 2023 17:12:21 +0000 Subject: [PATCH] subscription feed: filter shorts if the user enabled the 'noshorts' setting videos are displayed iff either noshorts config is false or not a shorts video, but pinning overrides hiding. if shorts are shown, they are marked 'shorts' instead of the length. --- app/youtube/__init__.py | 21 ++++++++++++++++++--- app/youtube/templates/index.html.j2 | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/youtube/__init__.py b/app/youtube/__init__.py index d0f187c..6acff52 100644 --- a/app/youtube/__init__.py +++ b/app/youtube/__init__.py @@ -33,8 +33,21 @@ def feed(): page = request.args.get('page', 0, type=int) with sqlite3.connect(cf['global']['database']) as conn: c = conn.cursor() + + settings = {} # fallback for guest user + if current_user.is_authenticated: + c.execute(""" + SELECT setting, value + FROM user_settings + WHERE user_id = ? + """, (current_user.id,)) + settings = { + setting: json.loads(value) + for setting, value in c.fetchall() + } + c.execute(""" - SELECT videos.id, channel_id, name, title, length, livestream, premiere, published, playlist_videos.playlist_id, display + SELECT videos.id, channel_id, name, title, length, livestream, premiere, shorts, published, playlist_videos.playlist_id, display FROM videos JOIN channels ON videos.channel_id = channels.id LEFT JOIN playlist_videos ON (videos.id = playlist_videos.video_id) @@ -43,9 +56,10 @@ def feed(): OR playlist_videos.playlist_id IN (SELECT channel_id FROM subscriptions WHERE user=? AND type = 'playlist') OR flags.display = 'pinned') AND flags.display IS NOT 'hidden' + AND (flags.display = 'pinned' OR not ? or not shorts) ORDER BY (display = 'pinned') DESC, crawled DESC LIMIT 36 - OFFSET 36*?""", (token, token, token, page)) + OFFSET 36*?""", (token, token, token, settings.get('noshorts', False), page)) rows = [{ 'video_id': video_id, 'channel_id': channel_id, @@ -56,10 +70,11 @@ def feed(): 'premiere': premiere and (# only if it hasn't yet premiered: datetime.strptime(published+'+0000', "%Y-%m-%d %H:%M:%S%z")>datetime.now(tz=timezone.utc) ), + 'shorts': shorts, 'published': published, 'playlist': playlist, 'pinned': display == 'pinned', - } for (video_id, channel_id, author, title, length, livestream, premiere, published, playlist, display) in c.fetchall()] + } for (video_id, channel_id, author, title, length, livestream, premiere, shorts, published, playlist, display) in c.fetchall()] return render_template('index.html.j2', rows=rows, page=page) @frontend.route('/watch') diff --git a/app/youtube/templates/index.html.j2 b/app/youtube/templates/index.html.j2 index fbcb3a6..9347427 100644 --- a/app/youtube/templates/index.html.j2 +++ b/app/youtube/templates/index.html.j2 @@ -7,7 +7,7 @@ {{ super() }}
{% for row in rows %} - {% set badge = 'LIVE' if row.livestream else 'SOON' if row.premiere else row.length|format_time %} + {% set badge = 'shorts' if row.shorts else 'LIVE' if row.livestream else 'SOON' if row.premiere else row.length|format_time %} {% call macros.card(row.video_id, row.title, row.published|format_date, row.pinned, badge=badge) %} {{ macros.infobar_subscriptions(row.video_id, row.channel_id, row.author) }} {% endcall %} -- 2.39.3