1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 12:12:34 +01:00

fix/improve Cloudflare bypass code

This commit is contained in:
Mike Fährmann 2020-05-01 23:35:43 +02:00
parent b47cfc5ac9
commit 714566b6e3
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

View File

@ -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,
}