add support for merging multiple audios

This commit is contained in:
remitamine 2015-08-02 15:19:39 +01:00
parent 3f125c8c70
commit ed9bd32a46
2 changed files with 13 additions and 14 deletions

View File

@ -1120,11 +1120,9 @@ class YoutubeDL(object):
# the first that is available, starting from left # the first that is available, starting from left
req_formats = rfstr.split('/') req_formats = rfstr.split('/')
for rf in req_formats: for rf in req_formats:
if re.match(r'.+?\+.+?', rf) is not None: if '+' in rf:
# Two formats have been requested like '137+139' # Two formats have been requested like '137+139'
format_1, format_2 = rf.split('+') formats_info = [self.select_format(selected_format, formats) for selected_format in rf.split('+')]
formats_info = (self.select_format(format_1, formats),
self.select_format(format_2, formats))
if all(formats_info): if all(formats_info):
# The first format must contain the video and the # The first format must contain the video and the
# second the audio # second the audio
@ -1139,10 +1137,8 @@ class YoutubeDL(object):
else self.params['merge_output_format']) else self.params['merge_output_format'])
selected_format = { selected_format = {
'requested_formats': formats_info, 'requested_formats': formats_info,
'format': '%s+%s' % (formats_info[0].get('format'), 'format': rf,
formats_info[1].get('format')), 'format_id': rf,
'format_id': '%s+%s' % (formats_info[0].get('format_id'),
formats_info[1].get('format_id')),
'width': formats_info[0].get('width'), 'width': formats_info[0].get('width'),
'height': formats_info[0].get('height'), 'height': formats_info[0].get('height'),
'resolution': formats_info[0].get('resolution'), 'resolution': formats_info[0].get('resolution'),
@ -1390,17 +1386,18 @@ class YoutubeDL(object):
postprocessors = [merger] postprocessors = [merger]
def compatible_formats(formats): def compatible_formats(formats):
video, audio = formats
# Check extension # Check extension
video_ext, audio_ext = audio.get('ext'), video.get('ext') video_ext = formats[0].get('ext')
if video_ext and audio_ext: if video_ext:
COMPATIBLE_EXTS = ( COMPATIBLE_EXTS = (
('mp3', 'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v'), ('mp3', 'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v'),
('webm') ('webm')
) )
for exts in COMPATIBLE_EXTS: for exts in COMPATIBLE_EXTS:
if video_ext in exts and audio_ext in exts: for audio_format in formats[1:]:
return True if video_ext not in exts or audio_format.get('ext') not in exts:
return False
return True
# TODO: Check acodec/vcodec # TODO: Check acodec/vcodec
return False return False

View File

@ -398,7 +398,9 @@ class FFmpegMergerPP(FFmpegPostProcessor):
def run(self, info): def run(self, info):
filename = info['filepath'] filename = info['filepath']
temp_filename = prepend_extension(filename, 'temp') temp_filename = prepend_extension(filename, 'temp')
args = ['-c', 'copy', '-map', '0:v:0', '-map', '1:a:0'] args = ['-c', 'copy', '-map', '0:v:0']
for i in range(1, len(info['__files_to_merge'][1:]) + 1):
args.extend(['-map', '%d:a:0' % (i)])
self._downloader.to_screen('[ffmpeg] Merging formats into "%s"' % filename) self._downloader.to_screen('[ffmpeg] Merging formats into "%s"' % filename)
self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args) self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args)
os.rename(encodeFilename(temp_filename), encodeFilename(filename)) os.rename(encodeFilename(temp_filename), encodeFilename(filename))