From b469536ce6cbdcdfd966a15aa1ce45d8f5b42db9 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sun, 11 Aug 2019 18:17:19 -0700 Subject: Ability to only show videos from channels with specific tag --- youtube/subscriptions.py | 24 +++++++++++++++++------- youtube/templates/subscriptions.html | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'youtube') diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index ba1f334..3cb02ff 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -120,12 +120,21 @@ def _unsubscribe(cursor, channel_ids): gevent.spawn(delete_thumbnails, to_delete) cursor.executemany("DELETE FROM subscribed_channels WHERE yt_channel_id=?", ((channel_id, ) for channel_id in channel_ids)) -def _get_videos(cursor, number, offset): - db_videos = cursor.execute('''SELECT video_id, title, duration, channel_name - FROM videos - INNER JOIN subscribed_channels on videos.sql_channel_id = subscribed_channels.id - ORDER BY time_published DESC - LIMIT ? OFFSET ?''', (number, offset)) +def _get_videos(cursor, number, offset, tag = None): + if tag is not None: + db_videos = cursor.execute('''SELECT video_id, title, duration, channel_name + FROM videos + INNER JOIN subscribed_channels on videos.sql_channel_id = subscribed_channels.id + INNER JOIN tag_associations on videos.sql_channel_id = tag_associations.sql_channel_id + WHERE tag = ? + ORDER BY time_published DESC + LIMIT ? OFFSET ?''', (tag, number, offset)) + else: + db_videos = cursor.execute('''SELECT video_id, title, duration, channel_name + FROM videos + INNER JOIN subscribed_channels on videos.sql_channel_id = subscribed_channels.id + ORDER BY time_published DESC + LIMIT ? OFFSET ?''', (number, offset)) for db_video in db_videos: yield { @@ -481,8 +490,9 @@ def post_subscription_manager_page(): def get_subscriptions_page(): with open_database() as connection: with connection as cursor: + tag = request.args.get('tag', None) videos = [] - for video in _get_videos(cursor, 60, 0): + for video in _get_videos(cursor, 60, 0, tag): video['thumbnail'] = util.URL_ORIGIN + '/data/subscription_thumbnails/' + video['id'] + '.jpg' video['type'] = 'video' video['item_size'] = 'small' diff --git a/youtube/templates/subscriptions.html b/youtube/templates/subscriptions.html index a3227b1..442bd88 100644 --- a/youtube/templates/subscriptions.html +++ b/youtube/templates/subscriptions.html @@ -64,7 +64,7 @@