|
|
|
@ -1271,21 +1271,20 @@ class YoutubeDL:
|
|
|
|
|
return outer_mobj.group(0)
|
|
|
|
|
key = outer_mobj.group('key')
|
|
|
|
|
mobj = re.match(INTERNAL_FORMAT_RE, key)
|
|
|
|
|
initial_field = mobj.group('fields') if mobj else ''
|
|
|
|
|
value, replacement, default = None, None, na
|
|
|
|
|
value, replacement, default, last_field = None, None, na, ''
|
|
|
|
|
while mobj:
|
|
|
|
|
mobj = mobj.groupdict()
|
|
|
|
|
default = mobj['default'] if mobj['default'] is not None else default
|
|
|
|
|
value = get_value(mobj)
|
|
|
|
|
replacement = mobj['replacement']
|
|
|
|
|
last_field, replacement = mobj['fields'], mobj['replacement']
|
|
|
|
|
if value is None and mobj['alternate']:
|
|
|
|
|
mobj = re.match(INTERNAL_FORMAT_RE, mobj['remaining'][1:])
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
fmt = outer_mobj.group('format')
|
|
|
|
|
if fmt == 's' and value is not None and key in field_size_compat_map.keys():
|
|
|
|
|
fmt = f'0{field_size_compat_map[key]:d}d'
|
|
|
|
|
if fmt == 's' and value is not None and last_field in field_size_compat_map.keys():
|
|
|
|
|
fmt = f'0{field_size_compat_map[last_field]:d}d'
|
|
|
|
|
|
|
|
|
|
if None not in (value, replacement):
|
|
|
|
|
try:
|
|
|
|
@ -1322,7 +1321,7 @@ class YoutubeDL:
|
|
|
|
|
value = format_decimal_suffix(value, f'%{num_fmt}f%s' if num_fmt else '%d%s',
|
|
|
|
|
factor=1024 if '#' in flags else 1000)
|
|
|
|
|
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':
|
|
|
|
|
if value:
|
|
|
|
|
value = str(value)[0]
|
|
|
|
@ -1341,7 +1340,7 @@ class YoutubeDL:
|
|
|
|
|
elif fmt[-1] == 'a':
|
|
|
|
|
value, fmt = ascii(value), str_fmt
|
|
|
|
|
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'))
|
|
|
|
|
TMPL_DICT[key] = value
|
|
|
|
|