# -*- coding: utf-8 -*- import yaml import os def xfltd(serial): # 获取当前路径 current_path = os.getcwd() yaml_path = os.path.join(current_path, 'XFLTD.yaml') if not os.path.exists(f'{yaml_path}'): return with open(f'{yaml_path}', 'r', encoding='utf-8') as file: config = yaml.safe_load(file) split_config_path = os.path.join(current_path, 'split_config') if not os.path.exists(split_config_path): os.makedirs(split_config_path) # 为每个代理创建一个新的配置文件 for proxy in config['proxies']: if '剩余流量' in proxy['name'] or '套餐到期' in proxy['name']: continue new_config = { "mixed-port": config["mixed-port"], "allow-lan": config["allow-lan"], "bind-address": config["bind-address"], "mode": config["mode"], "log-level": config["log-level"], "external-controller": config["external-controller"], "dns": config["dns"], "proxies": [proxy], # 只包含当前代理 "proxy-groups": [{'name': 'XFLTD', 'type': 'select', 'proxies': [proxy['name']]}], "rules": config["rules"] } config_name = 'config_' + str(serial).zfill(4) + '.yaml' save_file_path = os.path.join(split_config_path, config_name) # 将新的配置写入文件 with open(save_file_path, 'w', encoding='utf-8') as outfile: yaml.dump(new_config, outfile, allow_unicode=True, indent=4) print(f'Generated {config_name}') serial += 1 return serial def bitz(serial): # 获取当前路径 current_path = os.getcwd() yaml_path = os.path.join(current_path, 'Bitz Net.yaml') if not os.path.exists(f'{yaml_path}'): return with open(f'{yaml_path}', 'r', encoding='utf-8') as file: config = yaml.safe_load(file) # 获取当前路径 current_path = os.getcwd() split_config_path = os.path.join(current_path, 'split_config') if not os.path.exists(split_config_path): os.makedirs(split_config_path) # 为每个代理创建一个新的配置文件 for proxy in config['proxies']: new_config = { "allow-lan": config["allow-lan"], "bind-address": config["bind-address"], "dns": config["dns"], "external-controller": config["external-controller"], "log-level": config["log-level"], "mixed-port": config["mixed-port"], "mode": config["mode"], "proxies": [proxy], # 只包含当前代理 "proxy-groups": [ { "name": "Bitz Net", "proxies": [proxy["name"]], "type": "select" }, { "interval": 86400, "name": "自动选择", "proxies": [proxy["name"]], "type": "url-test", "url": "http://www.gstatic.com/generate_204" }, { "interval": 7200, "name": "故障转移", "proxies": [proxy["name"]], "type": "fallback", "url": "http://www.gstatic.com/generate_204" } ], "rules": config["rules"] } config_name = 'config_' + str(serial).zfill(4) + '.yaml' save_file_path = os.path.join(split_config_path, config_name) # 将新的配置写入文件 with open(save_file_path, 'w', encoding='utf-8') as outfile: yaml.dump(new_config, outfile, allow_unicode=True, indent=4) print(f'Generated {config_name}') serial += 1 return serial def patriot(serial): current_path = os.getcwd() yaml_path = os.path.join(current_path, 'index.php.yaml') if not os.path.exists(f'{yaml_path}'): return # 读取原始的 YAML 配置文件 with open(f'{yaml_path}', 'r', encoding='utf-8') as file: config = yaml.safe_load(file) # 获取当前路径 current_path = os.getcwd() split_config_path = os.path.join(current_path, 'split_config') if not os.path.exists(split_config_path): os.makedirs(split_config_path) # 为每个代理创建一个新的配置文件 for proxy in config['proxies']: new_config = { "port": config["port"], "socks-port": config["socks-port"], "allow-lan": config["allow-lan"], "mode": config["mode"], "log-level": config["log-level"], "external-controller": config["external-controller"], "secret": config["secret"], "proxies": [proxy], "proxy-groups": [ {"name": "auto", "type": "url-test", "proxies": [proxy["name"]], "url": "https://www.bing.com", "interval": 300}, {"name": "fallback-auto", "type": "fallback", "proxies": [proxy["name"]], "url": "https://www.bing.com", "interval": 300}, {"name": "select", "type": "select", "proxies": [proxy["name"]]} ], "rules": config["rules"] } config_name = 'config_' + str(serial).zfill(4) + '.yaml' save_file_path = os.path.join(split_config_path, config_name) # 将新的配置写入文件 with open(save_file_path, 'w', encoding='utf-8') as outfile: yaml.dump(new_config, outfile, allow_unicode=True, indent=4) print(f'Generated {config_name}') serial += 1 return serial if __name__ == '__main__': serial = 1 serial = xfltd(serial) serial = patriot(serial) serial = bitz(serial) print(f'线路总数: {serial - 1}')