mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-22 16:44:32 +01:00
[YoutubeDL] Improve _default_format_spec (closes #14461)
This commit is contained in:
parent
9e38dbb19c
commit
af0f74288d
@ -466,12 +466,18 @@ class TestFormatSelection(unittest.TestCase):
|
|||||||
ydl = YDL({'simulate': True})
|
ydl = YDL({'simulate': True})
|
||||||
self.assertEqual(ydl._default_format_spec({}), 'bestvideo+bestaudio/best')
|
self.assertEqual(ydl._default_format_spec({}), 'bestvideo+bestaudio/best')
|
||||||
|
|
||||||
|
ydl = YDL({'is_live': True})
|
||||||
|
self.assertEqual(ydl._default_format_spec({}), 'best/bestvideo+bestaudio')
|
||||||
|
|
||||||
|
ydl = YDL({'simulate': True, 'is_live': True})
|
||||||
|
self.assertEqual(ydl._default_format_spec({}), 'bestvideo+bestaudio/best')
|
||||||
|
|
||||||
ydl = YDL({'outtmpl': '-'})
|
ydl = YDL({'outtmpl': '-'})
|
||||||
self.assertEqual(ydl._default_format_spec({}), 'best')
|
self.assertEqual(ydl._default_format_spec({}), 'best/bestvideo+bestaudio')
|
||||||
|
|
||||||
ydl = YDL({})
|
ydl = YDL({})
|
||||||
self.assertEqual(ydl._default_format_spec({}, download=False), 'bestvideo+bestaudio/best')
|
self.assertEqual(ydl._default_format_spec({}, download=False), 'bestvideo+bestaudio/best')
|
||||||
self.assertEqual(ydl._default_format_spec({'is_live': True}), 'best')
|
self.assertEqual(ydl._default_format_spec({'is_live': True}), 'best/bestvideo+bestaudio')
|
||||||
|
|
||||||
|
|
||||||
class TestYoutubeDL(unittest.TestCase):
|
class TestYoutubeDL(unittest.TestCase):
|
||||||
|
@ -1078,22 +1078,27 @@ class YoutubeDL(object):
|
|||||||
return _filter
|
return _filter
|
||||||
|
|
||||||
def _default_format_spec(self, info_dict, download=True):
|
def _default_format_spec(self, info_dict, download=True):
|
||||||
req_format_list = []
|
|
||||||
|
|
||||||
def can_have_partial_formats():
|
def can_merge():
|
||||||
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)
|
merger = FFmpegMergerPP(self)
|
||||||
return merger.available and merger.can_merge()
|
return merger.available and merger.can_merge()
|
||||||
if can_have_partial_formats():
|
|
||||||
req_format_list.append('bestvideo+bestaudio')
|
def prefer_best():
|
||||||
req_format_list.append('best')
|
if self.params.get('simulate', False):
|
||||||
|
return False
|
||||||
|
if not download:
|
||||||
|
return False
|
||||||
|
if self.params.get('outtmpl', DEFAULT_OUTTMPL) == '-':
|
||||||
|
return True
|
||||||
|
if info_dict.get('is_live'):
|
||||||
|
return True
|
||||||
|
if not can_merge():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
req_format_list = ['bestvideo+bestaudio', 'best']
|
||||||
|
if prefer_best():
|
||||||
|
req_format_list.reverse()
|
||||||
return '/'.join(req_format_list)
|
return '/'.join(req_format_list)
|
||||||
|
|
||||||
def build_format_selector(self, format_spec):
|
def build_format_selector(self, format_spec):
|
||||||
|
Loading…
Reference in New Issue
Block a user