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