allow '*-filter' options to be a list of expressions
This commit is contained in:
@@ -843,24 +843,27 @@ Description
|
||||
extractor.*.image-filter
|
||||
------------------------
|
||||
Type
|
||||
``string``
|
||||
Example
|
||||
* ``"width >= 1200 and width/height > 1.2"``
|
||||
* ``string``
|
||||
* ``list`` of ``strings``
|
||||
Examples
|
||||
* ``"re.search(r'foo(bar)+', description)"``
|
||||
* ``["width >= 1200", "width/height > 1.2"]``
|
||||
Description
|
||||
Python expression controlling which files to download.
|
||||
|
||||
| Files for which the expression evaluates to ``False`` are ignored.
|
||||
| Available keys are the filename-specific ones listed by ``-K`` or ``-j``.
|
||||
A file only gets downloaded when *all* of the given expressions evaluate to ``True``.
|
||||
|
||||
Available values are the filename-specific ones listed by ``-K`` or ``-j``.
|
||||
|
||||
|
||||
extractor.*.chapter-filter
|
||||
--------------------------
|
||||
Type
|
||||
``string``
|
||||
Example
|
||||
* ``string``
|
||||
* ``list`` of ``strings``
|
||||
Examples
|
||||
* ``"lang == 'en'"``
|
||||
* ``"language == 'French' and 10 <= chapter < 20"``
|
||||
* ``["language == 'French'", "10 <= chapter < 20"]``
|
||||
Description
|
||||
Like `image-filter <extractor.*.image-filter_>`__,
|
||||
but applies to delegated URLs like manga chapters, etc.
|
||||
|
||||
@@ -802,6 +802,8 @@ class FilterPredicate():
|
||||
"""Predicate; True if evaluating the given expression returns True"""
|
||||
|
||||
def __init__(self, expr, target="image"):
|
||||
if not isinstance(expr, str):
|
||||
expr = "(" + ") and (".join(expr) + ")"
|
||||
name = "<{} filter>".format(target)
|
||||
self.expr = compile_expression(expr, name)
|
||||
|
||||
|
||||
@@ -116,6 +116,14 @@ class TestPredicate(unittest.TestCase):
|
||||
with self.assertRaises(exception.FilterError):
|
||||
util.FilterPredicate("b > 1")(url, {"a": 2})
|
||||
|
||||
pred = util.FilterPredicate(["a < 3", "b < 4", "c < 5"])
|
||||
self.assertTrue(pred(url, {"a": 2, "b": 3, "c": 4}))
|
||||
self.assertFalse(pred(url, {"a": 3, "b": 3, "c": 4}))
|
||||
self.assertFalse(pred(url, {"a": 2, "b": 4, "c": 4}))
|
||||
self.assertFalse(pred(url, {"a": 2, "b": 3, "c": 5}))
|
||||
with self.assertRaises(exception.FilterError):
|
||||
pred(url, {"a": 2})
|
||||
|
||||
def test_build_predicate(self):
|
||||
pred = util.build_predicate([])
|
||||
self.assertIsInstance(pred, type(lambda: True))
|
||||
|
||||
Reference in New Issue
Block a user