xulh commited on
Commit
9471b22
·
1 Parent(s): fe2e75b

代码初始化

Browse files
Files changed (1) hide show
  1. video/iqiyi.py +46 -0
video/iqiyi.py CHANGED
@@ -71,3 +71,49 @@ async def video_search(
71
  except requests.exceptions.RequestException as e:
72
  # 处理请求错误
73
  raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  except requests.exceptions.RequestException as e:
72
  # 处理请求错误
73
  raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
74
+
75
+
76
+ # 定义请求体模型
77
+ class SearchVideoRequest(BaseModel):
78
+ date: int # 时间
79
+ videoName: str # 视频名称
80
+ sign: str
81
+
82
+
83
+ @routerVideo.post("/video/search")
84
+ def search_videos(request: SearchVideoRequest):
85
+ """
86
+ 搜索视频接口
87
+ :param date: 时间
88
+ :param videoName: 视频名称
89
+ :return: 符合条件的视频列表
90
+ """
91
+ api_url = "https://api.q168.vip/api/search"
92
+ params = {
93
+ "videoName": request.videoName
94
+ }
95
+ # 签名
96
+ # data_str = json.dumps(params)
97
+ # sign = hmac.new("OArmXWpMeX8n".encode('utf-8'), data_str.encode('utf-8'), hashlib.sha256).hexdigest()
98
+ # sign = generate_signature(params)
99
+
100
+ # 设置请求头
101
+ headers = {
102
+ "Sign": request.sign,
103
+ "Accept": "application/json, text/plain, */*",
104
+ "Accept-Encoding": "gzip, deflate, br", # 加入 br
105
+ "origin": "https://wantwatch.me",
106
+ "Content-Type": "application/json; charset=utf-8",
107
+ }
108
+
109
+ try:
110
+ # 发送请求到第三方API
111
+ response = requests.post(api_url, data=params, headers=headers)
112
+ response.raise_for_status() # 确保HTTP请求成功
113
+
114
+ # 返回第三方API的结果
115
+ return response.json()
116
+
117
+ except requests.exceptions.RequestException as e:
118
+ # 处理请求错误
119
+ raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")