mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 18:34:41 +01:00
[outtmpl] Fix bug in expanding environment variables
This commit is contained in:
parent
c111cefa5d
commit
b836dc94f2
@ -817,6 +817,12 @@ def gen():
|
|||||||
compat_setenv('__yt_dlp_var', 'expanded')
|
compat_setenv('__yt_dlp_var', 'expanded')
|
||||||
envvar = '%__yt_dlp_var%' if compat_os_name == 'nt' else '$__yt_dlp_var'
|
envvar = '%__yt_dlp_var%' if compat_os_name == 'nt' else '$__yt_dlp_var'
|
||||||
test(envvar, (envvar, 'expanded'))
|
test(envvar, (envvar, 'expanded'))
|
||||||
|
if compat_os_name == 'nt':
|
||||||
|
test('%s%', ('%s%', '%s%'))
|
||||||
|
compat_setenv('s', 'expanded')
|
||||||
|
test('%s%', ('%s%', 'expanded')) # %s% should be expanded before escaping %s
|
||||||
|
compat_setenv('(test)s', 'expanded')
|
||||||
|
test('%(test)s%', ('NA%', 'expanded')) # Environment should take priority over template
|
||||||
|
|
||||||
# Path expansion and escaping
|
# Path expansion and escaping
|
||||||
test('Hello %(title1)s', 'Hello $PATH')
|
test('Hello %(title1)s', 'Hello $PATH')
|
||||||
|
@ -1034,7 +1034,7 @@ def _dumpjson_default(obj):
|
|||||||
|
|
||||||
def create_key(outer_mobj):
|
def create_key(outer_mobj):
|
||||||
if not outer_mobj.group('has_key'):
|
if not outer_mobj.group('has_key'):
|
||||||
return f'%{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').split('.')[-1] if mobj else ''
|
initial_field = mobj.group('fields').split('.')[-1] if mobj else ''
|
||||||
@ -1105,10 +1105,8 @@ def _prepare_filename(self, info_dict, tmpl_type='default'):
|
|||||||
compat_str(v),
|
compat_str(v),
|
||||||
restricted=self.params.get('restrictfilenames'),
|
restricted=self.params.get('restrictfilenames'),
|
||||||
is_id=(k == 'id' or k.endswith('_id')))
|
is_id=(k == 'id' or k.endswith('_id')))
|
||||||
outtmpl = self.outtmpl_dict.get(tmpl_type, self.outtmpl_dict['default'])
|
outtmpl = self._outtmpl_expandpath(self.outtmpl_dict.get(tmpl_type, self.outtmpl_dict['default']))
|
||||||
outtmpl, template_dict = self.prepare_outtmpl(outtmpl, info_dict, sanitize)
|
filename = self.evaluate_outtmpl(outtmpl, info_dict, sanitize)
|
||||||
outtmpl = self.escape_outtmpl(self._outtmpl_expandpath(outtmpl))
|
|
||||||
filename = outtmpl % template_dict
|
|
||||||
|
|
||||||
force_ext = OUTTMPL_TYPES.get(tmpl_type)
|
force_ext = OUTTMPL_TYPES.get(tmpl_type)
|
||||||
if filename and force_ext is not None:
|
if filename and force_ext is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user