implement skip_on_empty in update_playlist

This commit is contained in:
Simon 2024-05-11 23:09:03 +02:00
parent 97b6d7d606
commit f874d402b1
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 10 additions and 13 deletions

View File

@ -287,18 +287,7 @@ class YoutubeChannel(YouTubeItem):
def _index_single_playlist(playlist):
"""add single playlist if needed"""
playlist = YoutubePlaylist(playlist[0])
playlist.build_json()
if not playlist.json_data:
return
entries = playlist.json_data["playlist_entries"]
downloaded = [i for i in entries if i["downloaded"]]
if not downloaded:
return
playlist.upload_to_es()
playlist.add_vids_to_playlist()
playlist.get_playlist_art()
playlist.update_playlist(skip_on_empty=True)
def get_channel_videos(self):
"""get all videos from channel"""

View File

@ -160,16 +160,24 @@ class YoutubePlaylist(YouTubeItem):
if status_code == 200:
print(f"{self.youtube_id}: removed {video_id} from playlist")
def update_playlist(self):
def update_playlist(self, skip_on_empty=False):
"""update metadata for playlist with data from YouTube"""
self.build_json(scrape=True)
if not self.json_data:
# return false to deactivate
return False
if skip_on_empty:
has_item_downloaded = next(
i["downloaded"] for i in self.json_data["playlist_entries"]
)
if not has_item_downloaded:
return True
self.upload_to_es()
self.add_vids_to_playlist()
self.remove_vids_from_playlist()
self.get_playlist_art()
return True
def build_nav(self, youtube_id):