aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-08-11 17:25:10 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-08-11 17:25:10 -0700
commit42036f92d25ec8f0a94e4f3af41c0977eca1274a (patch)
treebd198fd92ff7978b96edc484825559f606e08caa /youtube
parent525ec403c0d083eecae9727a0048ad9074c06e04 (diff)
downloadyt-local-42036f92d25ec8f0a94e4f3af41c0977eca1274a.tar.lz
yt-local-42036f92d25ec8f0a94e4f3af41c0977eca1274a.tar.xz
yt-local-42036f92d25ec8f0a94e4f3af41c0977eca1274a.zip
Delete thumbnails from channel when unsubscribing
Diffstat (limited to 'youtube')
-rw-r--r--youtube/subscriptions.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index b29bf87..3a0ef49 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -92,9 +92,32 @@ def _subscribe(cursor, channels):
cursor.executemany('''INSERT OR IGNORE INTO subscribed_channels (yt_channel_id, channel_name, time_last_checked)
VALUES (?, ?, ?)''', channels)
-# TODO: delete thumbnails
+
+def delete_thumbnails(to_delete):
+ for thumbnail in to_delete:
+ try:
+ video_id = thumbnail[0:-4]
+ if video_id in existing_thumbnails:
+ os.remove(os.path.join(thumbnails_directory, thumbnail))
+ existing_thumbnails.remove(video_id)
+ except Exception:
+ print('Failed to delete thumbnail: ' + thumbnail)
+ traceback.print_exc()
+
def _unsubscribe(cursor, channel_ids):
''' channel_ids is a list of channel_ids '''
+ to_delete = []
+ for channel_id in channel_ids:
+ rows = cursor.execute('''SELECT video_id
+ FROM videos
+ WHERE sql_channel_id = (
+ SELECT id
+ FROM subscribed_channels
+ WHERE yt_channel_id=?
+ )''', (channel_id,)).fetchall()
+ to_delete += [row[0] + '.jpg' for row in rows]
+
+ 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):