1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-03 21:55:34 +08:00

Add --max-files option

This commit is contained in:
Vladimir Berezhnoy 2011-11-26 23:15:34 +04:00
parent 849edab8ec
commit fa0d627720

View File

@ -702,6 +702,10 @@ class FileDownloader(object):
"""Process a single dictionary returned by an InfoExtractor.""" """Process a single dictionary returned by an InfoExtractor."""
filename = self.prepare_filename(info_dict) filename = self.prepare_filename(info_dict)
# Stop downloading at max_files
if int(self._num_downloads) > int(self.params.get('max_files', 0)):
return
# Forced printings # Forced printings
if self.params.get('forcetitle', False): if self.params.get('forcetitle', False):
print info_dict['title'].encode(preferredencoding(), 'xmlcharrefreplace') print info_dict['title'].encode(preferredencoding(), 'xmlcharrefreplace')
@ -4075,6 +4079,8 @@ def parseOpts():
filesystem.add_option('--write-info-json', filesystem.add_option('--write-info-json',
action='store_true', dest='writeinfojson', action='store_true', dest='writeinfojson',
help='write video metadata to a .info.json file', default=False) help='write video metadata to a .info.json file', default=False)
filesystem.add_option('--max-files',
dest='max_files', help='Maximum number of files to download', default=0)
postproc.add_option('--extract-audio', action='store_true', dest='extractaudio', default=False, postproc.add_option('--extract-audio', action='store_true', dest='extractaudio', default=False,
@ -4265,6 +4271,7 @@ def _real_main():
'writeinfojson': opts.writeinfojson, 'writeinfojson': opts.writeinfojson,
'matchtitle': opts.matchtitle, 'matchtitle': opts.matchtitle,
'rejecttitle': opts.rejecttitle, 'rejecttitle': opts.rejecttitle,
'max_files': opts.max_files,
}) })
for extractor in extractors: for extractor in extractors:
fd.add_info_extractor(extractor) fd.add_info_extractor(extractor)