From 4edb5adead1f075fbe65b0cefc21e917f22969fa Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 13 May 2024 18:26:17 +0200 Subject: [PATCH] thumb clean up notification, call in task --- tubearchivist/home/src/download/thumbnails.py | 27 +++++++++++++++++++ tubearchivist/home/tasks.py | 4 ++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/src/download/thumbnails.py b/tubearchivist/home/src/download/thumbnails.py index 3f80243e..4cefd847 100644 --- a/tubearchivist/home/src/download/thumbnails.py +++ b/tubearchivist/home/src/download/thumbnails.py @@ -366,6 +366,15 @@ class ThumbValidator: delete_path = os.path.join(folder_path, f"{thumb}.jpg") os.remove(delete_path) + if to_delete: + message = ( + f"[thumbs][video][{video_folder}] " + + f"delete {len(to_delete)} unused thumbnails" + ) + print(message) + if self.task: + self.task.send_progress([message]) + @staticmethod def _get_vid_thumbs_should(video_folder: str) -> set[str]: """get indexed""" @@ -393,6 +402,15 @@ class ThumbValidator: delete_path = os.path.join(channel_dir, channel_thumb) os.remove(delete_path) + if to_delete: + message = ( + "[thumbs][channel] " + + f"delete {len(to_delete)} unused channel art" + ) + print(message) + if self.task: + self.task.send_progress([message]) + def _clean_up_playlists(self): """clean up unneeded playlist thumbs""" playlist_dir = os.path.join(EnvironmentSettings.CACHE_DIR, "playlists") @@ -403,6 +421,15 @@ class ThumbValidator: delete_path = os.path.join(playlist_dir, f"{playlist_id}.jpg") os.remove(delete_path) + if to_delete: + message = ( + "[thumbs][playlist] " + + f"delete {len(to_delete)} unused playlist art" + ) + print(message) + if self.task: + self.task.send_progress([message]) + @staticmethod def _get_total(index_name): """get total documents in index""" diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index 9aa5146a..57462ed3 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -259,7 +259,9 @@ def thumbnail_check(self): return manager.init(self) - ThumbValidator(task=self).validate() + thumnail = ThumbValidator(task=self) + thumnail.validate() + thumnail.clean_up() @shared_task(bind=True, name="resync_thumbs", base=BaseTask)