mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-02 14:37:21 +00:00
[YoutubeDL] extend wide format selector
This commit is contained in:
parent
69b59b4b4b
commit
2ae28147b0
|
@ -2146,21 +2146,64 @@ def selector_function(ctx):
|
||||||
|
|
||||||
elif selector.type == SINGLE: # atom
|
elif selector.type == SINGLE: # atom
|
||||||
format_spec = selector.selector or 'best'
|
format_spec = selector.selector or 'best'
|
||||||
|
mobj = re.match(
|
||||||
|
r'(?P<m>merge)?all(?P<t>video|audio)?(?P<l>lang)?', format_spec)
|
||||||
|
if mobj:
|
||||||
|
mg, tp, la = mobj.groups()
|
||||||
|
def selector_function(ctx):
|
||||||
|
formats = ctx['formats'][::-1]
|
||||||
|
|
||||||
# TODO: Add allvideo, allaudio etc by generalizing the code with best/worst selector
|
if tp == 'video':
|
||||||
if format_spec == 'all':
|
formats = (f for f in formats if f.get('vcodec') != 'none')
|
||||||
def selector_function(ctx):
|
elif tp == 'audio':
|
||||||
yield from _check_formats(ctx['formats'][::-1])
|
formats = (f for f in formats if f.get('acodec') != 'none')
|
||||||
elif format_spec == 'mergeall':
|
elif mg:
|
||||||
def selector_function(ctx):
|
# exclude storyboards
|
||||||
formats = list(_check_formats(
|
formats = (
|
||||||
f for f in ctx['formats'] if f.get('vcodec') != 'none' or f.get('acodec') != 'none'))
|
f for f in formats if f.get('vcodec') != 'none' or f.get('acodec') != 'none')
|
||||||
if not formats:
|
|
||||||
|
if la:
|
||||||
|
all_fmts = formats if isinstance(formats, list) else list(formats)
|
||||||
|
langs = set(filter(None, traverse_obj(all_fmts, (..., 'language'), default=[])))
|
||||||
|
formats = []
|
||||||
|
if not langs:
|
||||||
|
self.report_warning('This video has no track with language tag')
|
||||||
|
formats = all_fmts
|
||||||
|
elif tp:
|
||||||
|
# only audio or video
|
||||||
|
for f in all_fmts:
|
||||||
|
if not langs:
|
||||||
|
break
|
||||||
|
lang = f.get('language')
|
||||||
|
if not lang or lang not in langs:
|
||||||
|
continue
|
||||||
|
langs.remove(lang)
|
||||||
|
formats.append(f)
|
||||||
|
else:
|
||||||
|
# no video/audio specified
|
||||||
|
# vcodec, acodec, language
|
||||||
|
langs = set(itertools.product((True, False), (True, False), langs))
|
||||||
|
for f in all_fmts:
|
||||||
|
if not langs:
|
||||||
|
break
|
||||||
|
lang = f.get('language')
|
||||||
|
tu = (f.get('vcodec') != 'none', f.get('acodec') != 'none', lang)
|
||||||
|
if not lang or tu not in langs:
|
||||||
|
continue
|
||||||
|
langs.remove(tu)
|
||||||
|
formats.append(f)
|
||||||
|
|
||||||
|
formats = _check_formats(formats)
|
||||||
|
if mg:
|
||||||
|
formats = iter(formats)
|
||||||
|
merged_format = next(formats, None)
|
||||||
|
if merged_format is None:
|
||||||
return
|
return
|
||||||
merged_format = formats[-1]
|
for f in formats:
|
||||||
for f in formats[-2::-1]:
|
|
||||||
merged_format = _merge((merged_format, f))
|
merged_format = _merge((merged_format, f))
|
||||||
yield merged_format
|
yield merged_format
|
||||||
|
else:
|
||||||
|
yield from formats
|
||||||
|
|
||||||
else:
|
else:
|
||||||
format_fallback, seperate_fallback, format_reverse, format_idx = False, None, True, 1
|
format_fallback, seperate_fallback, format_reverse, format_idx = False, None, True, 1
|
||||||
|
|
Loading…
Reference in a new issue