xulh
commited on
Commit
·
ee70e30
1
Parent(s):
9ac4797
代码初始化
Browse files- video/iqiyi.py +31 -0
video/iqiyi.py
CHANGED
|
@@ -35,3 +35,34 @@ async def video_search(
|
|
| 35 |
except requests.exceptions.RequestException as e:
|
| 36 |
# 处理请求错误
|
| 37 |
raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
except requests.exceptions.RequestException as e:
|
| 36 |
# 处理请求错误
|
| 37 |
raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@app.get("/video-recommend/")
|
| 41 |
+
async def video_search(
|
| 42 |
+
source: str = Query(..., description="资源类型"),
|
| 43 |
+
search_type: str = Query(..., description="返回格式,默认text可选json"),
|
| 44 |
+
hh: str = Query("\n", description="换行符号,默认为\\n")
|
| 45 |
+
):
|
| 46 |
+
api_url = ""
|
| 47 |
+
if source == '1':
|
| 48 |
+
api_url = "https://api.suyanw.cn/api/IQIYI_search_recommendation.php"
|
| 49 |
+
"""
|
| 50 |
+
视频搜索接口 - 封装第三方 API。
|
| 51 |
+
"""
|
| 52 |
+
# 参数传递给第三方API
|
| 53 |
+
params = {
|
| 54 |
+
"type": search_type,
|
| 55 |
+
"hh": hh
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
# 发送请求到第三方API
|
| 60 |
+
response = requests.get(api_url, params=params)
|
| 61 |
+
response.raise_for_status() # 确保HTTP请求成功
|
| 62 |
+
|
| 63 |
+
# 返回第三方API的结果
|
| 64 |
+
return response.text.split(hh)
|
| 65 |
+
|
| 66 |
+
except requests.exceptions.RequestException as e:
|
| 67 |
+
# 处理请求错误
|
| 68 |
+
raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
|