mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 06:15:46 +00:00
Swap audio+video format input
This commit is contained in:
parent
b13f29098f
commit
5888bba9e6
2 changed files with 38 additions and 20 deletions
|
@ -390,6 +390,15 @@ class TestFormatSelection(unittest.TestCase):
|
||||||
downloaded_ids = [info['format_id'] for info in ydl.downloaded_info_dicts]
|
downloaded_ids = [info['format_id'] for info in ydl.downloaded_info_dicts]
|
||||||
self.assertEqual(downloaded_ids, ['248+141'])
|
self.assertEqual(downloaded_ids, ['248+141'])
|
||||||
|
|
||||||
|
for f in ['248+141', '141+248']:
|
||||||
|
info_dict = _make_result(list(formats_order), extractor='youtube')
|
||||||
|
ydl = YDL({'format': f})
|
||||||
|
yie = YoutubeIE(ydl)
|
||||||
|
yie._sort_formats(info_dict['formats'])
|
||||||
|
ydl.process_ie_result(info_dict)
|
||||||
|
downloaded_ids = [info['format_id'] for info in ydl.downloaded_info_dicts]
|
||||||
|
self.assertEqual(downloaded_ids, ['248+141'])
|
||||||
|
|
||||||
for f1, f2 in zip(formats_order, formats_order[1:]):
|
for f1, f2 in zip(formats_order, formats_order[1:]):
|
||||||
info_dict = _make_result([f1, f2], extractor='youtube')
|
info_dict = _make_result([f1, f2], extractor='youtube')
|
||||||
ydl = YDL({'format': 'best/bestvideo'})
|
ydl = YDL({'format': 'best/bestvideo'})
|
||||||
|
|
|
@ -1316,39 +1316,48 @@ class YoutubeDL(object):
|
||||||
yield matches[-1]
|
yield matches[-1]
|
||||||
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 = formats_info[0], formats_info[1]
|
||||||
|
format_1_id, format_2_id = format_1['format_id'], format_2['format_id']
|
||||||
# The first format must contain the video and the
|
# The first format must contain the video and the
|
||||||
# second the audio
|
# second the audio
|
||||||
if formats_info[0].get('vcodec') == 'none':
|
|
||||||
|
# If the user swapped the two inputs, try swapping it for
|
||||||
|
# them
|
||||||
|
if format_1.get('acodec') != 'none' and format_2.get('vcodec') != 'none':
|
||||||
|
temp = format_1
|
||||||
|
format_1 = format_2
|
||||||
|
format_2 = temp
|
||||||
|
|
||||||
|
if format_1.get('vcodec') == 'none':
|
||||||
self.report_error('The first format must '
|
self.report_error('The first format must '
|
||||||
'contain the video, try using '
|
'contain the video, try using '
|
||||||
'"-f %s+%s"' % (format_2, format_1))
|
'"-f %s+%s"' % (format_1_id, format_2_id))
|
||||||
return
|
|
||||||
# Formats must be opposite (video+audio)
|
# Formats must be opposite (video+audio)
|
||||||
if formats_info[0].get('acodec') == 'none' and formats_info[1].get('acodec') == 'none':
|
if format_1.get('acodec') == 'none' and format_2.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_id, format_2_id))
|
||||||
return
|
return
|
||||||
output_ext = (
|
output_ext = (
|
||||||
formats_info[0]['ext']
|
format_1['ext']
|
||||||
if self.params.get('merge_output_format') is None
|
if self.params.get('merge_output_format') is None
|
||||||
else self.params['merge_output_format'])
|
else self.params['merge_output_format'])
|
||||||
return {
|
return {
|
||||||
'requested_formats': formats_info,
|
'requested_formats': formats_info,
|
||||||
'format': '%s+%s' % (formats_info[0].get('format'),
|
'format': '%s+%s' % (format_1.get('format'),
|
||||||
formats_info[1].get('format')),
|
format_2.get('format')),
|
||||||
'format_id': '%s+%s' % (formats_info[0].get('format_id'),
|
'format_id': '%s+%s' % (format_1.get('format_id'),
|
||||||
formats_info[1].get('format_id')),
|
format_2.get('format_id')),
|
||||||
'width': formats_info[0].get('width'),
|
'width': format_1.get('width'),
|
||||||
'height': formats_info[0].get('height'),
|
'height': format_1.get('height'),
|
||||||
'resolution': formats_info[0].get('resolution'),
|
'resolution': format_1.get('resolution'),
|
||||||
'fps': formats_info[0].get('fps'),
|
'fps': format_1.get('fps'),
|
||||||
'vcodec': formats_info[0].get('vcodec'),
|
'vcodec': format_1.get('vcodec'),
|
||||||
'vbr': formats_info[0].get('vbr'),
|
'vbr': format_1.get('vbr'),
|
||||||
'stretched_ratio': formats_info[0].get('stretched_ratio'),
|
'stretched_ratio': format_1.get('stretched_ratio'),
|
||||||
'acodec': formats_info[1].get('acodec'),
|
'acodec': format_2.get('acodec'),
|
||||||
'abr': formats_info[1].get('abr'),
|
'abr': format_2.get('abr'),
|
||||||
'ext': output_ext,
|
'ext': output_ext,
|
||||||
}
|
}
|
||||||
video_selector, audio_selector = map(_build_selector_function, selector.selector)
|
video_selector, audio_selector = map(_build_selector_function, selector.selector)
|
||||||
|
|
Loading…
Reference in a new issue