Spaces:
Running
Running
rogerxavier
commited on
Commit
•
4117d38
1
Parent(s):
3f92a54
Upload 6 files
Browse files- app.py +27 -0
- getNode.py +38 -0
- randomSubscribeUrl.py +108 -0
- requirements.txt +8 -0
- subscribeLink.txt +2 -0
- validSubCount.py +18 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from server.utils import config
|
3 |
+
from getNode import router as GetNodeRouter
|
4 |
+
from randomSubscribeUrl import router as randomSubscribeUrlRouter
|
5 |
+
from validSubCount import router as validSubCountRouter
|
6 |
+
import uvicorn
|
7 |
+
app = FastAPI()
|
8 |
+
fileName = "subscribeLink.txt"
|
9 |
+
randomSubscribeUrlRouter.fileName = fileName
|
10 |
+
validSubCountRouter.fileName = fileName
|
11 |
+
GetNodeRouter.fileName = fileName
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
@app.get("/uu.json", tags=["Root"])
|
16 |
+
async def read_root() -> dict:
|
17 |
+
return config
|
18 |
+
|
19 |
+
#全局路由
|
20 |
+
app.include_router(GetNodeRouter, prefix="/getNode")
|
21 |
+
app.include_router(randomSubscribeUrlRouter, prefix="/randomSubscribeUrl")
|
22 |
+
app.include_router(validSubCountRouter, prefix="/validSubCount")
|
23 |
+
|
24 |
+
#这个是部署hf上
|
25 |
+
if __name__ == '__main__':
|
26 |
+
uvicorn.run(app, host='0.0.0.0', port=7860)
|
27 |
+
|
getNode.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import requests
|
4 |
+
from server.decoder import decode_url_to_configs
|
5 |
+
from server.utils import config,headers
|
6 |
+
import random
|
7 |
+
from fastapi import APIRouter,BackgroundTasks
|
8 |
+
from randomSubscribeUrl import subscription_link_list,getRandomSubscribeUrl,delete_invalid_url_in_txt
|
9 |
+
|
10 |
+
|
11 |
+
router = APIRouter()
|
12 |
+
@router.get('/')
|
13 |
+
def getNode(background_tasks: BackgroundTasks)->str:
|
14 |
+
# 返回一个可用的订阅链接信息
|
15 |
+
SubscribeUrlList = subscription_link_list(router.fileName)
|
16 |
+
# 直接用现成的认为可用然后直接返回,之后再删不可用的
|
17 |
+
randomSubscribeUrl= getRandomSubscribeUrl(SubscribeUrlList)
|
18 |
+
NodeList = dump_configs(randomSubscribeUrl)
|
19 |
+
for i in NodeList:
|
20 |
+
print("nodelist包含"+i)
|
21 |
+
NodeStr = RandomNode(NodeList)
|
22 |
+
|
23 |
+
background_tasks.add_task(delete_invalid_url_in_txt, router.fileName)
|
24 |
+
return NodeStr
|
25 |
+
|
26 |
+
def RandomNode(NodeList:list)->str:
|
27 |
+
#返回一个节点信息
|
28 |
+
return random.choice(NodeList)
|
29 |
+
|
30 |
+
|
31 |
+
def dump_configs(url:str)->list:
|
32 |
+
#返回全部节点信息的列表
|
33 |
+
configs = decode_url_to_configs(url)
|
34 |
+
return configs
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
randomSubscribeUrl.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import requests
|
4 |
+
import random
|
5 |
+
from fastapi import APIRouter, BackgroundTasks
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
# 添加headers模拟浏览器访问(针对juzi等特殊订阅)
|
11 |
+
headers = {
|
12 |
+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
13 |
+
'accept-language': 'zh-CN,zh;q=0.9',
|
14 |
+
'cache-control': 'max-age=0',
|
15 |
+
'priority': 'u=0, i',
|
16 |
+
'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
|
17 |
+
'sec-ch-ua-mobile': '?0',
|
18 |
+
'sec-ch-ua-platform': '"macOS"',
|
19 |
+
'sec-fetch-dest': 'document',
|
20 |
+
'sec-fetch-mode': 'navigate',
|
21 |
+
'sec-fetch-site': 'none',
|
22 |
+
'sec-fetch-user': '?1',
|
23 |
+
'upgrade-insecure-requests': '1',
|
24 |
+
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
|
25 |
+
}
|
26 |
+
|
27 |
+
|
28 |
+
def is_subscription_link_valid(subscribeUrl: str) -> bool:
|
29 |
+
try:
|
30 |
+
result = requests.get(subscribeUrl,headers=headers).text
|
31 |
+
if "error" in result:
|
32 |
+
return False
|
33 |
+
return True
|
34 |
+
except Exception as e:
|
35 |
+
#这里如果只是请求超时那么认为正常返回true,比如juzi sub判断时候连接超时
|
36 |
+
print('判断sub link是否有效时候发生错误:',e)
|
37 |
+
return True
|
38 |
+
|
39 |
+
|
40 |
+
def delete_invalid_url_in_txt(fileName: str) -> "void":
|
41 |
+
valid_lines = []
|
42 |
+
with open(fileName, "r") as file:
|
43 |
+
lines = file.readlines()
|
44 |
+
for line in lines:
|
45 |
+
email = line.strip().split(",")[0]
|
46 |
+
subscription_url = line.strip().split(",")[1]
|
47 |
+
if is_subscription_link_valid(subscription_url):
|
48 |
+
valid_lines.append(line)
|
49 |
+
else:
|
50 |
+
print(email + "订阅已经不可用")
|
51 |
+
# 将有效行重新写回文件
|
52 |
+
with open(fileName, "w") as file:
|
53 |
+
file.writelines(valid_lines)
|
54 |
+
|
55 |
+
|
56 |
+
def subscription_link_list(fileName: str) -> list:
|
57 |
+
SubscribeUrlList = []
|
58 |
+
with open(fileName, "r") as f:
|
59 |
+
lines = f.readlines()
|
60 |
+
for line in lines:
|
61 |
+
subscription_url = line.strip().split(",")[1]
|
62 |
+
SubscribeUrlList.append(subscription_url)
|
63 |
+
return SubscribeUrlList
|
64 |
+
|
65 |
+
|
66 |
+
def subscription_link_valid_list(SubscribeUrlList: list) -> list:
|
67 |
+
valid_link_list = list(filter(lambda f: is_subscription_link_valid(f), SubscribeUrlList))
|
68 |
+
##返回可用订阅链接前对原始文件进行删除不可用链接操作:
|
69 |
+
return valid_link_list
|
70 |
+
|
71 |
+
|
72 |
+
def read_random_line(fileName: str) -> str:
|
73 |
+
with open(fileName, "r") as file:
|
74 |
+
lines = file.readlines()
|
75 |
+
return random.choice(lines)
|
76 |
+
|
77 |
+
|
78 |
+
def getRandomSubscribeUrl(validSubscribeUrlList: list) -> str:
|
79 |
+
# 返回一个可用的订阅链接信息
|
80 |
+
return random.choice(validSubscribeUrlList)
|
81 |
+
|
82 |
+
|
83 |
+
router = APIRouter()
|
84 |
+
|
85 |
+
#此接口目前唯一作用是方便调试查看订阅剩余状态
|
86 |
+
@router.get('/')
|
87 |
+
def returnRandomSubscribeUrl(background_tasks: BackgroundTasks) -> str:
|
88 |
+
# 返回一个可用的订阅链接信息
|
89 |
+
SubscribeUrlList = subscription_link_list(router.fileName)
|
90 |
+
#直接用现成的认为可用然后直接返回,之后再删不可用的
|
91 |
+
result = getRandomSubscribeUrl(SubscribeUrlList)
|
92 |
+
background_tasks.add_task(delete_invalid_url_in_txt, router.fileName)
|
93 |
+
return result
|
94 |
+
|
95 |
+
# return hf_test()
|
96 |
+
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
if __name__ == "__main__":
|
101 |
+
print()
|
102 |
+
|
103 |
+
##思路是随机选取一行订阅检测,如果没问题就返回
|
104 |
+
# 1订阅有问题,那么
|
105 |
+
##1->对全部订阅扫描,删除不可用的,然后重新随机一个返回,此返回时不用检测
|
106 |
+
##2->如果扫描后没有可用的,那么不做处理让vercel报错
|
107 |
+
|
108 |
+
# 1订阅一个都没有,那么vercel错误提醒(不做处理考虑就行)
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#gradio
|
2 |
+
uvicorn[standard]==0.17.*
|
3 |
+
requests==2.31.0
|
4 |
+
aiohttp==3.7.3
|
5 |
+
fastapi==0.95.0
|
6 |
+
urllib3==2.0.7
|
7 |
+
uvicorn
|
8 |
+
#这个适用hf和windows
|
subscribeLink.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
hanryr,https://s.juzicloud.vip/link/3Dv3anqm7fBcTxcT?sub=3
|
2 |
+
971,http://sub2.cutecloud.net/link/cDNGUOivouRigbSc?sub=3
|
validSubCount.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import requests
|
4 |
+
from fastapi import APIRouter,BackgroundTasks
|
5 |
+
|
6 |
+
|
7 |
+
def ValidSubCount(fileName:str)->int:
|
8 |
+
with open(fileName, "r") as f:
|
9 |
+
lines = f.readlines()
|
10 |
+
return len(lines)
|
11 |
+
|
12 |
+
|
13 |
+
router = APIRouter()
|
14 |
+
|
15 |
+
@router.get('/')
|
16 |
+
def returnValidSubCount():
|
17 |
+
# 获取当前剩余的有效订阅数量 (方便随时检测)
|
18 |
+
return ValidSubCount(router.fileName)
|