aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-04-18 03:00:35 +0600
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>2015-04-19 17:55:42 +0200
commit81cd954a512e48fb5cccc3159cd0581088bff0b3 (patch)
tree71d58f2a485ab9f6afa1e1571a6f30494292ea04 /youtube_dl/YoutubeDL.py
parentfeccf29c876869f44a9c983977371073b9801a51 (diff)
downloadyoutube-dl-81cd954a512e48fb5cccc3159cd0581088bff0b3.tar.xz
[YoutubeDL] Merge incompatible formats into mkv (#5456)
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rwxr-xr-xyoutube_dl/YoutubeDL.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index e5d497b3f..5dd9d2430 100755
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -1373,12 +1373,34 @@ class YoutubeDL(object):
' The formats won\'t be merged')
else:
postprocessors = [merger]
+
+ 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')
if os.path.exists(encodeFilename(filename)):
self.to_screen(
'[download] %s has already been downloaded and '
'merged' % filename)
else:
- for f in info_dict['requested_formats']:
+ for f in requested_formats:
new_info = dict(info_dict)
new_info.update(f)
fname = self.prepare_filename(new_info)