mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 18:32:39 +00:00
[cleanup] Deprecate YoutubeDL.parse_outtmpl
This commit is contained in:
parent
a70635b8a1
commit
bf1824b391
@ -669,7 +669,7 @@ def check_deprecated(param, option, suggestion):
|
||||
'Set the LC_ALL environment variable to fix this.')
|
||||
self.params['restrictfilenames'] = True
|
||||
|
||||
self.outtmpl_dict = self.parse_outtmpl()
|
||||
self._parse_outtmpl()
|
||||
|
||||
# Creating format selector here allows us to catch syntax errors before the extraction
|
||||
self.format_selector = (
|
||||
@ -996,21 +996,19 @@ def raise_no_formats(self, info, forced=False, *, msg=None):
|
||||
self.report_warning(msg)
|
||||
|
||||
def parse_outtmpl(self):
|
||||
outtmpl_dict = self.params.get('outtmpl', {})
|
||||
if not isinstance(outtmpl_dict, dict):
|
||||
outtmpl_dict = {'default': outtmpl_dict}
|
||||
# Remove spaces in the default template
|
||||
if self.params.get('restrictfilenames'):
|
||||
self.deprecation_warning('"YoutubeDL.parse_outtmpl" is deprecated and may be removed in a future version')
|
||||
self._parse_outtmpl()
|
||||
return self.params['outtmpl']
|
||||
|
||||
def _parse_outtmpl(self):
|
||||
sanitize = lambda x: x
|
||||
if self.params.get('restrictfilenames'): # Remove spaces in the default template
|
||||
sanitize = lambda x: x.replace(' - ', ' ').replace(' ', '-')
|
||||
else:
|
||||
sanitize = lambda x: x
|
||||
outtmpl_dict.update({
|
||||
k: sanitize(v) for k, v in DEFAULT_OUTTMPL.items()
|
||||
if outtmpl_dict.get(k) is None})
|
||||
for _, val in outtmpl_dict.items():
|
||||
if isinstance(val, bytes):
|
||||
self.report_warning('Parameter outtmpl is bytes, but should be a unicode string')
|
||||
return outtmpl_dict
|
||||
|
||||
outtmpl = self.params.setdefault('outtmpl', {})
|
||||
if not isinstance(outtmpl, dict):
|
||||
self.params['outtmpl'] = outtmpl = {'default': outtmpl}
|
||||
outtmpl.update({k: sanitize(v) for k, v in DEFAULT_OUTTMPL.items() if outtmpl.get(k) is None})
|
||||
|
||||
def get_output_path(self, dir_type='', filename=None):
|
||||
paths = self.params.get('paths', {})
|
||||
@ -1248,7 +1246,7 @@ def evaluate_outtmpl(self, outtmpl, info_dict, *args, **kwargs):
|
||||
def _prepare_filename(self, info_dict, *, outtmpl=None, tmpl_type=None):
|
||||
assert None in (outtmpl, tmpl_type), 'outtmpl and tmpl_type are mutually exclusive'
|
||||
if outtmpl is None:
|
||||
outtmpl = self.outtmpl_dict.get(tmpl_type or 'default', self.outtmpl_dict['default'])
|
||||
outtmpl = self.params['outtmpl'].get(tmpl_type or 'default', self.params['outtmpl']['default'])
|
||||
try:
|
||||
outtmpl = self._outtmpl_expandpath(outtmpl)
|
||||
filename = self.evaluate_outtmpl(outtmpl, info_dict, True)
|
||||
@ -1878,7 +1876,7 @@ def can_merge():
|
||||
and (
|
||||
not can_merge()
|
||||
or info_dict.get('is_live') and not self.params.get('live_from_start')
|
||||
or self.outtmpl_dict['default'] == '-'))
|
||||
or self.params['outtmpl']['default'] == '-'))
|
||||
compat = (
|
||||
prefer_best
|
||||
or self.params.get('allow_multiple_audio_streams', False)
|
||||
@ -3224,7 +3222,7 @@ def wrapper(*args, **kwargs):
|
||||
def download(self, url_list):
|
||||
"""Download a given list of URLs."""
|
||||
url_list = variadic(url_list) # Passing a single URL is a common mistake
|
||||
outtmpl = self.outtmpl_dict['default']
|
||||
outtmpl = self.params['outtmpl']['default']
|
||||
if (len(url_list) > 1
|
||||
and outtmpl != '-'
|
||||
and '%' not in outtmpl
|
||||
|
Loading…
Reference in New Issue
Block a user