[FOLLOWUP] Actually process YT channels and playlists ascending (#160)

* actually sort

* use playlist_index instead
This commit is contained in:
Jesse Bannon 2022-08-06 22:40:45 -07:00 committed by GitHub
parent 8033b1a44c
commit 47a46265cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -213,7 +213,10 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT]
) )
def _filter_entry_dicts( def _filter_entry_dicts(
self, entry_dicts: List[Dict], extractor: Optional[str] = None self,
entry_dicts: List[Dict],
extractor: Optional[str] = None,
sort_by: Optional[str] = None,
) -> List[Dict]: ) -> List[Dict]:
""" """
Parameters Parameters
@ -223,6 +226,8 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT]
extractor extractor
Optional. Extractor that the entry dicts must have. If None, defaults to the Optional. Extractor that the entry dicts must have. If None, defaults to the
entry type's extractor entry type's extractor
sort_by
Optional. Sort the entry dicts on this key
Returns Returns
------- -------
@ -231,9 +236,12 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT]
if extractor is None: if extractor is None:
extractor = self.downloader_entry_type.entry_extractor extractor = self.downloader_entry_type.entry_extractor
return [ output = [
entry_dict for entry_dict in entry_dicts if entry_dict.get("extractor") == extractor entry_dict for entry_dict in entry_dicts if entry_dict.get("extractor") == extractor
] ]
if sort_by:
output = sorted(output, key=lambda entry_dict: entry_dict[sort_by])
return output
def _get_entry_dicts_from_info_json_files(self) -> List[Dict]: def _get_entry_dicts_from_info_json_files(self) -> List[Dict]:
""" """

View file

@ -150,9 +150,9 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions
url=self.download_options.channel_url, url=self.download_options.channel_url,
) )
self.channel = self._get_channel(entry_dicts=entry_dicts) self.channel = self._get_channel(entry_dicts=entry_dicts)
channel_videos = self._filter_entry_dicts(entry_dicts=entry_dicts) channel_videos = self._filter_entry_dicts(entry_dicts, sort_by="playlist_index")
# Iterate in reverse to process older videos first. In case an error occurs and a # Iterate in descending order to process older videos first. In case an error occurs and a
# the channel must be redownloaded, it will fetch most recent metadata first, and break # the channel must be redownloaded, it will fetch most recent metadata first, and break
# on the older video that's been processed and is in the download archive. # on the older video that's been processed and is in the download archive.
for idx, entry_dict in enumerate(reversed(channel_videos), start=1): for idx, entry_dict in enumerate(reversed(channel_videos), start=1):

View file

@ -78,11 +78,11 @@ class YoutubePlaylistDownloader(
log_prefix_on_info_json_dl="Downloading metadata for", log_prefix_on_info_json_dl="Downloading metadata for",
url=self.download_options.playlist_url, url=self.download_options.playlist_url,
) )
playlist_videos = self._filter_entry_dicts(entry_dicts=entry_dicts)
# Iterate in reverse to process older videos first. In case an error occurs and a # Iterate in reverse order to process older videos first. In case an error occurs and a
# the playlist must be redownloaded, it will fetch most recent metadata first, and break # the playlist must be redownloaded, it will fetch most recent metadata first, and break
# on the older video that's been processed and is in the download archive. # on the older video that's been processed and is in the download archive.
playlist_videos = self._filter_entry_dicts(entry_dicts, sort_by="playlist_index")
for idx, entry_dict in enumerate(reversed(playlist_videos), start=1): for idx, entry_dict in enumerate(reversed(playlist_videos), start=1):
video = YoutubePlaylistVideo( video = YoutubePlaylistVideo(
entry_dict=entry_dict, working_directory=self.working_directory entry_dict=entry_dict, working_directory=self.working_directory