[YoutubeDL] Gracefully handle audio/video format reversal (Fixes #5154)

This commit is contained in:
nateschiffer 2016-01-06 19:45:31 -05:00
parent 51d3045de2
commit 1effc65271

View File

@ -1105,15 +1105,17 @@ class YoutubeDL(object):
elif selector.type == MERGE: elif selector.type == MERGE:
def _merge(formats_info): def _merge(formats_info):
format_1, format_2 = [f['format_id'] for f in formats_info] format_1, format_2 = [f['format_id'] for f in formats_info]
# The first format must contain the video and the # The first format must contain the video
# second the audio # If the formats are reversed, swap them
if formats_info[0].get('vcodec') == 'none': if formats_info[0].get('vcodec') == 'none':
self.report_error('The first format must ' if formats_info[1].get('vcodec') == 'none':
'contain the video, try using ' self.report_error(
'"-f %s+%s"' % (format_2, format_1)) 'Both formats %s and %s are audio-only, you must specify "-f video+audio"'
return % (format_1, format_2))
# Formats must be opposite (video+audio) return
if formats_info[0].get('acodec') == 'none' and formats_info[1].get('acodec') == 'none': formats_info = (formats_info[1], formats_info[0])
# Second format must contain audio
if formats_info[1].get('acodec') == 'none':
self.report_error( self.report_error(
'Both formats %s and %s are video-only, you must specify "-f video+audio"' 'Both formats %s and %s are video-only, you must specify "-f video+audio"'
% (format_1, format_2)) % (format_1, format_2))