diff options
Diffstat (limited to 'gallery_dl/cloudflare.py')
| -rw-r--r-- | gallery_dl/cloudflare.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/gallery_dl/cloudflare.py b/gallery_dl/cloudflare.py index e3ebd1a..43ccdeb 100644 --- a/gallery_dl/cloudflare.py +++ b/gallery_dl/cloudflare.py @@ -144,11 +144,15 @@ def evaluate_expression(expr, page, netloc, *, # evaluate them, # and accumulate their values in 'result' result = "" - for subexpr in split_re.findall(expr) or (expr,): - result += str(sum( - VALUES[part] - for part in subexpr.split("[]") - )) + for subexpr in expr.strip("+()").split(")+("): + value = 0 + for part in subexpr.split("+"): + if "-" in part: + p1, _, p2 = part.partition("-") + value += VALUES[p1] - VALUES[p2] + else: + value += VALUES[part] + result += str(value) return int(result) @@ -158,12 +162,14 @@ OPERATORS = { "*": operator.mul, } + VALUES = { "": 0, - "+": 0, - "!+": 1, - "!!": 1, - "+!!": 1, + "!": 1, + "[]": 0, + "!![]": 1, + "(!![]": 1, + "(!![])": 1, } |
