From 59fdbda886c1bc1acc12da7061b0710b048ce252 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Tue, 11 Jun 2019 01:47:06 -0700 Subject: Add channel muting --- youtube/subscriptions.py | 126 ++++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 50 deletions(-) (limited to 'youtube/subscriptions.py') diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py index e12fa0b..5d049be 100644 --- a/youtube/subscriptions.py +++ b/youtube/subscriptions.py @@ -36,7 +36,9 @@ def open_database(): id integer PRIMARY KEY, yt_channel_id text UNIQUE NOT NULL, channel_name text NOT NULL, - time_last_checked integer + time_last_checked integer, + muted integer DEFAULT 0, + upload_frequency integer )''') cursor.execute('''CREATE TABLE IF NOT EXISTS videos ( id integer PRIMARY KEY, @@ -113,7 +115,7 @@ def _get_videos(cursor, number, offset): } def _get_subscribed_channels(cursor): - for item in cursor.execute('''SELECT channel_name, yt_channel_id + for item in cursor.execute('''SELECT channel_name, yt_channel_id, muted FROM subscribed_channels ORDER BY channel_name COLLATE NOCASE'''): yield item @@ -155,15 +157,22 @@ def _get_channel_names(cursor, channel_ids): return result -def _channels_with_tag(cursor, tag, order=False): +def _channels_with_tag(cursor, tag, order=False, exclude_muted=False, include_muted_status=False): ''' returns list of (channel_id, channel_name) ''' - statement = '''SELECT yt_channel_id, channel_name + statement = '''SELECT yt_channel_id, channel_name''' + + if include_muted_status: + statement += ''', muted''' + + statement += ''' FROM subscribed_channels WHERE subscribed_channels.id IN ( SELECT tag_associations.sql_channel_id FROM tag_associations WHERE tag=? ) ''' + if exclude_muted: + statement += '''AND muted != 1\n''' if order: statement += '''ORDER BY channel_name COLLATE NOCASE''' @@ -289,7 +298,9 @@ def _get_upstream_videos(channel_id): def check_all_channels(): with open_database() as connection: with connection as cursor: - channel_id_name_list = cursor.execute('''SELECT yt_channel_id, channel_name FROM subscribed_channels''').fetchall() + channel_id_name_list = cursor.execute('''SELECT yt_channel_id, channel_name + FROM subscribed_channels + WHERE muted != 1''').fetchall() channel_names.update(channel_id_name_list) check_channels_if_necessary([item[0] for item in channel_id_name_list]) @@ -300,7 +311,7 @@ def check_tags(tags): with open_database() as connection: with connection as cursor: for tag in tags: - channel_id_name_list += _channels_with_tag(cursor, tag) + channel_id_name_list += _channels_with_tag(cursor, tag, exclude_muted=True) channel_names.update(channel_id_name_list) check_channels_if_necessary([item[0] for item in channel_id_name_list]) @@ -369,7 +380,7 @@ def import_subscriptions(env, start_response): sub_list_item_template = Template(''' -
  • +
  • $channel_name $tags @@ -394,12 +405,13 @@ def get_subscription_manager_page(env, start_response): main_list_html = '