|
@@ -75,6 +75,25 @@ def detect_country(node_name: str) -> str:
|
|
|
return "OTHER"
|
|
return "OTHER"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def extract_rate(node_name: str) -> Optional[float]:
|
|
|
|
|
+ """
|
|
|
|
|
+ 从节点名称中提取倍率数字 (例如 '丨10x HK' -> 10.0, '5x' -> 5.0)
|
|
|
|
|
+ """
|
|
|
|
|
+ m = re.search(r'(?:丨|\||\s|\[|\()(\d+(?:\.\d+)?)\s*[xX]', node_name)
|
|
|
|
|
+ if m:
|
|
|
|
|
+ try:
|
|
|
|
|
+ return float(m.group(1))
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ pass
|
|
|
|
|
+ m2 = re.search(r'(\d+(?:\.\d+)?)\s*[xX]', node_name)
|
|
|
|
|
+ if m2:
|
|
|
|
|
+ try:
|
|
|
|
|
+ return float(m2.group(1))
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ pass
|
|
|
|
|
+ return None
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def fetch_config(source: str) -> dict:
|
|
def fetch_config(source: str) -> dict:
|
|
|
"""从网络链接或本地文件读取 yaml 配置"""
|
|
"""从网络链接或本地文件读取 yaml 配置"""
|
|
|
if source.startswith("http://") or source.startswith("https://"):
|
|
if source.startswith("http://") or source.startswith("https://"):
|
|
@@ -99,6 +118,8 @@ def main():
|
|
|
parser.add_argument("--sub", type=str, required=True, help="服务商提供的订阅链接 (URL) 或本地 yaml 文件路径")
|
|
parser.add_argument("--sub", type=str, required=True, help="服务商提供的订阅链接 (URL) 或本地 yaml 文件路径")
|
|
|
parser.add_argument("--start-port", type=int, default=10001, help="起始监听端口 (默认: 10001)")
|
|
parser.add_argument("--start-port", type=int, default=10001, help="起始监听端口 (默认: 10001)")
|
|
|
parser.add_argument("--count", type=int, default=0, help="最多导出的节点总数量 (默认: 0 表示全部节点)")
|
|
parser.add_argument("--count", type=int, default=0, help="最多导出的节点总数量 (默认: 0 表示全部节点)")
|
|
|
|
|
+ parser.add_argument("--exclude-rates", type=str, default="5,10", help="排除指定倍率的节点,逗号隔开 (默认: '5,10',支持 '5,10' 或 '5x,10x',留空或设为 'none' 则不过滤)")
|
|
|
|
|
+ parser.add_argument("--max-rate", type=float, default=None, help="最大允许倍率,超过该倍率的节点将被过滤 (例如: 3.0 则自动排除 5x, 10x 等)")
|
|
|
parser.add_argument("--filter-kw", type=str, default="", help="节点关键词过滤 (如: '专线', '家宽',留空表示不限制)")
|
|
parser.add_argument("--filter-kw", type=str, default="", help="节点关键词过滤 (如: '专线', '家宽',留空表示不限制)")
|
|
|
parser.add_argument("--countries", type=str, default="", help="仅导出的国家代码列表,逗号分隔 (例如: 'DE,IE,GB,US',留空表示全量导出)")
|
|
parser.add_argument("--countries", type=str, default="", help="仅导出的国家代码列表,逗号分隔 (例如: 'DE,IE,GB,US',留空表示全量导出)")
|
|
|
parser.add_argument("--pool-prefix", type=str, default="local", help="国家池子的前缀 (默认: 'local' -> 生成 'local_de', 'local_ie' 等)")
|
|
parser.add_argument("--pool-prefix", type=str, default="local", help="国家池子的前缀 (默认: 'local' -> 生成 'local_de', 'local_ie' 等)")
|
|
@@ -125,8 +146,20 @@ def main():
|
|
|
if c:
|
|
if c:
|
|
|
target_countries.add(c)
|
|
target_countries.add(c)
|
|
|
|
|
|
|
|
|
|
+ # 倍率过滤规则解析
|
|
|
|
|
+ exclude_rates_set = set()
|
|
|
|
|
+ if args.exclude_rates and args.exclude_rates.lower() != "none":
|
|
|
|
|
+ for r_str in args.exclude_rates.split(","):
|
|
|
|
|
+ r_str = r_str.strip().lower().rstrip("x")
|
|
|
|
|
+ if r_str:
|
|
|
|
|
+ try:
|
|
|
|
|
+ exclude_rates_set.add(float(r_str))
|
|
|
|
|
+ except ValueError:
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
# 2. 节点过滤与国家识别
|
|
# 2. 节点过滤与国家识别
|
|
|
selected_proxies = []
|
|
selected_proxies = []
|
|
|
|
|
+ filtered_by_rate_count = 0
|
|
|
for p in proxies:
|
|
for p in proxies:
|
|
|
name = p.get("name", "")
|
|
name = p.get("name", "")
|
|
|
# 排除不可用的系统提示节点
|
|
# 排除不可用的系统提示节点
|
|
@@ -134,6 +167,13 @@ def main():
|
|
|
continue
|
|
continue
|
|
|
if args.filter_kw and args.filter_kw.lower() not in name.lower():
|
|
if args.filter_kw and args.filter_kw.lower() not in name.lower():
|
|
|
continue
|
|
continue
|
|
|
|
|
+
|
|
|
|
|
+ # 倍率过滤
|
|
|
|
|
+ node_rate = extract_rate(name)
|
|
|
|
|
+ if node_rate is not None:
|
|
|
|
|
+ if node_rate in exclude_rates_set or (args.max_rate is not None and node_rate > args.max_rate):
|
|
|
|
|
+ filtered_by_rate_count += 1
|
|
|
|
|
+ continue
|
|
|
|
|
|
|
|
# 国家过滤
|
|
# 国家过滤
|
|
|
c_code = detect_country(name)
|
|
c_code = detect_country(name)
|
|
@@ -143,6 +183,14 @@ def main():
|
|
|
p["_country_code"] = c_code
|
|
p["_country_code"] = c_code
|
|
|
selected_proxies.append(p)
|
|
selected_proxies.append(p)
|
|
|
|
|
|
|
|
|
|
+ if filtered_by_rate_count > 0:
|
|
|
|
|
+ rules_desc = []
|
|
|
|
|
+ if exclude_rates_set:
|
|
|
|
|
+ rules_desc.append(f"排除倍率: {[f'{r:g}x' for r in sorted(exclude_rates_set)]}")
|
|
|
|
|
+ if args.max_rate is not None:
|
|
|
|
|
+ rules_desc.append(f"倍率上限 <= {args.max_rate:g}x")
|
|
|
|
|
+ print(f"[*] 已根据倍率规则自动过滤掉 {filtered_by_rate_count} 个高倍率节点 ({', '.join(rules_desc)})。")
|
|
|
|
|
+
|
|
|
if args.count > 0:
|
|
if args.count > 0:
|
|
|
selected_proxies = selected_proxies[:args.count]
|
|
selected_proxies = selected_proxies[:args.count]
|
|
|
|
|
|
|
@@ -219,11 +267,16 @@ def main():
|
|
|
except Exception:
|
|
except Exception:
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
- # 汇总所有现有节点和新节点到 nodes 列表 (按节点名称去重)
|
|
|
|
|
|
|
+ # 汇总所有现有节点和新节点到 nodes 列表 (按节点名称去重,并同步过滤掉需要排除的高倍率节点)
|
|
|
existing_nodes_dict = {}
|
|
existing_nodes_dict = {}
|
|
|
for n in all_proxies_data["nodes"]:
|
|
for n in all_proxies_data["nodes"]:
|
|
|
if isinstance(n, dict) and "name" in n:
|
|
if isinstance(n, dict) and "name" in n:
|
|
|
- existing_nodes_dict[n["name"]] = n
|
|
|
|
|
|
|
+ n_name = n["name"]
|
|
|
|
|
+ n_rate = extract_rate(n_name)
|
|
|
|
|
+ if n_rate is not None:
|
|
|
|
|
+ if n_rate in exclude_rates_set or (args.max_rate is not None and n_rate > args.max_rate):
|
|
|
|
|
+ continue
|
|
|
|
|
+ existing_nodes_dict[n_name] = n
|
|
|
|
|
|
|
|
for item in all_proxies_list:
|
|
for item in all_proxies_list:
|
|
|
existing_nodes_dict[item["name"]] = item
|
|
existing_nodes_dict[item["name"]] = item
|
|
@@ -243,6 +296,15 @@ def main():
|
|
|
port_range_str = f"{min(ports)}" if len(ports) == 1 else f"{min(ports)}~{max(ports)}"
|
|
port_range_str = f"{min(ports)}" if len(ports) == 1 else f"{min(ports)}~{max(ports)}"
|
|
|
generated_country_pools.append((pool_key, c_code.upper(), len(items), port_range_str))
|
|
generated_country_pools.append((pool_key, c_code.upper(), len(items), port_range_str))
|
|
|
|
|
|
|
|
|
|
+ # (3) 清理所有历史池子中的高倍率节点名称,并移除变空的废弃池子
|
|
|
|
|
+ valid_node_names = set(existing_nodes_dict.keys())
|
|
|
|
|
+ for pool_key in list(all_proxies_data["pools"].keys()):
|
|
|
|
|
+ cleaned_pool = [n for n in all_proxies_data["pools"][pool_key] if n in valid_node_names]
|
|
|
|
|
+ if cleaned_pool:
|
|
|
|
|
+ all_proxies_data["pools"][pool_key] = cleaned_pool
|
|
|
|
|
+ else:
|
|
|
|
|
+ del all_proxies_data["pools"][pool_key]
|
|
|
|
|
+
|
|
|
with open(proxies_yaml_path, "w", encoding="utf-8") as f:
|
|
with open(proxies_yaml_path, "w", encoding="utf-8") as f:
|
|
|
yaml.safe_dump(all_proxies_data, f, allow_unicode=True, sort_keys=False)
|
|
yaml.safe_dump(all_proxies_data, f, allow_unicode=True, sort_keys=False)
|
|
|
|
|
|