From 1effc652713e93b4baa861698fe0c49eb9773ac4 Mon Sep 17 00:00:00 2001 From: nateschiffer Date: Wed, 6 Jan 2016 19:45:31 -0500 Subject: [PATCH] [YoutubeDL] Gracefully handle audio/video format reversal (Fixes #5154) --- youtube_dl/YoutubeDL.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 3b2be3159..0b448a506 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1105,15 +1105,17 @@ class YoutubeDL(object): elif selector.type == MERGE: def _merge(formats_info): format_1, format_2 = [f['format_id'] for f in formats_info] - # The first format must contain the video and the - # second the audio + # The first format must contain the video + # If the formats are reversed, swap them if formats_info[0].get('vcodec') == 'none': - self.report_error('The first format must ' - 'contain the video, try using ' - '"-f %s+%s"' % (format_2, format_1)) - return - # Formats must be opposite (video+audio) - if formats_info[0].get('acodec') == 'none' and formats_info[1].get('acodec') == 'none': + if formats_info[1].get('vcodec') == 'none': + self.report_error( + 'Both formats %s and %s are audio-only, you must specify "-f video+audio"' + % (format_1, format_2)) + return + formats_info = (formats_info[1], formats_info[0]) + # Second format must contain audio + if formats_info[1].get('acodec') == 'none': self.report_error( 'Both formats %s and %s are video-only, you must specify "-f video+audio"' % (format_1, format_2))