actually sort

This commit is contained in:
jbannon 2022-08-07 05:08:17 +00:00
parent 8033b1a44c
commit 8c01c473cc
3 changed files with 12 additions and 4 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,7 +150,7 @@ 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="upload_date")
# Iterate in reverse to process older videos first. In case an error occurs and a # Iterate in reverse 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

View file

@ -78,7 +78,7 @@ 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) playlist_videos = self._filter_entry_dicts(entry_dicts, sort_by="upload_date")
# Iterate in reverse to process older videos first. In case an error occurs and a # Iterate in reverse 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