xulh
commited on
Commit
·
9ac4797
1
Parent(s):
1a3a6e5
代码初始化
Browse files- video/__init__.py +0 -0
- video/iqiyi.py +37 -0
video/__init__.py
ADDED
File without changes
|
video/iqiyi.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Query, HTTPException
|
2 |
+
import requests
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
# 第三方API地址
|
7 |
+
EXTERNAL_API_URL = "https://api.suyanw.cn/api/Iqiyi_video_search.php"
|
8 |
+
|
9 |
+
|
10 |
+
@app.get("/video-search/")
|
11 |
+
async def video_search(
|
12 |
+
msg: str = Query(..., description="需要搜索的视频内容"),
|
13 |
+
n: int = Query(0, description="选择序号"),
|
14 |
+
size: int = Query(10, description="搜索内容列表数"),
|
15 |
+
hh: str = Query("\n", description="换行符号,默认为\\n")
|
16 |
+
):
|
17 |
+
"""
|
18 |
+
视频搜索接口 - 封装第三方 API。
|
19 |
+
"""
|
20 |
+
# 参数传递给第三方API
|
21 |
+
params = {
|
22 |
+
"msg": msg,
|
23 |
+
"n": n,
|
24 |
+
"size": size,
|
25 |
+
"hh": hh
|
26 |
+
}
|
27 |
+
try:
|
28 |
+
# 发送请求到第三方API
|
29 |
+
response = requests.get(EXTERNAL_API_URL, params=params)
|
30 |
+
response.raise_for_status() # 确保HTTP请求成功
|
31 |
+
|
32 |
+
# 返回第三方API的结果
|
33 |
+
return response.text.split(hh)
|
34 |
+
|
35 |
+
except requests.exceptions.RequestException as e:
|
36 |
+
# 处理请求错误
|
37 |
+
raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
|