diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-08-11 18:17:19 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-08-11 18:17:19 -0700 |
commit | b469536ce6cbdcdfd966a15aa1ce45d8f5b42db9 (patch) | |
tree | f7b557eaf25f3a6877fc1a16866b1e70ce8a7694 /youtube/subscriptions.py | |
parent | d1ae8dc290e294a7f0a4d1fc485479a0236a2345 (diff) | |
download | yt-local-b469536ce6cbdcdfd966a15aa1ce45d8f5b42db9.tar.lz yt-local-b469536ce6cbdcdfd966a15aa1ce45d8f5b42db9.tar.xz yt-local-b469536ce6cbdcdfd966a15aa1ce45d8f5b42db9.zip |
Ability to only show videos from channels with specific tag
Diffstat (limited to 'youtube/subscriptions.py')
-rw-r--r-- | youtube/subscriptions.py | 24 |
1 files changed, 17 insertions, 7 deletions
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' |