diff options
| author | Sergey M․ <dstftw@gmail.com> | 2017-02-23 22:01:09 +0700 | 
|---|---|---|
| committer | Sergey M․ <dstftw@gmail.com> | 2017-02-23 22:01:09 +0700 | 
| commit | 89db639dfe02b291bbf901973ca00d6e60fc1dce (patch) | |
| tree | 68ec47ff76659a79834082fdd56077931b719085 | |
| parent | d0d9ade4860fd44a07f5513d13b66233fdca0e89 (diff) | |
[YoutubeDL] Rewrite outtmpl for playlist_index and autonumber for backward compatibility
| -rwxr-xr-x | youtube_dl/YoutubeDL.py | 20 | 
1 files changed, 16 insertions, 4 deletions
| diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index bdaf06e62..fc5e67828 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -594,10 +594,7 @@ class YoutubeDL(object):              autonumber_size = self.params.get('autonumber_size')              if autonumber_size is None:                  autonumber_size = 5 -            autonumber_templ = '%0' + str(autonumber_size) + 'd' -            template_dict['autonumber'] = autonumber_templ % (self.params.get('autonumber_start', 1) - 1 + 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']) +            template_dict['autonumber'] = self.params.get('autonumber_start', 1) - 1 + self._num_downloads              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']) @@ -617,6 +614,20 @@ class YoutubeDL(object):              outtmpl = self.params.get('outtmpl', DEFAULT_OUTTMPL) +            # For fields playlist_index and autonumber convert all occurrences +            # of %(field)s to %(field)0Nd for backward compatibility +            field_size_compat_map = { +                'playlist_index': len(str(template_dict['n_entries'])), +                'autonumber': autonumber_size, +            } +            FIELD_SIZE_COMPAT_RE = r'(?<!%)%\((?P<field>autonumber|playlist_index)\)s' +            mobj = re.search(FIELD_SIZE_COMPAT_RE, outtmpl) +            if mobj: +                outtmpl = re.sub( +                    FIELD_SIZE_COMPAT_RE, +                    r'%%(\1)0%dd' % field_size_compat_map[mobj.group('field')], +                    outtmpl) +              NUMERIC_FIELDS = set((                  'width', 'height', 'tbr', 'abr', 'asr', 'vbr', 'fps', 'filesize', 'filesize_approx',                  'upload_year', 'upload_month', 'upload_day', @@ -624,6 +635,7 @@ class YoutubeDL(object):                  'average_rating', 'comment_count', 'age_limit',                  'start_time', 'end_time',                  'chapter_number', 'season_number', 'episode_number', +                'playlist_index',              ))              # Missing numeric fields used together with integer presentation types | 
