Skip to content

Commit e118a87

Browse files
committed
[YoutubeDL] Fix typo in string negation implementation and add more tests (closes #18961)
1 parent 435e382 commit e118a87

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

test/test_YoutubeDL.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def test_format_selection_video(self):
242242
def test_format_selection_string_ops(self):
243243
formats = [
244244
{'format_id': 'abc-cba', 'ext': 'mp4', 'url': TEST_URL},
245+
{'format_id': 'zxc-cxz', 'ext': 'webm', 'url': TEST_URL},
245246
]
246247
info_dict = _make_result(formats)
247248

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

254255
# does not equal (!=)
255256
ydl = YDL({'format': '[format_id!=abc-cba]'})
257+
ydl.process_ie_result(info_dict.copy())
258+
downloaded = ydl.downloaded_info_dicts[0]
259+
self.assertEqual(downloaded['format_id'], 'zxc-cxz')
260+
261+
ydl = YDL({'format': '[format_id!=abc-cba][format_id!=zxc-cxz]'})
256262
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())
257263

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

264270
# does not start with (!^=)
265-
ydl = YDL({'format': '[format_id!^=abc-cba]'})
271+
ydl = YDL({'format': '[format_id!^=abc]'})
272+
ydl.process_ie_result(info_dict.copy())
273+
downloaded = ydl.downloaded_info_dicts[0]
274+
self.assertEqual(downloaded['format_id'], 'zxc-cxz')
275+
276+
ydl = YDL({'format': '[format_id!^=abc][format_id!^=zxc]'})
266277
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())
267278

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

274285
# does not end with (!$=)
275-
ydl = YDL({'format': '[format_id!$=abc-cba]'})
286+
ydl = YDL({'format': '[format_id!$=cba]'})
287+
ydl.process_ie_result(info_dict.copy())
288+
downloaded = ydl.downloaded_info_dicts[0]
289+
self.assertEqual(downloaded['format_id'], 'zxc-cxz')
290+
291+
ydl = YDL({'format': '[format_id!$=cba][format_id!$=cxz]'})
276292
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())
277293

278294
# contains (*=)
279-
ydl = YDL({'format': '[format_id*=-]'})
295+
ydl = YDL({'format': '[format_id*=bc-cb]'})
280296
ydl.process_ie_result(info_dict.copy())
281297
downloaded = ydl.downloaded_info_dicts[0]
282298
self.assertEqual(downloaded['format_id'], 'abc-cba')
283299

284300
# does not contain (!*=)
301+
ydl = YDL({'format': '[format_id!*=bc-cb]'})
302+
ydl.process_ie_result(info_dict.copy())
303+
downloaded = ydl.downloaded_info_dicts[0]
304+
self.assertEqual(downloaded['format_id'], 'zxc-cxz')
305+
306+
ydl = YDL({'format': '[format_id!*=abc][format_id!*=zxc]'})
307+
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())
308+
285309
ydl = YDL({'format': '[format_id!*=-]'})
286310
self.assertRaises(ExtractorError, ydl.process_ie_result, info_dict.copy())
287311

youtube_dl/YoutubeDL.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ def _build_format_filter(self, filter_spec):
10781078
comparison_value = m.group('value')
10791079
str_op = STR_OPERATORS[m.group('op')]
10801080
if m.group('negation'):
1081-
op = lambda attr, value: not str_op
1081+
op = lambda attr, value: not str_op(attr, value)
10821082
else:
10831083
op = str_op
10841084

0 commit comments

Comments
 (0)