From 39fe0f30895e7e318dcfbe5b5f16c2ec4c35fd5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9-Patrick=20Bubel?= Date: Mon, 27 Jun 2016 23:41:58 +0200 Subject: [PATCH] Add --playlist-index-size option It works similarly to the --autonumber-size option, i.e. it determines the length of the '%(playlist_index)s' format string, with '0' as padding. When it isn't specified it works like before, i.e. the size is determined from the number of entries to download. --- youtube_dl/YoutubeDL.py | 5 ++++- youtube_dl/__init__.py | 1 + youtube_dl/options.py | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 5036289b0..1afc26621 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -568,7 +568,10 @@ class YoutubeDL(object): autonumber_templ = '%0' + str(autonumber_size) + 'd' template_dict['autonumber'] = autonumber_templ % self._num_downloads if template_dict.get('playlist_index') is not None: - template_dict['playlist_index'] = '%0*d' % (len(str(template_dict['n_entries'])), template_dict['playlist_index']) + playlist_index_size = self.params.get('playlist_index_size') + if playlist_index_size is None: + playlist_index_size = len(str(template_dict['n_entries'])) + template_dict['playlist_index'] = '%0*d' % (int(playlist_index_size), template_dict['playlist_index']) if template_dict.get('resolution') is None: if template_dict.get('width') and template_dict.get('height'): template_dict['resolution'] = '%dx%d' % (template_dict['width'], template_dict['height']) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 4905674ad..fb2381dd3 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -301,6 +301,7 @@ def _real_main(argv=None): 'listformats': opts.listformats, 'outtmpl': outtmpl, 'autonumber_size': opts.autonumber_size, + 'playlist_index_size': opts.playlist_index_size, 'restrictfilenames': opts.restrictfilenames, 'ignoreerrors': opts.ignoreerrors, 'force_generic_extractor': opts.force_generic_extractor, diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 99ce4131f..7401d8e52 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -619,6 +619,10 @@ def parseOpts(overrideArguments=None): '--autonumber-size', dest='autonumber_size', metavar='NUMBER', help='Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given') + filesystem.add_option( + '--playlist-index-size', + dest='playlist_index_size', metavar='NUMBER', + help='Specify the number of digits in %(playlist_index)s when it is present in output filename template') filesystem.add_option( '--restrict-filenames', action='store_true', dest='restrictfilenames', default=False,