From fa0d62772076210f840998726dfb0822fceeb5fb Mon Sep 17 00:00:00 2001 From: Vladimir Berezhnoy Date: Sat, 26 Nov 2011 23:15:34 +0400 Subject: [PATCH 1/3] Add --max-files option --- youtube-dl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/youtube-dl b/youtube-dl index 1ce120007..b98d3b42a 100755 --- a/youtube-dl +++ b/youtube-dl @@ -701,7 +701,11 @@ class FileDownloader(object): def process_info(self, info_dict): """Process a single dictionary returned by an InfoExtractor.""" 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 if self.params.get('forcetitle', False): print info_dict['title'].encode(preferredencoding(), 'xmlcharrefreplace') @@ -4075,6 +4079,8 @@ def parseOpts(): filesystem.add_option('--write-info-json', action='store_true', dest='writeinfojson', 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, @@ -4265,6 +4271,7 @@ def _real_main(): 'writeinfojson': opts.writeinfojson, 'matchtitle': opts.matchtitle, 'rejecttitle': opts.rejecttitle, + 'max_files': opts.max_files, }) for extractor in extractors: fd.add_info_extractor(extractor) From 1080820b50db0d1bdf351d34b2f69d8f68664851 Mon Sep 17 00:00:00 2001 From: Vladimir Berezhnoy Date: Sun, 27 Nov 2011 19:41:24 +0400 Subject: [PATCH 2/3] fix behavior when max_files not set --- youtube-dl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/youtube-dl b/youtube-dl index b98d3b42a..3f762e528 100755 --- a/youtube-dl +++ b/youtube-dl @@ -702,8 +702,9 @@ class FileDownloader(object): """Process a single dictionary returned by an InfoExtractor.""" filename = self.prepare_filename(info_dict) - # Stop downloading at max_files - if int(self._num_downloads) > int(self.params.get('max_files', 0)): + # Stop downloading at max_files (0 means no limit) + if int(self.params.get('max_files', 0)) != 0 and \ + (int(self._num_downloads) > int(self.params.get('max_files', 0))): return # Forced printings From 353c030b76ca3e4bcd12daf9ba7acb2632808a8e Mon Sep 17 00:00:00 2001 From: Vladimir Berezhnoy Date: Sun, 27 Nov 2011 20:36:27 +0400 Subject: [PATCH 3/3] Rename max-files to max-downloads, improve handling of max_downloads --- youtube-dl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/youtube-dl b/youtube-dl index 3f762e528..93f85d15f 100755 --- a/youtube-dl +++ b/youtube-dl @@ -702,9 +702,9 @@ class FileDownloader(object): """Process a single dictionary returned by an InfoExtractor.""" filename = self.prepare_filename(info_dict) - # Stop downloading at max_files (0 means no limit) - if int(self.params.get('max_files', 0)) != 0 and \ - (int(self._num_downloads) > int(self.params.get('max_files', 0))): + # Stop downloading at max_downloads (negative means no limit) + if int(self.params.get('max_downloads', -1)) >= 0 and \ + int(self._num_downloads) > int(self.params.get('max_downloads', -1)): return # Forced printings @@ -4001,6 +4001,8 @@ def parseOpts(): 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('--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='Maximum number of files to download, -1 means no limit', default=-1) authentication.add_option('-u', '--username', dest='username', metavar='USERNAME', help='account username') @@ -4080,9 +4082,6 @@ def parseOpts(): filesystem.add_option('--write-info-json', action='store_true', dest='writeinfojson', 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, help='convert video files to audio-only files (requires ffmpeg and ffprobe)') @@ -4272,7 +4271,7 @@ def _real_main(): 'writeinfojson': opts.writeinfojson, 'matchtitle': opts.matchtitle, 'rejecttitle': opts.rejecttitle, - 'max_files': opts.max_files, + 'max_downloads': opts.max_downloads, }) for extractor in extractors: fd.add_info_extractor(extractor)