X-Git-Url: https://git.jankratochvil.net/?a=blobdiff_plain;f=youtube-dl;h=d7e9c50c0076016d2dcabfec86d49c8cdab1b04e;hb=f1f300e629de62bcda925ea93eeed8191b80edb3;hp=1ce120007a1008ec8b4844a7518643f92c17fdc7;hpb=849edab8ec4fed42f131285b66235b26c78a2d1a;p=youtube-dl.git diff --git a/youtube-dl b/youtube-dl index 1ce1200..d7e9c50 100755 --- a/youtube-dl +++ b/youtube-dl @@ -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 = self.params.get('max_downloads') + if max_downloads is not None: + if self._num_downloads > int(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 @@ -3916,6 +3924,20 @@ def parseOpts(): # Deferred imports import getpass import optparse + import shlex + + def _readOptions(filename): + try: + optionf = open(filename) + except IOError: + return [] # silently skip if file is not present + try: + res = [] + for l in optionf: + res += shlex.split(l, comments=True) + finally: + optionf.close() + return res def _format_option_string(option): ''' ('-o', '--option') -> -o, --format METAVAR''' @@ -3996,6 +4018,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') @@ -4052,7 +4075,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', @@ -4095,7 +4118,8 @@ def parseOpts(): parser.add_option_group(authentication) parser.add_option_group(postproc) - opts, args = parser.parse_args() + argv = _readOptions('/etc/youtube-dl.conf') + _readOptions(os.path.expanduser('~/.youtube-dl.conf')) + sys.argv[1:] + opts, args = parser.parse_args(argv) return parser, opts, args @@ -4265,6 +4289,7 @@ def _real_main(): 'writeinfojson': opts.writeinfojson, 'matchtitle': opts.matchtitle, 'rejecttitle': opts.rejecttitle, + 'max_downloads': opts.max_downloads, }) for extractor in extractors: fd.add_info_extractor(extractor)