From bb889f7f67badc1bc33cc48a6eaae7270e5dc17e Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 18 Nov 2021 16:37:05 +0700 Subject: [PATCH] use find_missing to also add missing videos from playlist to download queue --- tubearchivist/home/src/download.py | 32 ++++++++++++++++++++++++++++++ tubearchivist/home/tasks.py | 16 ++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 4e0d119..4550aff 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -403,6 +403,38 @@ class PlaylistSubscription: return True + def find_missing(self): + """find videos in subscribed playlists not downloaded yet""" + all_playlists = self.get_playlists() + pending_handler = PendingList() + all_pending, all_ignore = pending_handler.get_all_pending() + all_ids = [i["youtube_id"] for i in all_ignore + all_pending] + all_downloaded = pending_handler.get_all_downloaded() + to_ignore = all_ids + all_downloaded + + missing_videos = [] + counter = 1 + for playlist in all_playlists: + playlist_entries = playlist["playlist_entries"] + all_missing = [i for i in playlist_entries if not i["downloaded"]] + + RedisArchivist().set_message( + "progress:download", + { + "status": "rescan", + "level": "info", + "title": "Scanning playlists: Looking for new videos.", + "message": f"Progress: {counter}/{len(all_playlists)}", + }, + ) + for video in all_missing: + youtube_id = video["youtube_id"] + if youtube_id not in to_ignore: + missing_videos.append(youtube_id) + counter = counter + 1 + + return missing_videos + class VideoDownloader: """ diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index 2f5bd72..2f49778 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -40,8 +40,17 @@ app.autodiscover_tasks() @shared_task def update_subscribed(): """look for missing videos and add to pending""" + message = { + "status": "rescan", + "level": "info", + "title": "Start rescanning channels and playlists.", + } + RedisArchivist().set_message("progress:download", message) channel_handler = ChannelSubscription() - missing_videos = channel_handler.find_missing() + missing_from_channels = channel_handler.find_missing() + playlist_handler = PlaylistSubscription() + missing_from_playlists = playlist_handler.find_missing() + missing_videos = missing_from_channels + missing_from_playlists if missing_videos: pending_handler = PendingList() all_videos_added = pending_handler.add_to_pending(missing_videos) @@ -257,3 +266,8 @@ def subscribe_to_playlist(url_str): PlaylistSubscription().change_subscribe( playlist_id, subscribe_status=True ) + + if new_playlists: + handler = ThumbManager() + missing_playlists = handler.get_missing_playlists() + handler.download_playlist(missing_playlists)