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.
This commit is contained in:
voussoir 2020-07-20 19:08:27 -07:00
parent 41c6a344fa
commit 0cf422977b

View file

@ -38,6 +38,9 @@ class Channel(Base):
def refresh(self, force=False, commit=True): def refresh(self, force=False, commit=True):
seen_ids = set() 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) video_generator = self.ycdldb.youtube.get_playlist_videos(self.uploads_playlist)
self.ycdldb.log.debug('Refreshing channel: %s', self.id) self.ycdldb.log.debug('Refreshing channel: %s', self.id)
for video in video_generator: for video in video_generator:
@ -77,6 +80,20 @@ class Channel(Base):
if commit: if commit:
self.ycdldb.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): class Video(Base):
table = 'videos' table = 'videos'