This commit is contained in:
jxxghp
2023-06-07 21:16:33 +08:00
parent 1c8e349bfc
commit ab86eaf59a
12 changed files with 81 additions and 11 deletions

View File

@ -41,6 +41,7 @@ class RuleParser:
if __name__ == '__main__':
# 测试代码
expression1 = "!BLU & (1080P | CN)"
parsed_expr1 = RuleParser().parse(expression1)
print(parsed_expr1.as_list())
expression = "!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P"
for exp in expression.split('>'):
parsed_expr = RuleParser().parse(exp)
print(parsed_expr.as_list())

View File

@ -111,15 +111,18 @@ class FilterModule(_ModuleBase):
if not isinstance(rule_group, list):
# 不是列表,说明是规则名称
return self.__match_rule(torrent, rule_group)
if rule_group[0] == "not":
elif isinstance(rule_group, list) and len(rule_group) == 1:
# 只有一个规则项
return self.__match_rule(torrent, rule_group[0])
elif rule_group[0] == "not":
# 非操作
return not self.__match_group(torrent, rule_group[1])
return not self.__match_group(torrent, rule_group[1:])
elif rule_group[1] == "and":
# 与操作
return self.__match_group(torrent, rule_group[0]) and self.__match_group(torrent, rule_group[2])
return self.__match_group(torrent, rule_group[0]) and self.__match_group(torrent, rule_group[2:])
elif rule_group[1] == "or":
# 或操作
return self.__match_group(torrent, rule_group[0]) or self.__match_group(torrent, rule_group[2])
return self.__match_group(torrent, rule_group[0]) or self.__match_group(torrent, rule_group[2:])
def __match_rule(self, torrent: TorrentInfo, rule_name: str) -> bool:
"""