[FOLLOWUP] Actually process YT channels and playlists ascending (#160)
* actually sort * use playlist_index instead
This commit is contained in:
parent
8033b1a44c
commit
47a46265cf
3 changed files with 14 additions and 6 deletions
|
|
@ -213,7 +213,10 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT]
|
|||
)
|
||||
|
||||
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]:
|
||||
"""
|
||||
Parameters
|
||||
|
|
@ -223,6 +226,8 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT]
|
|||
extractor
|
||||
Optional. Extractor that the entry dicts must have. If None, defaults to the
|
||||
entry type's extractor
|
||||
sort_by
|
||||
Optional. Sort the entry dicts on this key
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -231,9 +236,12 @@ class Downloader(DownloadArchiver, Generic[DownloaderOptionsT, DownloaderEntryT]
|
|||
if extractor is None:
|
||||
extractor = self.downloader_entry_type.entry_extractor
|
||||
|
||||
return [
|
||||
output = [
|
||||
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]:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -150,9 +150,9 @@ class YoutubeChannelDownloader(YoutubeDownloader[YoutubeChannelDownloaderOptions
|
|||
url=self.download_options.channel_url,
|
||||
)
|
||||
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
|
||||
# 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):
|
||||
|
|
|
|||
|
|
@ -78,11 +78,11 @@ class YoutubePlaylistDownloader(
|
|||
log_prefix_on_info_json_dl="Downloading metadata for",
|
||||
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
|
||||
# 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):
|
||||
video = YoutubePlaylistVideo(
|
||||
entry_dict=entry_dict, working_directory=self.working_directory
|
||||
|
|
|
|||
Loading…
Reference in a new issue