1+ import re
2+ import asyncio
3+ import sys
4+
5+ import httpx
6+
7+ from _utils import vv_generator
8+
9+
10+ def check_vv_generator_format () -> bool :
11+ """
12+ 校验 vv_generator 返回一个非空的十六进制字符串。
13+ 纯本地检查,不依赖网络。
14+ """
15+ vv = vv_generator ()
16+
17+ if not isinstance (vv , str ):
18+ print ("❌ vv 应该是字符串" )
19+ return False
20+
21+ if len (vv ) <= 20 :
22+ print (f"❌ vv 看起来太短,可能生成失败: { vv } " )
23+ return False
24+
25+ if not re .fullmatch (r"[0-9a-f]+" , vv ):
26+ print (f"❌ vv 包含非十六进制字符: { vv } " )
27+ return False
28+
29+ print (f"✅ vv_generator 格式正常: { vv } " )
30+ return True
31+
32+
33+ async def check_upstream_relay_search () -> bool :
34+ """
35+ 请求上游轻量接口,验证 relay 是否可达。
36+ 会真正访问 api.olelive.com。
37+ """
38+ vv = vv_generator ()
39+ url = f"https://api.olelive.com/v1/pub/index/vod/hot/4/0/1?_vv={ vv } "
40+ headers = {"User-Agent" : "animeapi-test/1.0" }
41+
42+ try :
43+ async with httpx .AsyncClient (timeout = 30.0 ) as client :
44+ resp = await client .get (url , headers = headers )
45+
46+ if resp .status_code != 200 :
47+ print (f"❌ 上游返回非 200 状态: { resp .status_code } " )
48+ print (f"响应内容: { resp .text } " )
49+ return False
50+
51+ try :
52+ data = resp .json ()
53+ except Exception as e :
54+ print (f"❌ 上游返回内容无法解析为 JSON: { e } " )
55+ print (f"响应内容: { resp .text } " )
56+ return False
57+
58+ if not isinstance (data , (dict , list )):
59+ print (f"❌ 上游返回的数据不是 JSON 对象或数组: { type (data )} " )
60+ return False
61+
62+ print ("✅ 上游 relay 可达,返回 JSON 数据" )
63+ print (data )
64+ return True
65+
66+ except httpx .TimeoutException :
67+ print ("❌ 请求上游超时" )
68+ return False
69+ except httpx .RequestError as e :
70+ print (f"❌ 请求上游失败: { e } " )
71+ return False
72+
73+
74+ async def main () -> int :
75+ print ("开始检查 vv_generator..." )
76+ vv_ok = check_vv_generator_format ()
77+
78+ print ("\n 开始检查上游 relay..." )
79+ upstream_ok = await check_upstream_relay_search ()
80+
81+ if vv_ok and upstream_ok :
82+ print ("\n 🎉 全部检查通过" )
83+ return 0
84+
85+ print ("\n 💥 检查未通过" )
86+ return 1
87+
88+
89+ if __name__ == "__main__" :
90+ exit_code = asyncio .run (main ())
91+ sys .exit (exit_code )
0 commit comments