1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-29 19:47:54 +01:00

--max-downloads option (Closes #230)

This commit is contained in:
Philipp Hagemeister 2011-11-28 00:55:44 +01:00
parent a95567af99
commit b88a52504e
3 changed files with 20 additions and 0 deletions

View File

@ -28,6 +28,7 @@ which means you can modify it, redistribute it or use it however you like.
sub-string) sub-string)
--reject-title REGEX skip download for matching titles (regex or --reject-title REGEX skip download for matching titles (regex or
caseless sub-string) caseless sub-string)
--max-downloads NUMBER Abort after downloading NUMBER files
### Filesystem Options: ### Filesystem Options:
-t, --title use title in file name -t, --title use title in file name

View File

@ -701,6 +701,13 @@ class FileDownloader(object):
def process_info(self, info_dict): def process_info(self, info_dict):
"""Process a single dictionary returned by an InfoExtractor.""" """Process a single dictionary returned by an InfoExtractor."""
max_downloads = int(self.params.get('max_downloads'))
if max_downloads is not None:
if self._num_downloads > max_downloads:
self.to_screen(u'[download] Maximum number of downloads reached. Skipping ' + info_dict['title'])
return
filename = self.prepare_filename(info_dict) filename = self.prepare_filename(info_dict)
# Forced printings # Forced printings
@ -3997,6 +4004,7 @@ def parseOpts():
dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1) dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1)
selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)') selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)')
selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)') selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)')
selection.add_option('--max-downloads', metavar='NUMBER', dest='max_downloads', help='Abort after downloading NUMBER files', default=None)
authentication.add_option('-u', '--username', authentication.add_option('-u', '--username',
dest='username', metavar='USERNAME', help='account username') dest='username', metavar='USERNAME', help='account username')
@ -4266,6 +4274,7 @@ def _real_main():
'writeinfojson': opts.writeinfojson, 'writeinfojson': opts.writeinfojson,
'matchtitle': opts.matchtitle, 'matchtitle': opts.matchtitle,
'rejecttitle': opts.rejecttitle, 'rejecttitle': opts.rejecttitle,
'max_downloads': int(opts.max_downloads),
}) })
for extractor in extractors: for extractor in extractors:
fd.add_info_extractor(extractor) fd.add_info_extractor(extractor)

View File

@ -14,6 +14,7 @@ __author__ = (
'Sören Schulze', 'Sören Schulze',
'Kevin Ngo', 'Kevin Ngo',
'Ori Avtalion', 'Ori Avtalion',
'shizeeg',
) )
__license__ = 'Public Domain' __license__ = 'Public Domain'
@ -700,6 +701,13 @@ class FileDownloader(object):
def process_info(self, info_dict): def process_info(self, info_dict):
"""Process a single dictionary returned by an InfoExtractor.""" """Process a single dictionary returned by an InfoExtractor."""
max_downloads = int(self.params.get('max_downloads'))
if max_downloads is not None:
if self._num_downloads > max_downloads:
self.to_screen(u'[download] Maximum number of downloads reached. Skipping ' + info_dict['title'])
return
filename = self.prepare_filename(info_dict) filename = self.prepare_filename(info_dict)
# Forced printings # Forced printings
@ -3996,6 +4004,7 @@ def parseOpts():
dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1) dest='playlistend', metavar='NUMBER', help='playlist video to end at (default is last)', default=-1)
selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)') selection.add_option('--match-title', dest='matchtitle', metavar='REGEX',help='download only matching titles (regex or caseless sub-string)')
selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)') selection.add_option('--reject-title', dest='rejecttitle', metavar='REGEX',help='skip download for matching titles (regex or caseless sub-string)')
selection.add_option('--max-downloads', metavar='NUMBER', dest='max_downloads', help='Abort after downloading NUMBER files', default=None)
authentication.add_option('-u', '--username', authentication.add_option('-u', '--username',
dest='username', metavar='USERNAME', help='account username') dest='username', metavar='USERNAME', help='account username')
@ -4265,6 +4274,7 @@ def _real_main():
'writeinfojson': opts.writeinfojson, 'writeinfojson': opts.writeinfojson,
'matchtitle': opts.matchtitle, 'matchtitle': opts.matchtitle,
'rejecttitle': opts.rejecttitle, 'rejecttitle': opts.rejecttitle,
'max_downloads': int(opts.max_downloads),
}) })
for extractor in extractors: for extractor in extractors:
fd.add_info_extractor(extractor) fd.add_info_extractor(extractor)