From 124bc071ee8fda22be50f84117f932e875acb6a5 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 5 Aug 2021 19:45:37 +0530 Subject: [PATCH] Fix wrong extension for intermediate files Closes #632 --- yt_dlp/YoutubeDL.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 7461082d7..19fc5bdb6 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -2675,16 +2675,17 @@ class YoutubeDL(object): info_dict['ext'] = 'mkv' self.report_warning( 'Requested formats are incompatible for merge and will be merged into mkv.') + new_ext = info_dict['ext'] - def correct_ext(filename): + def correct_ext(filename, ext=new_ext): if filename == '-': return filename filename_real_ext = os.path.splitext(filename)[1][1:] filename_wo_ext = ( os.path.splitext(filename)[0] - if filename_real_ext == old_ext + if filename_real_ext in (old_ext, new_ext) else filename) - return '%s.%s' % (filename_wo_ext, info_dict['ext']) + return '%s.%s' % (filename_wo_ext, ext) # Ensure filename always has a correct extension for successful merge full_filename = correct_ext(full_filename) @@ -2729,7 +2730,9 @@ class YoutubeDL(object): del new_info['requested_formats'] new_info.update(f) if temp_filename != '-': - fname = prepend_extension(temp_filename, 'f%s' % f['format_id'], new_info['ext']) + fname = prepend_extension( + correct_ext(temp_filename, new_info['ext']), + 'f%s' % f['format_id'], new_info['ext']) if not self._ensure_dir_exists(fname): return downloaded.append(fname)