aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2016-10-31 23:32:08 +0700
committerSergey M․ <dstftw@gmail.com>2016-10-31 23:32:08 +0700
commite5a088dc4be4fdcc96927a9f1b7284d4cd49c415 (patch)
tree825b69d75fc0cbd509c8b73a9ae74ecadb9c177e /youtube_dl/utils.py
parent2c6da7df4a4d69ec933688e3c53795fd3436a1c6 (diff)
[utils] Fix --match-filter for int-like strings (closes #11082)
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 2770c5f1c..1a5ce8688 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -2345,11 +2345,18 @@ def _match_one(filter_part, dct):
m = operator_rex.search(filter_part)
if m:
op = COMPARISON_OPERATORS[m.group('op')]
- if m.group('strval') is not None:
+ actual_value = dct.get(m.group('key'))
+ if (m.group('strval') is not None or
+ # If the original field is a string and matching comparisonvalue is
+ # a number we should respect the origin of the original field
+ # and process comparison value as a string (see
+ # https://github.com/rg3/youtube-dl/issues/11082).
+ actual_value is not None and m.group('intval') is not None and
+ isinstance(actual_value, compat_str)):
if m.group('op') not in ('=', '!='):
raise ValueError(
'Operator %s does not support string values!' % m.group('op'))
- comparison_value = m.group('strval')
+ comparison_value = m.group('strval') or m.group('intval')
else:
try:
comparison_value = int(m.group('intval'))
@@ -2361,7 +2368,6 @@ def _match_one(filter_part, dct):
raise ValueError(
'Invalid integer value %r in filter part %r' % (
m.group('intval'), filter_part))
- actual_value = dct.get(m.group('key'))
if actual_value is None:
return m.group('none_inclusive')
return op(actual_value, comparison_value)