--max-downloads option (Closes #230)
authorPhilipp Hagemeister <phihag@phihag.de>
Sun, 27 Nov 2011 23:55:44 +0000 (00:55 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Sun, 27 Nov 2011 23:55:44 +0000 (00:55 +0100)
README.md
youtube-dl
youtube_dl/__init__.py

index 2b0ab67eba2215b3c4d1f9189d1f2456ee03dad0..1f568e73b0a6ac4025678f3d2d2c596391f67427 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@ which means you can modify it, redistribute it or use it however you like.
                              sub-string)
     --reject-title REGEX     skip download for matching titles (regex or
                              caseless sub-string)
+    --max-downloads NUMBER   Abort after downloading NUMBER files
 
 ### Filesystem Options:
     -t, --title              use title in file name
index ebfb6ae06531def478204f25108b3dc42170dfbe..6dac70b68b0d486bf0d54fa5d630ba8e26452dde 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')
@@ -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)
index 1ce120007a1008ec8b4844a7518643f92c17fdc7..6dac70b68b0d486bf0d54fa5d630ba8e26452dde 100755 (executable)
@@ -14,6 +14,7 @@ __author__  = (
        'Sören Schulze',
        'Kevin Ngo',
        'Ori Avtalion',
+       'shizeeg',
        )
 
 __license__ = 'Public Domain'
@@ -700,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
@@ -3996,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')
@@ -4265,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)