From eccee557b1899abd12dcf66dee837a6ccf1a9f61 Mon Sep 17 00:00:00 2001 From: Glenn Slayden <5589855+glenn-slayden@users.noreply.github.com> Date: Sun, 20 Sep 2020 03:45:10 -0700 Subject: [PATCH] Fix for '--max-downloads' to stop immediately when reaching the limit. Currently, the specifying a limit with `--max-downloads` doesn't cause **youtube-dl** to stop right after it has successfully downloaded that number of files. Instead, it keeps iterating the playlist until another candidate file is found to download, only to then discovers that the limit was previously met. This unnecessary activity can actually take quite a while when a large playlist is already mostly downloaded. This fix adds an additional tail-check on the `_num_downloads` condition so that it terminates immediately after finishing the last eligible file. --- youtube_dl/YoutubeDL.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 19370f62b..ae12f6c3e 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -2002,6 +2002,9 @@ class YoutubeDL(object): self.report_error('postprocessing: %s' % str(err)) return self.record_download_archive(info_dict) + max_downloads = self.params.get('max_downloads') + if max_downloads is not None and self._num_downloads >= int(max_downloads): + raise MaxDownloadsReached() def download(self, url_list): """Download a given list of URLs."""