Skip to content

Commit 6a0546e

Browse files
committed
[outtmpl] Handle hard-coded file extension better
When we know that the user-provided extension is the correct final one, replace it with intermediate extension during download
1 parent dbcea05 commit 6a0546e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

yt_dlp/YoutubeDL.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,10 +1222,17 @@ def _prepare_filename(self, info_dict, tmpl_type='default'):
12221222
try:
12231223
outtmpl = self._outtmpl_expandpath(self.outtmpl_dict.get(tmpl_type, self.outtmpl_dict['default']))
12241224
filename = self.evaluate_outtmpl(outtmpl, info_dict, True)
1225+
if not filename:
1226+
return None
12251227

1226-
force_ext = OUTTMPL_TYPES.get(tmpl_type)
1227-
if filename and force_ext is not None:
1228-
filename = replace_extension(filename, force_ext, info_dict.get('ext'))
1228+
if tmpl_type in ('default', 'temp'):
1229+
final_ext, ext = self.params.get('final_ext'), info_dict.get('ext')
1230+
if final_ext and ext and final_ext != ext and filename.endswith(f'.{final_ext}'):
1231+
filename = replace_extension(filename, ext, final_ext)
1232+
else:
1233+
force_ext = OUTTMPL_TYPES[tmpl_type]
1234+
if force_ext:
1235+
filename = replace_extension(filename, force_ext, info_dict.get('ext'))
12291236

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

0 commit comments

Comments
 (0)