Skip to content

Commit

Permalink
[YoutubeDL] Merge incompatible formats into mkv (#5456)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstftw authored and jaimeMF committed Apr 19, 2015
1 parent feccf29 commit 81cd954
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,12 +1373,34 @@ def dl(name, info):
' 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)
Expand Down

0 comments on commit 81cd954

Please sign in to comment.