mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-07-09 14:58:32 +00:00
Refactor
This commit is contained in:
parent
a6068e695c
commit
200d27682d
@ -720,7 +720,7 @@ def test(tmpl, expected, *, info=None, **params):
|
||||
ydl._num_downloads = 1
|
||||
self.assertEqual(ydl.validate_outtmpl(tmpl), None)
|
||||
|
||||
out = ydl.evaluate_outtmpl_for_filename(tmpl, info or self.outtmpl_info)
|
||||
out = ydl.evaluate_outtmpl(tmpl, info or self.outtmpl_info, trim_filename=True)
|
||||
fname = ydl.prepare_filename(info or self.outtmpl_info)
|
||||
|
||||
if not isinstance(expected, (list, tuple)):
|
||||
|
@ -1425,12 +1425,11 @@ def create_key(outer_mobj):
|
||||
|
||||
return EXTERNAL_FORMAT_RE.sub(create_key, outtmpl), TMPL_DICT
|
||||
|
||||
def evaluate_outtmpl(self, outtmpl, info_dict, *args, **kwargs):
|
||||
def evaluate_outtmpl(self, outtmpl, info_dict, *args, trim_filename=False, **kwargs):
|
||||
outtmpl, info_dict = self.prepare_outtmpl(outtmpl, info_dict, *args, **kwargs)
|
||||
return self.escape_outtmpl(outtmpl) % info_dict
|
||||
if not trim_filename:
|
||||
return self.escape_outtmpl(outtmpl) % info_dict
|
||||
|
||||
def evaluate_outtmpl_for_filename(self, outtmpl, info_dict, *args, **kwargs):
|
||||
outtmpl, info_dict = self.prepare_outtmpl(outtmpl, info_dict, *args, **kwargs)
|
||||
ext_suffix = '.%(ext\x00s)s' # not sure why this has null char
|
||||
suffix = ''
|
||||
if outtmpl.endswith(ext_suffix):
|
||||
@ -1491,7 +1490,7 @@ def _prepare_filename(self, info_dict, *, outtmpl=None, tmpl_type=None):
|
||||
outtmpl = self.params['outtmpl'].get(tmpl_type or 'default', self.params['outtmpl']['default'])
|
||||
try:
|
||||
outtmpl = self._outtmpl_expandpath(outtmpl)
|
||||
filename = self.evaluate_outtmpl_for_filename(outtmpl, info_dict, True)
|
||||
filename = self.evaluate_outtmpl(outtmpl, info_dict, True, trim_filename=True)
|
||||
if not filename:
|
||||
return None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user