[cleanup] Deprecate YoutubeDL.parse_outtmpl

This commit is contained in:
pukkandan 2022-06-18 08:25:57 +05:30
parent a70635b8a1
commit bf1824b391
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

View File

@ -669,7 +669,7 @@ def check_deprecated(param, option, suggestion):
'Set the LC_ALL environment variable to fix this.') 'Set the LC_ALL environment variable to fix this.')
self.params['restrictfilenames'] = True 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 # Creating format selector here allows us to catch syntax errors before the extraction
self.format_selector = ( self.format_selector = (
@ -996,21 +996,19 @@ def raise_no_formats(self, info, forced=False, *, msg=None):
self.report_warning(msg) self.report_warning(msg)
def parse_outtmpl(self): def parse_outtmpl(self):
outtmpl_dict = self.params.get('outtmpl', {}) self.deprecation_warning('"YoutubeDL.parse_outtmpl" is deprecated and may be removed in a future version')
if not isinstance(outtmpl_dict, dict): self._parse_outtmpl()
outtmpl_dict = {'default': outtmpl_dict} return self.params['outtmpl']
# Remove spaces in the default template
if self.params.get('restrictfilenames'): 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(' ', '-') sanitize = lambda x: x.replace(' - ', ' ').replace(' ', '-')
else:
sanitize = lambda x: x outtmpl = self.params.setdefault('outtmpl', {})
outtmpl_dict.update({ if not isinstance(outtmpl, dict):
k: sanitize(v) for k, v in DEFAULT_OUTTMPL.items() self.params['outtmpl'] = outtmpl = {'default': outtmpl}
if outtmpl_dict.get(k) is None}) outtmpl.update({k: sanitize(v) for k, v in DEFAULT_OUTTMPL.items() if outtmpl.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
def get_output_path(self, dir_type='', filename=None): def get_output_path(self, dir_type='', filename=None):
paths = self.params.get('paths', {}) 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): def _prepare_filename(self, info_dict, *, outtmpl=None, tmpl_type=None):
assert None in (outtmpl, tmpl_type), 'outtmpl and tmpl_type are mutually exclusive' assert None in (outtmpl, tmpl_type), 'outtmpl and tmpl_type are mutually exclusive'
if outtmpl is None: 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: try:
outtmpl = self._outtmpl_expandpath(outtmpl) outtmpl = self._outtmpl_expandpath(outtmpl)
filename = self.evaluate_outtmpl(outtmpl, info_dict, True) filename = self.evaluate_outtmpl(outtmpl, info_dict, True)
@ -1878,7 +1876,7 @@ def can_merge():
and ( and (
not can_merge() not can_merge()
or info_dict.get('is_live') and not self.params.get('live_from_start') 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 = ( compat = (
prefer_best prefer_best
or self.params.get('allow_multiple_audio_streams', False) or self.params.get('allow_multiple_audio_streams', False)
@ -3224,7 +3222,7 @@ def wrapper(*args, **kwargs):
def download(self, url_list): def download(self, url_list):
"""Download a given list of URLs.""" """Download a given list of URLs."""
url_list = variadic(url_list) # Passing a single URL is a common mistake 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 if (len(url_list) > 1
and outtmpl != '-' and outtmpl != '-'
and '%' not in outtmpl and '%' not in outtmpl