mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-14 01:05:06 +00:00
[outtmpl] Pad playlist_index
etc even when with internal formatting
Closes #7501
This commit is contained in:
parent
662ef1e910
commit
47bcd43724
2 changed files with 7 additions and 8 deletions
|
@ -684,7 +684,7 @@ def test(tmpl, expected, *, info=None, **params):
|
||||||
test('%(id)s.%(ext)s', '1234.mp4')
|
test('%(id)s.%(ext)s', '1234.mp4')
|
||||||
test('%(duration_string)s', ('27:46:40', '27-46-40'))
|
test('%(duration_string)s', ('27:46:40', '27-46-40'))
|
||||||
test('%(resolution)s', '1080p')
|
test('%(resolution)s', '1080p')
|
||||||
test('%(playlist_index)s', '001')
|
test('%(playlist_index|)s', '001')
|
||||||
test('%(playlist_autonumber)s', '02')
|
test('%(playlist_autonumber)s', '02')
|
||||||
test('%(autonumber)s', '00001')
|
test('%(autonumber)s', '00001')
|
||||||
test('%(autonumber+2)03d', '005', autonumber_start=3)
|
test('%(autonumber+2)03d', '005', autonumber_start=3)
|
||||||
|
|
|
@ -1271,21 +1271,20 @@ def create_key(outer_mobj):
|
||||||
return outer_mobj.group(0)
|
return outer_mobj.group(0)
|
||||||
key = outer_mobj.group('key')
|
key = outer_mobj.group('key')
|
||||||
mobj = re.match(INTERNAL_FORMAT_RE, key)
|
mobj = re.match(INTERNAL_FORMAT_RE, key)
|
||||||
initial_field = mobj.group('fields') if mobj else ''
|
value, replacement, default, last_field = None, None, na, ''
|
||||||
value, replacement, default = None, None, na
|
|
||||||
while mobj:
|
while mobj:
|
||||||
mobj = mobj.groupdict()
|
mobj = mobj.groupdict()
|
||||||
default = mobj['default'] if mobj['default'] is not None else default
|
default = mobj['default'] if mobj['default'] is not None else default
|
||||||
value = get_value(mobj)
|
value = get_value(mobj)
|
||||||
replacement = mobj['replacement']
|
last_field, replacement = mobj['fields'], mobj['replacement']
|
||||||
if value is None and mobj['alternate']:
|
if value is None and mobj['alternate']:
|
||||||
mobj = re.match(INTERNAL_FORMAT_RE, mobj['remaining'][1:])
|
mobj = re.match(INTERNAL_FORMAT_RE, mobj['remaining'][1:])
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
fmt = outer_mobj.group('format')
|
fmt = outer_mobj.group('format')
|
||||||
if fmt == 's' and value is not None and key in field_size_compat_map.keys():
|
if fmt == 's' and value is not None and last_field in field_size_compat_map.keys():
|
||||||
fmt = f'0{field_size_compat_map[key]:d}d'
|
fmt = f'0{field_size_compat_map[last_field]:d}d'
|
||||||
|
|
||||||
if None not in (value, replacement):
|
if None not in (value, replacement):
|
||||||
try:
|
try:
|
||||||
|
@ -1322,7 +1321,7 @@ def create_key(outer_mobj):
|
||||||
value = format_decimal_suffix(value, f'%{num_fmt}f%s' if num_fmt else '%d%s',
|
value = format_decimal_suffix(value, f'%{num_fmt}f%s' if num_fmt else '%d%s',
|
||||||
factor=1024 if '#' in flags else 1000)
|
factor=1024 if '#' in flags else 1000)
|
||||||
elif fmt[-1] == 'S': # filename sanitization
|
elif fmt[-1] == 'S': # filename sanitization
|
||||||
value, fmt = filename_sanitizer(initial_field, value, restricted='#' in flags), str_fmt
|
value, fmt = filename_sanitizer(last_field, value, restricted='#' in flags), str_fmt
|
||||||
elif fmt[-1] == 'c':
|
elif fmt[-1] == 'c':
|
||||||
if value:
|
if value:
|
||||||
value = str(value)[0]
|
value = str(value)[0]
|
||||||
|
@ -1341,7 +1340,7 @@ def create_key(outer_mobj):
|
||||||
elif fmt[-1] == 'a':
|
elif fmt[-1] == 'a':
|
||||||
value, fmt = ascii(value), str_fmt
|
value, fmt = ascii(value), str_fmt
|
||||||
if fmt[-1] in 'csra':
|
if fmt[-1] in 'csra':
|
||||||
value = sanitizer(initial_field, value)
|
value = sanitizer(last_field, value)
|
||||||
|
|
||||||
key = '%s\0%s' % (key.replace('%', '%\0'), outer_mobj.group('format'))
|
key = '%s\0%s' % (key.replace('%', '%\0'), outer_mobj.group('format'))
|
||||||
TMPL_DICT[key] = value
|
TMPL_DICT[key] = value
|
||||||
|
|
Loading…
Reference in a new issue