Spaces:
Running
Running
Upload 3 files
Browse files- getServerList.py +18 -12
- server/decoder.py +20 -4
- subscribeLink.txt +2 -1
getServerList.py
CHANGED
@@ -3,30 +3,36 @@
|
|
3 |
from server.decoder import decode_url_to_configs
|
4 |
import base64
|
5 |
from fastapi import APIRouter,BackgroundTasks
|
6 |
-
from randomSubscribeUrl import subscription_link_list,getRandomSubscribeUrl
|
7 |
|
8 |
|
9 |
router = APIRouter()
|
10 |
@router.get('/')
|
11 |
def getServerList(background_tasks: BackgroundTasks)->str:
|
12 |
-
#
|
13 |
SubscribeUrlList = subscription_link_list(router.fileName)
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# 将字符串转换为字节串
|
22 |
combined_links_bytes = combined_links.encode("utf-8")
|
23 |
-
|
24 |
# 对字节串进行 Base64 编码
|
25 |
encoded_links = base64.b64encode(combined_links_bytes)
|
26 |
-
|
27 |
# 将编码后的字节串转换为字符串
|
28 |
encoded_links_str = encoded_links.decode("utf-8")
|
29 |
-
# 输出 Base64
|
30 |
return encoded_links_str
|
31 |
|
32 |
|
|
|
3 |
from server.decoder import decode_url_to_configs
|
4 |
import base64
|
5 |
from fastapi import APIRouter,BackgroundTasks
|
6 |
+
from randomSubscribeUrl import subscription_link_list,getRandomSubscribeUrl
|
7 |
|
8 |
|
9 |
router = APIRouter()
|
10 |
@router.get('/')
|
11 |
def getServerList(background_tasks: BackgroundTasks)->str:
|
12 |
+
# 获取订阅链接列表
|
13 |
SubscribeUrlList = subscription_link_list(router.fileName)
|
14 |
+
# 初始化一个空列表,用于存储所有解析出的节点
|
15 |
+
all_node_lists = []
|
16 |
+
# 遍历每个订阅链接
|
17 |
+
for subscribe_url in SubscribeUrlList:
|
18 |
+
try:
|
19 |
+
# 尝试解析当前订阅链接
|
20 |
+
NodeList = dump_configs(subscribe_url)
|
21 |
+
# 如果解析成功,将解析出的节点列表添加到总列表中
|
22 |
+
all_node_lists.extend(NodeList)
|
23 |
+
except Exception as e:
|
24 |
+
# 如果解析失败,打印错误信息并继续处理下一个订阅链接
|
25 |
+
print(f"解析订阅链接 {subscribe_url} 时发生错误: {e}")
|
26 |
+
|
27 |
+
# 将所有节点拼接成一个字符串,每个节点之间用换行符分隔
|
28 |
+
combined_links = "\n".join(all_node_lists)
|
29 |
# 将字符串转换为字节串
|
30 |
combined_links_bytes = combined_links.encode("utf-8")
|
|
|
31 |
# 对字节串进行 Base64 编码
|
32 |
encoded_links = base64.b64encode(combined_links_bytes)
|
|
|
33 |
# 将编码后的字节串转换为字符串
|
34 |
encoded_links_str = encoded_links.decode("utf-8")
|
35 |
+
# 输出 Base64 编码后的订阅地址集合
|
36 |
return encoded_links_str
|
37 |
|
38 |
|
server/decoder.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
#!/usr/bin/env python
|
3 |
# -*- coding: utf-8 -*-
|
4 |
import re
|
@@ -31,6 +30,24 @@ class EncodedCfg:
|
|
31 |
nameinfo: str = ""
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
class ListDecoder(BaseDecoder):
|
35 |
def iter_encode_config(self) -> Iterator[EncodedCfg]:
|
36 |
for config_str in self.decode_str.splitlines():
|
@@ -54,7 +71,7 @@ class ListDecoder(BaseDecoder):
|
|
54 |
yield _encoded_config_str_without_type+"&allowInsecure=1"+"#"+nameinfo
|
55 |
|
56 |
if ("vmess" in config_str):
|
57 |
-
vmess_decoded_data =
|
58 |
vmess_info_json = json.loads(vmess_decoded_data)
|
59 |
vmess_info_str = json.dumps(vmess_info_json,ensure_ascii=False)#不转译中文
|
60 |
if ('倍率提示'not in vmess_info_str)and('导航' not in vmess_info_str) and('443' not in vmess_info_str):
|
@@ -99,6 +116,5 @@ def _get_listencoded_cfg_from_encoded_str(encoded_str: str) -> List[EncodedCfg]:
|
|
99 |
|
100 |
def decode_url_to_configs(url: str)->list:
|
101 |
encoded_str = _get_resource_from_url(url)
|
102 |
-
##https://github.com/CareyWang/sub-web 成功用这个订阅解析解决了订阅被cf格挡问题,且可用于sspanel
|
103 |
lst_encoded_cfg = _get_listencoded_cfg_from_encoded_str(encoded_str)#lst_encoded_cfg解析为节点后的列表,包含所有节点链接
|
104 |
-
return lst_encoded_cfg
|
|
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
import re
|
|
|
30 |
nameinfo: str = ""
|
31 |
|
32 |
|
33 |
+
def decode_base64_with_filter(encoded_str):
|
34 |
+
# 定义合法的 Base64 字符集(包括字母、数字、加号、斜杠和等号)
|
35 |
+
base64_pattern = re.compile(r'[^A-Za-z0-9+/=]')
|
36 |
+
|
37 |
+
# 过滤掉非 Base64 字符
|
38 |
+
filtered_str = base64_pattern.sub('', encoded_str)
|
39 |
+
|
40 |
+
# 确保字符串长度是4的倍数(Base64编码要求)
|
41 |
+
while len(filtered_str) % 4:
|
42 |
+
filtered_str += '='
|
43 |
+
|
44 |
+
try:
|
45 |
+
# 解码
|
46 |
+
decoded_bytes = b64decode(filtered_str)
|
47 |
+
return decoded_bytes.decode('utf-8')
|
48 |
+
except Exception as e:
|
49 |
+
return f"解码失败: {e}"
|
50 |
+
|
51 |
class ListDecoder(BaseDecoder):
|
52 |
def iter_encode_config(self) -> Iterator[EncodedCfg]:
|
53 |
for config_str in self.decode_str.splitlines():
|
|
|
71 |
yield _encoded_config_str_without_type+"&allowInsecure=1"+"#"+nameinfo
|
72 |
|
73 |
if ("vmess" in config_str):
|
74 |
+
vmess_decoded_data = decode_base64_with_filter(_config_str)
|
75 |
vmess_info_json = json.loads(vmess_decoded_data)
|
76 |
vmess_info_str = json.dumps(vmess_info_json,ensure_ascii=False)#不转译中文
|
77 |
if ('倍率提示'not in vmess_info_str)and('导航' not in vmess_info_str) and('443' not in vmess_info_str):
|
|
|
116 |
|
117 |
def decode_url_to_configs(url: str)->list:
|
118 |
encoded_str = _get_resource_from_url(url)
|
|
|
119 |
lst_encoded_cfg = _get_listencoded_cfg_from_encoded_str(encoded_str)#lst_encoded_cfg解析为节点后的列表,包含所有节点链接
|
120 |
+
return lst_encoded_cfg
|
subscribeLink.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
335,https://sublink.cute-cloud.de/link?token=176ba293ad7f4e3c8ebd53cb6d7eadbc
|
|
|
|
1 |
+
335,https://sublink.cute-cloud.de/link?token=176ba293ad7f4e3c8ebd53cb6d7eadbc
|
2 |
+
jms from git,https://jmssub.net/members/getsub.php?service=131783&id=a35aa5ea-5893-41bc-86c9-5d283bd9cd68&usedomains=1
|