From 0cf422977bb97d0dd8ba0e9d572ffd51ce415af7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 20 Jul 2020 19:08:27 -0700 Subject: [PATCH] If upload_playlist is not set during refresh, try to get it. This is possible if a channel is temporarily suspended during the time you tried to fetch the playlist id originally. --- ycdl/objects.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ycdl/objects.py b/ycdl/objects.py index aa9c90d..2c225d2 100644 --- a/ycdl/objects.py +++ b/ycdl/objects.py @@ -38,6 +38,9 @@ class Channel(Base): def refresh(self, force=False, commit=True): seen_ids = set() + if not self.uploads_playlist: + self.uploads_playlist = self.ycdldb.youtube.get_user_uploads_playlist_id(self.id) + self.set_uploads_playlist_id(self.uploads_playlist) video_generator = self.ycdldb.youtube.get_playlist_videos(self.uploads_playlist) self.ycdldb.log.debug('Refreshing channel: %s', self.id) for video in video_generator: @@ -77,6 +80,20 @@ class Channel(Base): if commit: self.ycdldb.commit() + def set_uploads_playlist_id(self, playlist_id, commit=True): + if not isinstance(playlist_id, str): + raise TypeError(f'Playlist id must be a string, not {type(playlist_id)}.') + + pairs = { + 'id': self.id, + 'uploads_playlist': playlist_id, + } + self.ycdldb.sql_update(table='channels', pairs=pairs, where_key='id') + self.uploads_playlist = playlist_id + + if commit: + self.ycdldb.commit() + class Video(Base): table = 'videos'