mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-27 06:10:38 +01:00
[YoutubeDL] Allow filtering by string properties (#4906)
This commit is contained in:
parent
12931e1c6e
commit
9ddb6925bf
|
@ -832,21 +832,38 @@ class YoutubeDL(object):
|
||||||
\]$
|
\]$
|
||||||
''' % '|'.join(map(re.escape, OPERATORS.keys())))
|
''' % '|'.join(map(re.escape, OPERATORS.keys())))
|
||||||
m = operator_rex.search(format_spec)
|
m = operator_rex.search(format_spec)
|
||||||
|
if m:
|
||||||
|
try:
|
||||||
|
comparison_value = int(m.group('value'))
|
||||||
|
except ValueError:
|
||||||
|
comparison_value = parse_filesize(m.group('value'))
|
||||||
|
if comparison_value is None:
|
||||||
|
comparison_value = parse_filesize(m.group('value') + 'B')
|
||||||
|
if comparison_value is None:
|
||||||
|
raise ValueError(
|
||||||
|
'Invalid value %r in format specification %r' % (
|
||||||
|
m.group('value'), format_spec))
|
||||||
|
op = OPERATORS[m.group('op')]
|
||||||
|
|
||||||
|
if not m:
|
||||||
|
STR_OPERATORS = {
|
||||||
|
'=': operator.eq,
|
||||||
|
'!=': operator.ne,
|
||||||
|
}
|
||||||
|
str_operator_rex = re.compile(r'''(?x)\s*\[
|
||||||
|
\s*(?P<key>ext|acodec|vcodec|container|protocol)
|
||||||
|
\s*(?P<op>%s)(?P<none_inclusive>\s*\?)?
|
||||||
|
\s*(?P<value>[a-zA-Z0-9_-]+)
|
||||||
|
\s*\]$
|
||||||
|
''' % '|'.join(map(re.escape, STR_OPERATORS.keys())))
|
||||||
|
m = str_operator_rex.search(format_spec)
|
||||||
|
if m:
|
||||||
|
comparison_value = m.group('value')
|
||||||
|
op = STR_OPERATORS[m.group('op')]
|
||||||
|
|
||||||
if not m:
|
if not m:
|
||||||
raise ValueError('Invalid format specification %r' % format_spec)
|
raise ValueError('Invalid format specification %r' % format_spec)
|
||||||
|
|
||||||
try:
|
|
||||||
comparison_value = int(m.group('value'))
|
|
||||||
except ValueError:
|
|
||||||
comparison_value = parse_filesize(m.group('value'))
|
|
||||||
if comparison_value is None:
|
|
||||||
comparison_value = parse_filesize(m.group('value') + 'B')
|
|
||||||
if comparison_value is None:
|
|
||||||
raise ValueError(
|
|
||||||
'Invalid value %r in format specification %r' % (
|
|
||||||
m.group('value'), format_spec))
|
|
||||||
op = OPERATORS[m.group('op')]
|
|
||||||
|
|
||||||
def _filter(f):
|
def _filter(f):
|
||||||
actual_value = f.get(m.group('key'))
|
actual_value = f.get(m.group('key'))
|
||||||
if actual_value is None:
|
if actual_value is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user