Skip to content

Commit

Permalink
[core] Make --max-downloads ... stop immediately on reaching the limit
Browse files Browse the repository at this point in the history
Based on and closes #26638.
  • Loading branch information
dirkf committed Aug 10, 2022
1 parent deee741 commit e6a836d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1779,10 +1779,9 @@ def process_info(self, info_dict):

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']
Expand Down Expand Up @@ -2062,6 +2061,9 @@ def compatible_formats(formats):
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."""
Expand Down

0 comments on commit e6a836d

Please sign in to comment.