diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index fe30758ef..935857267 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -192,6 +192,7 @@ class YoutubeDL(object): keepvideo: Keep the video file after post-processing daterange: A DateRange object, download only if the upload_date is in the range. skip_download: Skip the actual download of the video file + autonumber_reset: Reset autonumber counter to autonumber-start before each playlist cachedir: Location of the cache files in the filesystem. False to disable filesystem cache. noplaylist: Download single video instead of a playlist if in doubt. @@ -339,6 +340,7 @@ class YoutubeDL(object): _pps = [] _download_retcode = None _num_downloads = None + _autonumber_index = None _playlist_level = 0 _playlist_urls = set() _screen_file = None @@ -353,6 +355,7 @@ class YoutubeDL(object): self._progress_hooks = [] self._download_retcode = 0 self._num_downloads = 0 + self._autonumber_index = 0 self._screen_file = [sys.stdout, sys.stderr][params.get('logtostderr', False)] self._err_file = sys.stderr self.params = { @@ -643,7 +646,7 @@ class YoutubeDL(object): autonumber_size = self.params.get('autonumber_size') if autonumber_size is None: autonumber_size = 5 - template_dict['autonumber'] = self.params.get('autonumber_start', 1) - 1 + self._num_downloads + template_dict['autonumber'] = self.params.get('autonumber_start', 1) - 1 + self._autonumber_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']) @@ -965,6 +968,9 @@ class YoutubeDL(object): self.to_screen('[download] Downloading playlist: %s' % playlist) + if self.params.get('autonumber_reset'): + self._autonumber_index = 0 + playlist_results = [] playliststart = self.params.get('playliststart', 1) - 1 @@ -1795,6 +1801,7 @@ class YoutubeDL(object): return self._num_downloads += 1 + self._autonumber_index += 1 info_dict['_filename'] = filename = self.prepare_filename(info_dict) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index e1bd67919..cbea3037e 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -343,6 +343,7 @@ def _real_main(argv=None): 'outtmpl_na_placeholder': opts.outtmpl_na_placeholder, 'autonumber_size': opts.autonumber_size, 'autonumber_start': opts.autonumber_start, + 'autonumber_reset': opts.autonumber_reset, '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 0a0641bd4..781d54409 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -709,6 +709,10 @@ def parseOpts(overrideArguments=None): '-A', '--auto-number', action='store_true', dest='autonumber', default=False, help=optparse.SUPPRESS_HELP) + filesystem.add_option( + '--autonumber-reset', + action='store_true', dest='autonumber_reset', default=False, + help='Reset %(autonumber)s counter to %(autonumber_start)s before each playlist') filesystem.add_option( '-t', '--title', action='store_true', dest='usetitle', default=False,