forked from 3878590578/VPSscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge_subscriptions.py
More file actions
177 lines (152 loc) · 5.34 KB
/
merge_subscriptions.py
File metadata and controls
177 lines (152 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Clash 订阅合并脚本 - GitHub Actions 版本
自动下载订阅,合并节点,生成配置文件
"""
import requests
import yaml
from datetime import datetime
import sys
# ========== 订阅配置 ==========
SUBSCRIPTION_URLS = [
"https://substore.panell.top/share/file/%E4%B8%91%E5%9B%A21?token=ChouLink1",
"https://substore.panell.top/share/file/%E4%B8%91%E5%9B%A22?token=ChouLink2",
"https://substore.panell.top/share/file/%E4%B8%91%E5%9B%A23?token=ChouLink3",
"https://substore.panell.top/share/file/%E4%B8%91%E5%9B%A24?token=ChouLink4",
]
OUTPUT_FILE = "config.yaml"
def download_subscription(url):
"""下载订阅"""
try:
print(f" 下载: {url[:50]}...")
response = requests.get(url, timeout=30)
response.raise_for_status()
return yaml.safe_load(response.text)
except Exception as e:
print(f" ✗ 失败: {e}")
return None
def merge_proxies(subscriptions):
"""合并节点并去重"""
all_proxies = []
seen_names = set()
for sub in subscriptions:
if not sub or 'proxies' not in sub:
continue
for proxy in sub['proxies']:
original_name = proxy['name']
name = original_name
counter = 1
while name in seen_names:
name = f"{original_name}-{counter}"
counter += 1
proxy['name'] = name
seen_names.add(name)
all_proxies.append(proxy)
return all_proxies
def generate_config(proxies):
"""生成配置文件"""
proxy_names = [p['name'] for p in proxies]
return {
'mixed-port': 7890,
'allow-lan': True,
'bind-address': '*',
'mode': 'rule',
'log-level': 'info',
'ipv6': False,
'external-controller': '127.0.0.1:9090',
'external-ui': 'ui',
'dns': {
'enable': True,
'ipv6': False,
'listen': '0.0.0.0:53',
'enhanced-mode': 'fake-ip',
'fake-ip-range': '198.18.0.1/16',
'nameserver': ['223.5.5.5', '119.29.29.29'],
'fallback': ['https://1.1.1.1/dns-query', 'https://dns.google/dns-query']
},
'proxies': proxies,
'proxy-groups': [
{
'name': '🚀 节点选择',
'type': 'select',
'proxies': ['♻️ 自动选择', '🔯 故障转移', 'DIRECT'] + proxy_names
},
{
'name': '♻️ 自动选择',
'type': 'url-test',
'proxies': proxy_names,
'url': 'http://www.gstatic.com/generate_204',
'interval': 300,
'tolerance': 50
},
{
'name': '🔯 故障转移',
'type': 'fallback',
'proxies': proxy_names,
'url': 'http://www.gstatic.com/generate_204',
'interval': 300
},
{
'name': '🛑 广告拦截',
'type': 'select',
'proxies': ['REJECT', 'DIRECT']
}
],
'rule-providers': {
'reject': {
'type': 'http',
'behavior': 'domain',
'url': 'https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/reject.txt',
'path': './ruleset/reject.yaml',
'interval': 86400
},
'proxy': {
'type': 'http',
'behavior': 'domain',
'url': 'https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt',
'path': './ruleset/proxy.yaml',
'interval': 86400
},
'direct': {
'type': 'http',
'behavior': 'domain',
'url': 'https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/direct.txt',
'path': './ruleset/direct.yaml',
'interval': 86400
}
},
'rules': [
'RULE-SET,reject,🛑 广告拦截',
'RULE-SET,direct,DIRECT',
'RULE-SET,proxy,🚀 节点选择',
'GEOIP,CN,DIRECT',
'MATCH,🚀 节点选择'
]
}
def main():
print("=" * 60)
print("Clash 订阅合并工具")
print(f"时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 60)
# 下载订阅
print(f"\n[1/3] 下载 {len(SUBSCRIPTION_URLS)} 个订阅")
subscriptions = [download_subscription(url) for url in SUBSCRIPTION_URLS]
subscriptions = [s for s in subscriptions if s]
if not subscriptions:
print("\n❌ 错误:没有成功下载任何订阅")
sys.exit(1)
# 合并节点
print(f"\n[2/3] 合并节点")
proxies = merge_proxies(subscriptions)
print(f" ✓ 共 {len(proxies)} 个节点")
# 生成配置
print(f"\n[3/3] 生成配置文件")
config = generate_config(proxies)
with open(OUTPUT_FILE, 'w', encoding='utf-8') as f:
yaml.dump(config, f, allow_unicode=True, sort_keys=False)
print(f" ✓ 已保存: {OUTPUT_FILE}")
print("\n" + "=" * 60)
print("✅ 完成")
if __name__ == '__main__':
main()