[YoutubeDL] Ensure correct extension is always present for a merged file (Closes...
authorSergey M․ <dstftw@gmail.com>
Sat, 2 May 2015 16:52:21 +0000 (22:52 +0600)
committerSergey M․ <dstftw@gmail.com>
Sat, 2 May 2015 16:52:21 +0000 (22:52 +0600)
youtube_dl/YoutubeDL.py

index 55b429f31ac3f4b1d6908f428beab4e0829d0d3c..eaa436bf9a34029402c801784f4696b869fc035b 100755 (executable)
@@ -1382,11 +1382,18 @@ class YoutubeDL(object):
                         # TODO: Check acodec/vcodec
                         return False
 
+                    filename_real_ext = os.path.splitext(filename)[1][1:]
+                    filename_wo_ext = (
+                        os.path.splitext(filename)[0]
+                        if filename_real_ext == info_dict['ext']
+                        else filename)
                     requested_formats = info_dict['requested_formats']
                     if self.params.get('merge_output_format') is None and not compatible_formats(requested_formats):
-                        filename = os.path.splitext(filename)[0] + '.mkv'
+                        info_dict['ext'] = 'mkv'
                         self.report_warning('You have requested formats incompatible for merge. '
                                             'The formats will be merged into mkv')
+                    # Ensure filename always has a correct extension for successful merge
+                    filename = '%s.%s' % (filename_wo_ext, info_dict['ext'])
                     if os.path.exists(encodeFilename(filename)):
                         self.to_screen(
                             '[download] %s has already been downloaded and '