use find_missing to also add missing videos from playlist to download queue

This commit is contained in:
simon 2021-11-18 16:37:05 +07:00
parent 1af0196208
commit bb889f7f67
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 47 additions and 1 deletions

View File

@ -403,6 +403,38 @@ class PlaylistSubscription:
return True 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: class VideoDownloader:
""" """

View File

@ -40,8 +40,17 @@ app.autodiscover_tasks()
@shared_task @shared_task
def update_subscribed(): def update_subscribed():
"""look for missing videos and add to pending""" """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() 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: if missing_videos:
pending_handler = PendingList() pending_handler = PendingList()
all_videos_added = pending_handler.add_to_pending(missing_videos) all_videos_added = pending_handler.add_to_pending(missing_videos)
@ -257,3 +266,8 @@ def subscribe_to_playlist(url_str):
PlaylistSubscription().change_subscribe( PlaylistSubscription().change_subscribe(
playlist_id, subscribe_status=True playlist_id, subscribe_status=True
) )
if new_playlists:
handler = ThumbManager()
missing_playlists = handler.get_missing_playlists()
handler.download_playlist(missing_playlists)