From cbb393f97cfd276f0da1283efa844f6d95012488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Sat, 18 Apr 2015 03:00:35 +0600 Subject: [PATCH] [YoutubeDL] Merge incompatible formats into mkv (#5456) --- youtube_dl/YoutubeDL.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 4b08fbfed..047887509 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1373,7 +1373,29 @@ class YoutubeDL(object): ' The formats won\'t be merged') else: postprocessors = [merger] - for f in info_dict['requested_formats']: + + def compatible_formats(formats): + video, audio = formats + # Check extension + video_ext, audio_ext = audio.get('ext'), video.get('ext') + if video_ext and audio_ext: + COMPATIBLE_EXTS = ( + ('mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v'), + ('webm') + ) + for exts in COMPATIBLE_EXTS: + if video_ext in exts and audio_ext in exts: + return True + # TODO: Check acodec/vcodec + return False + + requested_formats = info_dict['requested_formats'] + # Merge incompatible formats into mkv + if not compatible_formats(requested_formats): + filename = os.path.splitext(filename)[0] + '.mkv' + self.report_warning('You have requested formats uncompatible for merge. ' + 'The formats will be merged into mkv') + for f in requested_formats: new_info = dict(info_dict) new_info.update(f) fname = self.prepare_filename(new_info)