Document -o %(upload_date)s (Closes #228)
[youtube-dl.git] / youtube-dl
index ebfb6ae..63ad30f 100755 (executable)
@@ -701,6 +701,13 @@ class FileDownloader(object):
 
        def process_info(self, info_dict):
                """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)
                
                # Forced printings
@@ -3997,6 +4004,7 @@ 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='Abort after downloading NUMBER files', default=None)
 
        authentication.add_option('-u', '--username',
                        dest='username', metavar='USERNAME', help='account username')
@@ -4053,7 +4061,7 @@ def parseOpts():
                        action='store_true', dest='autonumber',
                        help='number downloaded files starting from 00000', default=False)
        filesystem.add_option('-o', '--output',
-                       dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(stitle)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, and %% for a literal percent')
+                       dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(stitle)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), and %% for a literal percent')
        filesystem.add_option('-a', '--batch-file',
                        dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)')
        filesystem.add_option('-w', '--no-overwrites',
@@ -4266,6 +4274,7 @@ def _real_main():
                'writeinfojson': opts.writeinfojson,
                'matchtitle': opts.matchtitle,
                'rejecttitle': opts.rejecttitle,
+               'max_downloads': int(opts.max_downloads),
                })
        for extractor in extractors:
                fd.add_info_extractor(extractor)