Strip IP-ASN rules unsupported by Clash Premium; add sanitize.py
This commit is contained in:
parent
7a5ce10802
commit
1c70a699c5
@ -5,3 +5,6 @@ Clash / Stash rule-providers 镜像。
|
|||||||
示例:https://g.yiku.work/troy/clash-rules/raw/branch/main/rules/reject.yaml
|
示例:https://g.yiku.work/troy/clash-rules/raw/branch/main/rules/reject.yaml
|
||||||
|
|
||||||
来源:Loyalsoldier/clash-rules、blackmatrix7/ios_rule_script。仅个人使用。
|
来源:Loyalsoldier/clash-rules、blackmatrix7/ios_rule_script。仅个人使用。
|
||||||
|
|
||||||
|
镜像文件经 sanitize.py 处理,已剔除旧版 Clash Premium 不支持的规则类型(IP-ASN 等)。
|
||||||
|
刷新流程:重新下载到 rules/ 后执行 python3 sanitize.py,再提交。
|
||||||
|
|||||||
@ -52,8 +52,3 @@ payload:
|
|||||||
- PROCESS-NAME,telegram-desktop
|
- PROCESS-NAME,telegram-desktop
|
||||||
- PROCESS-NAME,tw.nekomimi.nekogram
|
- PROCESS-NAME,tw.nekomimi.nekogram
|
||||||
- PROCESS-NAME,xyz.nextalone.nagram
|
- PROCESS-NAME,xyz.nextalone.nagram
|
||||||
- IP-ASN,211157
|
|
||||||
- IP-ASN,44907
|
|
||||||
- IP-ASN,59930
|
|
||||||
- IP-ASN,62014
|
|
||||||
- IP-ASN,62041
|
|
||||||
|
|||||||
16
sanitize.py
Executable file
16
sanitize.py
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""去掉 Clash Premium(Clash for Windows) 不认识的规则类型,保持镜像可被新旧内核共用。"""
|
||||||
|
import pathlib, re, sys
|
||||||
|
|
||||||
|
UNSUPPORTED = ("IP-ASN", "GEOSITE", "IP-SUFFIX", "SRC-IP-SUFFIX", "RULE-SET", "SUB-RULE", "AND", "OR", "NOT")
|
||||||
|
|
||||||
|
changed = 0
|
||||||
|
for f in sorted(pathlib.Path("rules").iterdir()):
|
||||||
|
lines = f.read_text(encoding="utf-8").splitlines(True)
|
||||||
|
kept = [l for l in lines
|
||||||
|
if not any(re.match(rf"\s*-\s*{t},", l) for t in UNSUPPORTED)]
|
||||||
|
if len(kept) != len(lines):
|
||||||
|
f.write_text("".join(kept), encoding="utf-8")
|
||||||
|
print(f"{f.name}: removed {len(lines) - len(kept)} line(s)")
|
||||||
|
changed += 1
|
||||||
|
print(f"files changed: {changed}")
|
||||||
Loading…
Reference in New Issue
Block a user