mirror of
https://github.com/lifegpc/pythonscript.git
synced 2026-06-05 11:08:49 +08:00
Update
This commit is contained in:
@@ -20,6 +20,9 @@ proxies:
|
|||||||
type: socks5
|
type: socks5
|
||||||
server: localhost
|
server: localhost
|
||||||
port: 7891
|
port: 7891
|
||||||
|
# 保留来自订阅来源的订阅组
|
||||||
|
# 默认 false
|
||||||
|
keep-proxy-groups: true
|
||||||
# 添加自定义规则组
|
# 添加自定义规则组
|
||||||
proxy-groups:
|
proxy-groups:
|
||||||
- name: all
|
- name: all
|
||||||
@@ -28,6 +31,7 @@ proxy-groups:
|
|||||||
- group1
|
- group1
|
||||||
- group2
|
- group2
|
||||||
# 是否将DIRECT加至列表
|
# 是否将DIRECT加至列表
|
||||||
|
# 默认 false
|
||||||
add-direct: true
|
add-direct: true
|
||||||
- name: JP
|
- name: JP
|
||||||
type: select
|
type: select
|
||||||
@@ -38,8 +42,15 @@ proxy-groups:
|
|||||||
- name: All
|
- name: All
|
||||||
type: select
|
type: select
|
||||||
# 将所有节点/组加至列表
|
# 将所有节点/组加至列表
|
||||||
|
# 默认 false
|
||||||
match-all: true
|
match-all: true
|
||||||
add-direct: true
|
add-direct: true
|
||||||
# 自定义节点(默认覆盖)
|
# 保留来自订阅来源的规则
|
||||||
|
# 默认 false
|
||||||
|
keep-rules: true
|
||||||
|
# 将自定义规则加到来自订阅的规则前
|
||||||
|
# 默认 false
|
||||||
|
prepend-rules: false
|
||||||
|
# 自定义规则
|
||||||
rules:
|
rules:
|
||||||
- MATCH,All
|
- MATCH,All
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ with open(config["dest"]) as f:
|
|||||||
dest["proxies"] = []
|
dest["proxies"] = []
|
||||||
dest["proxy-groups"] = []
|
dest["proxy-groups"] = []
|
||||||
more_groups = []
|
more_groups = []
|
||||||
|
keep_rules = config["keep-rules"] if "keep-rules" in config else False
|
||||||
|
prepend_rules = config["prepend-rules"] if "prepend-rules" in config else False
|
||||||
|
if keep_rules:
|
||||||
|
dest["rules"] = []
|
||||||
|
last_match_rule = "MATCH,DIRECT"
|
||||||
for s in src:
|
for s in src:
|
||||||
add_group = False
|
add_group = False
|
||||||
if isinstance(s, dict):
|
if isinstance(s, dict):
|
||||||
@@ -43,6 +48,9 @@ for s in src:
|
|||||||
raise ValueError(f"Failed to download src: {s}")
|
raise ValueError(f"Failed to download src: {s}")
|
||||||
dest["proxies"] += ori["proxies"]
|
dest["proxies"] += ori["proxies"]
|
||||||
dest["proxy-groups"] += ori["proxy-groups"]
|
dest["proxy-groups"] += ori["proxy-groups"]
|
||||||
|
if keep_rules:
|
||||||
|
dest["rules"] += ori["rules"][:-1]
|
||||||
|
last_match_rule = ori["rules"][-1]
|
||||||
if add_group:
|
if add_group:
|
||||||
more_groups.append({
|
more_groups.append({
|
||||||
"name": s["name"],
|
"name": s["name"],
|
||||||
@@ -51,8 +59,10 @@ for s in src:
|
|||||||
})
|
})
|
||||||
if "proxies" in config:
|
if "proxies" in config:
|
||||||
dest["proxies"] += config["proxies"]
|
dest["proxies"] += config["proxies"]
|
||||||
|
keep_proxy_groups = config["keep-proxy-groups"] if "keep-proxy-groups" in config else False
|
||||||
if "proxy-groups" in config:
|
if "proxy-groups" in config:
|
||||||
dest["proxy-groups"] = []
|
if not keep_proxy_groups:
|
||||||
|
dest["proxy-groups"] = []
|
||||||
for group in config["proxy-groups"]:
|
for group in config["proxy-groups"]:
|
||||||
if 'proxies' not in group:
|
if 'proxies' not in group:
|
||||||
group['proxies'] = []
|
group['proxies'] = []
|
||||||
@@ -75,6 +85,15 @@ if "proxy-groups" in config:
|
|||||||
dest["proxy-groups"].append(group)
|
dest["proxy-groups"].append(group)
|
||||||
dest["proxy-groups"] += more_groups
|
dest["proxy-groups"] += more_groups
|
||||||
if 'rules' in config:
|
if 'rules' in config:
|
||||||
dest['rules'] = config['rules']
|
if keep_rules:
|
||||||
|
if prepend_rules:
|
||||||
|
dest['rules'] = config['rules'][:-1] + dest['rules']
|
||||||
|
dest['rules'].append(config['rules'][-1])
|
||||||
|
else:
|
||||||
|
dest['rules'] += config['rules']
|
||||||
|
else:
|
||||||
|
dest['rules'] = config['rules']
|
||||||
|
elif keep_rules:
|
||||||
|
dest['rules'].append(last_match_rule)
|
||||||
with open(config["dest"], "w") as f:
|
with open(config["dest"], "w") as f:
|
||||||
dump(dest, f, Dumper=SafeDumper, allow_unicode=True)
|
dump(dest, f, Dumper=SafeDumper, allow_unicode=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user