Skip to content

Commit

Permalink
[YoutubeDL] Fix typo in string negation implementation and add more t…
Browse files Browse the repository at this point in the history
…ests (closes #18961)
  • Loading branch information
dstftw committed Jan 23, 2019
1 parent 435e382 commit e118a87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions test/test_YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def test_format_selection_video(self):
def test_format_selection_string_ops(self):
formats = [
{'format_id': 'abc-cba', 'ext': 'mp4', 'url': TEST_URL},
{'format_id': 'zxc-cxz', 'ext': 'webm', 'url': TEST_URL},
]
info_dict = _make_result(formats)

Expand All @@ -253,6 +254,11 @@ def test_format_selection_string_ops(self):

# does not equal (!=)
ydl = YDL({'format': '[format_id!=abc-cba]'})
ydl.process_ie_result(info_dict.copy())
downloaded = ydl.downloaded_info_dicts[0]
self.assertEqual(downloaded['format_id'], 'zxc-cxz')

ydl = YDL({'format': '[format_id!=abc-cba][format_id!=zxc-cxz]'})
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())

# starts with (^=)
Expand All @@ -262,7 +268,12 @@ def test_format_selection_string_ops(self):
self.assertEqual(downloaded['format_id'], 'abc-cba')

# does not start with (!^=)
ydl = YDL({'format': '[format_id!^=abc-cba]'})
ydl = YDL({'format': '[format_id!^=abc]'})
ydl.process_ie_result(info_dict.copy())
downloaded = ydl.downloaded_info_dicts[0]
self.assertEqual(downloaded['format_id'], 'zxc-cxz')

ydl = YDL({'format': '[format_id!^=abc][format_id!^=zxc]'})
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())

# ends with ($=)
Expand All @@ -272,16 +283,29 @@ def test_format_selection_string_ops(self):
self.assertEqual(downloaded['format_id'], 'abc-cba')

# does not end with (!$=)
ydl = YDL({'format': '[format_id!$=abc-cba]'})
ydl = YDL({'format': '[format_id!$=cba]'})
ydl.process_ie_result(info_dict.copy())
downloaded = ydl.downloaded_info_dicts[0]
self.assertEqual(downloaded['format_id'], 'zxc-cxz')

ydl = YDL({'format': '[format_id!$=cba][format_id!$=cxz]'})
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())

# contains (*=)
ydl = YDL({'format': '[format_id*=-]'})
ydl = YDL({'format': '[format_id*=bc-cb]'})
ydl.process_ie_result(info_dict.copy())
downloaded = ydl.downloaded_info_dicts[0]
self.assertEqual(downloaded['format_id'], 'abc-cba')

# does not contain (!*=)
ydl = YDL({'format': '[format_id!*=bc-cb]'})
ydl.process_ie_result(info_dict.copy())
downloaded = ydl.downloaded_info_dicts[0]
self.assertEqual(downloaded['format_id'], 'zxc-cxz')

ydl = YDL({'format': '[format_id!*=abc][format_id!*=zxc]'})
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())

ydl = YDL({'format': '[format_id!*=-]'})
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())

Expand Down
2 changes: 1 addition & 1 deletion youtube_dl/YoutubeDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ def _build_format_filter(self, filter_spec):
comparison_value = m.group('value')
str_op = STR_OPERATORS[m.group('op')]
if m.group('negation'):
op = lambda attr, value: not str_op
op = lambda attr, value: not str_op(attr, value)
else:
op = str_op

Expand Down

0 comments on commit e118a87

Please sign in to comment.