Rearrange some lines for clarity, comment on known_ids.
This commit is contained in:
parent
b1e35f6604
commit
ce028e4ebb
1 changed files with 10 additions and 5 deletions
|
@ -38,12 +38,14 @@ class Channel(Base):
|
||||||
return self.ycdldb.sql_select_one(query, bindings) is not None
|
return self.ycdldb.sql_select_one(query, bindings) is not None
|
||||||
|
|
||||||
def refresh(self, force=False, commit=True):
|
def refresh(self, force=False, commit=True):
|
||||||
seen_ids = set()
|
self.ycdldb.log.debug('Refreshing channel: %s', self.id)
|
||||||
|
|
||||||
if not self.uploads_playlist:
|
if not self.uploads_playlist:
|
||||||
self.uploads_playlist = self.ycdldb.youtube.get_user_uploads_playlist_id(self.id)
|
self.uploads_playlist = self.ycdldb.youtube.get_user_uploads_playlist_id(self.id)
|
||||||
self.set_uploads_playlist_id(self.uploads_playlist)
|
self.set_uploads_playlist_id(self.uploads_playlist)
|
||||||
|
|
||||||
|
seen_ids = set()
|
||||||
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)
|
|
||||||
for video in video_generator:
|
for video in video_generator:
|
||||||
seen_ids.add(video.id)
|
seen_ids.add(video.id)
|
||||||
status = self.ycdldb.insert_video(video, commit=False)
|
status = self.ycdldb.insert_video(video, commit=False)
|
||||||
|
@ -54,12 +56,15 @@ class Channel(Base):
|
||||||
self.ycdldb.download_video(video.id, commit=False)
|
self.ycdldb.download_video(video.id, commit=False)
|
||||||
video.mark_state(self.automark, commit=False)
|
video.mark_state(self.automark, commit=False)
|
||||||
|
|
||||||
if not force and not status['new']:
|
if not (force or status['new']):
|
||||||
break
|
break
|
||||||
|
|
||||||
if force:
|
if force:
|
||||||
known_videos = self.ycdldb.get_videos(channel_id=self.id)
|
# If some videos have become unlisted, then they will not have been
|
||||||
known_ids = {v.id for v in known_videos}
|
# refreshed by the previous loop. So, take the set of all known ids
|
||||||
|
# minus those refreshed by the loop, and try to refresh them.
|
||||||
|
# Of course, it's possible they were deleted.
|
||||||
|
known_ids = {v.id for v in self.ycdldb.get_videos(channel_id=self.id)}
|
||||||
refresh_ids = list(known_ids.difference(seen_ids))
|
refresh_ids = list(known_ids.difference(seen_ids))
|
||||||
for video in self.ycdldb.youtube.get_video(refresh_ids):
|
for video in self.ycdldb.youtube.get_video(refresh_ids):
|
||||||
self.ycdldb.insert_video(video, commit=False)
|
self.ycdldb.insert_video(video, commit=False)
|
||||||
|
|
Loading…
Reference in a new issue