Skip to content

Commit

Permalink
[outtmpl] Handle hard-coded file extension better
Browse files Browse the repository at this point in the history
When we know that the user-provided extension is the correct final one,
replace it with intermediate extension during download
  • Loading branch information
pukkandan committed Feb 1, 2022
1 parent dbcea05 commit 6a0546e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions yt_dlp/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,17 @@ def _prepare_filename(self, info_dict, tmpl_type='default'):
try:
outtmpl = self._outtmpl_expandpath(self.outtmpl_dict.get(tmpl_type, self.outtmpl_dict['default']))
filename = self.evaluate_outtmpl(outtmpl, info_dict, True)
if not filename:
return None

force_ext = OUTTMPL_TYPES.get(tmpl_type)
if filename and force_ext is not None:
filename = replace_extension(filename, force_ext, info_dict.get('ext'))
if tmpl_type in ('default', 'temp'):
final_ext, ext = self.params.get('final_ext'), info_dict.get('ext')
if final_ext and ext and final_ext != ext and filename.endswith(f'.{final_ext}'):
filename = replace_extension(filename, ext, final_ext)
else:
force_ext = OUTTMPL_TYPES[tmpl_type]
if force_ext:
filename = replace_extension(filename, force_ext, info_dict.get('ext'))

# https://github.com/blackjack4494/youtube-dlc/issues/85
trim_file_name = self.params.get('trim_file_name', False)
Expand Down

0 comments on commit 6a0546e

Please sign in to comment.