Ability to only show videos from channels with specific tag

This commit is contained in:
James Taylor 2019-08-11 18:17:19 -07:00
parent d1ae8dc290
commit b469536ce6
2 changed files with 18 additions and 8 deletions

View File

@ -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'

View File

@ -64,7 +64,7 @@
<ol class="sidebar-list tags">
{% for tag in tags %}
<li class="sidebar-list-item">
<span class="sidebar-item-name">{{ tag }}</span>
<a href="?tag={{ tag|urlencode }}" class="sidebar-item-name">{{ tag }}</a>
<form method="POST" class="sidebar-item-refresh">
<input type="submit" value="Check">
<input type="hidden" name="action" value="refresh">