about summary refs log tree commit diff
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2022-08-10 15:37:59 +0100
committerdirkf <fieldhouse@gmx.net>2022-08-10 15:37:59 +0100
commite6a836d54ca1d3cd02f3ee45ef707a46f23e8291 (patch)
tree6ea2cee5bfe03002cbf4c71c3a5c8b25211d4b4d /youtube_dl/YoutubeDL.py
parentdeee741fb145360576ceae9d69b1b43db082c404 (diff)
downloadyoutube-dl-e6a836d54ca1d3cd02f3ee45ef707a46f23e8291.tar.gz
youtube-dl-e6a836d54ca1d3cd02f3ee45ef707a46f23e8291.tar.xz
youtube-dl-e6a836d54ca1d3cd02f3ee45ef707a46f23e8291.zip
[core] Make `--max-downloads ...` stop immediately on reaching the limit
Based on and closes #26638.
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rwxr-xr-xyoutube_dl/YoutubeDL.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index 3895b408f..e77b8d50c 100755
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -1779,10 +1779,9 @@ class YoutubeDL(object):
 
         assert info_dict.get('_type', 'video') == 'video'
 
-        max_downloads = self.params.get('max_downloads')
-        if max_downloads is not None:
-            if self._num_downloads >= int(max_downloads):
-                raise MaxDownloadsReached()
+        max_downloads = int_or_none(self.params.get('max_downloads')) or float('inf')
+        if self._num_downloads >= max_downloads:
+            raise MaxDownloadsReached()
 
         # TODO: backward compatibility, to be removed
         info_dict['fulltitle'] = info_dict['title']
@@ -2062,6 +2061,9 @@ class YoutubeDL(object):
                     self.report_error('postprocessing: %s' % str(err))
                     return
                 self.record_download_archive(info_dict)
+                # avoid possible nugatory search for further items (PR #26638)
+                if self._num_downloads >= max_downloads:
+                    raise MaxDownloadsReached()
 
     def download(self, url_list):
         """Download a given list of URLs."""