mirror of
https://github.com/LucBerge/yt-dlp.git
synced 2025-03-17 19:57:52 +03:00
[utils] Add orderedSet_from_options
This commit is contained in:
parent
13db4e7b9e
commit
5314b52192
3 changed files with 47 additions and 45 deletions
|
@ -5785,6 +5785,36 @@ def truncate_string(s, left, right=0):
|
|||
return f'{s[:left-3]}...{s[-right:]}'
|
||||
|
||||
|
||||
def orderedSet_from_options(options, alias_dict, *, use_regex=False, start=None):
|
||||
assert 'all' in alias_dict, '"all" alias is required'
|
||||
requested = list(start or [])
|
||||
for val in options:
|
||||
discard = val.startswith('-')
|
||||
if discard:
|
||||
val = val[1:]
|
||||
|
||||
if val in alias_dict:
|
||||
val = alias_dict[val] if not discard else [
|
||||
i[1:] if i.startswith('-') else f'-{i}' for i in alias_dict[val]]
|
||||
# NB: Do not allow regex in aliases for performance
|
||||
requested = orderedSet_from_options(val, alias_dict, start=requested)
|
||||
continue
|
||||
|
||||
current = (filter(re.compile(val, re.I).fullmatch, alias_dict['all']) if use_regex
|
||||
else [val] if val in alias_dict['all'] else None)
|
||||
if current is None:
|
||||
raise ValueError(val)
|
||||
|
||||
if discard:
|
||||
for item in current:
|
||||
while item in requested:
|
||||
requested.remove(item)
|
||||
else:
|
||||
requested.extend(current)
|
||||
|
||||
return orderedSet(requested)
|
||||
|
||||
|
||||
# Deprecated
|
||||
has_certifi = bool(certifi)
|
||||
has_websockets = bool(websockets)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue