mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 01:02:13 +01:00
[YoutubeDL] Improve default format specification (closes #13704)
This commit is contained in:
parent
327c8364f1
commit
0017d9ad6d
2 changed files with 34 additions and 8 deletions
|
@ -449,6 +449,17 @@ def test_format_filtering(self):
|
||||||
pass
|
pass
|
||||||
self.assertEqual(ydl.downloaded_info_dicts, [])
|
self.assertEqual(ydl.downloaded_info_dicts, [])
|
||||||
|
|
||||||
|
def test_default_format_spec(self):
|
||||||
|
ydl = YDL({'simulate': True})
|
||||||
|
self.assertEqual(ydl._default_format_spec({}), 'bestvideo+bestaudio/best')
|
||||||
|
|
||||||
|
ydl = YDL({'outtmpl': '-'})
|
||||||
|
self.assertEqual(ydl._default_format_spec({}), 'best')
|
||||||
|
|
||||||
|
ydl = YDL({})
|
||||||
|
self.assertEqual(ydl._default_format_spec({}, download=False), 'bestvideo+bestaudio/best')
|
||||||
|
self.assertEqual(ydl._default_format_spec({'is_live': True}), 'best')
|
||||||
|
|
||||||
|
|
||||||
class TestYoutubeDL(unittest.TestCase):
|
class TestYoutubeDL(unittest.TestCase):
|
||||||
def test_subtitles(self):
|
def test_subtitles(self):
|
||||||
|
|
|
@ -1064,6 +1064,25 @@ def _filter(f):
|
||||||
return op(actual_value, comparison_value)
|
return op(actual_value, comparison_value)
|
||||||
return _filter
|
return _filter
|
||||||
|
|
||||||
|
def _default_format_spec(self, info_dict, download=True):
|
||||||
|
req_format_list = []
|
||||||
|
|
||||||
|
def can_have_partial_formats():
|
||||||
|
if self.params.get('simulate', False):
|
||||||
|
return True
|
||||||
|
if not download:
|
||||||
|
return True
|
||||||
|
if self.params.get('outtmpl', DEFAULT_OUTTMPL) == '-':
|
||||||
|
return False
|
||||||
|
if info_dict.get('is_live'):
|
||||||
|
return False
|
||||||
|
merger = FFmpegMergerPP(self)
|
||||||
|
return merger.available and merger.can_merge()
|
||||||
|
if can_have_partial_formats():
|
||||||
|
req_format_list.append('bestvideo+bestaudio')
|
||||||
|
req_format_list.append('best')
|
||||||
|
return '/'.join(req_format_list)
|
||||||
|
|
||||||
def build_format_selector(self, format_spec):
|
def build_format_selector(self, format_spec):
|
||||||
def syntax_error(note, start):
|
def syntax_error(note, start):
|
||||||
message = (
|
message = (
|
||||||
|
@ -1534,14 +1553,10 @@ def is_wellformed(f):
|
||||||
|
|
||||||
req_format = self.params.get('format')
|
req_format = self.params.get('format')
|
||||||
if req_format is None:
|
if req_format is None:
|
||||||
req_format_list = []
|
req_format = self._default_format_spec(info_dict, download=download)
|
||||||
if (self.params.get('outtmpl', DEFAULT_OUTTMPL) != '-' and
|
if self.params.get('verbose'):
|
||||||
not info_dict.get('is_live')):
|
self.to_stdout('[debug] Default format spec: %s' % req_format)
|
||||||
merger = FFmpegMergerPP(self)
|
|
||||||
if merger.available and merger.can_merge():
|
|
||||||
req_format_list.append('bestvideo+bestaudio')
|
|
||||||
req_format_list.append('best')
|
|
||||||
req_format = '/'.join(req_format_list)
|
|
||||||
format_selector = self.build_format_selector(req_format)
|
format_selector = self.build_format_selector(req_format)
|
||||||
|
|
||||||
# While in format selection we may need to have an access to the original
|
# While in format selection we may need to have an access to the original
|
||||||
|
|
Loading…
Reference in a new issue