xulh commited on
Commit
7f394e7
·
1 Parent(s): 5fb9efa

代码初始化

Browse files
Files changed (1) hide show
  1. video/iqiyi.py +13 -10
video/iqiyi.py CHANGED
@@ -1,7 +1,10 @@
1
  from fastapi import APIRouter, Query, HTTPException
2
  import requests
3
  from pydantic import BaseModel
4
- from utils.utils import generate_signature
 
 
 
5
  import time
6
 
7
  routerVideo = APIRouter()
@@ -74,10 +77,11 @@ async def video_search(
74
  class SearchVideoRequest(BaseModel):
75
  date: str # 时间
76
  videoName: str # 视频名称
 
77
 
78
 
79
  @routerVideo.post("/video/search")
80
- async def search_videos(request: SearchVideoRequest):
81
  """
82
  搜索视频接口
83
  :param date: 时间
@@ -90,13 +94,17 @@ async def search_videos(request: SearchVideoRequest):
90
  "videoName": request.videoName
91
  }
92
  # 签名
93
- sign = generate_signature(params)
 
 
94
 
95
  # 设置请求头
96
  headers = {
97
- "Sign": sign,
98
  "Accept": "application/json, text/plain, */*",
99
- "origin": "https://wantwatch.me"
 
 
100
  }
101
 
102
  try:
@@ -110,8 +118,3 @@ async def search_videos(request: SearchVideoRequest):
110
  except requests.exceptions.RequestException as e:
111
  # 处理请求错误
112
  raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")
113
-
114
-
115
- if __name__ == '__main__':
116
- timestamp_ms = int(time.time() * 1000)
117
- search_videos(timestamp_ms, "我是刑警")
 
1
  from fastapi import APIRouter, Query, HTTPException
2
  import requests
3
  from pydantic import BaseModel
4
+ # from utils.utils import generate_signature
5
+ import hmac
6
+ import hashlib
7
+ import json
8
  import time
9
 
10
  routerVideo = APIRouter()
 
77
  class SearchVideoRequest(BaseModel):
78
  date: str # 时间
79
  videoName: str # 视频名称
80
+ sign: str
81
 
82
 
83
  @routerVideo.post("/video/search")
84
+ def search_videos(request: SearchVideoRequest):
85
  """
86
  搜索视频接口
87
  :param date: 时间
 
94
  "videoName": request.videoName
95
  }
96
  # 签名
97
+ # data_str = json.dumps(params)
98
+ # sign = hmac.new("OArmXWpMeX8n".encode('utf-8'), data_str.encode('utf-8'), hashlib.sha256).hexdigest()
99
+ # sign = generate_signature(params)
100
 
101
  # 设置请求头
102
  headers = {
103
+ "Sign": request.sign,
104
  "Accept": "application/json, text/plain, */*",
105
+ "Accept-Encoding": "gzip, deflate, br", # 加入 br
106
+ "origin": "https://wantwatch.me",
107
+ "Content-Type": "application/json; charset=utf-8",
108
  }
109
 
110
  try:
 
118
  except requests.exceptions.RequestException as e:
119
  # 处理请求错误
120
  raise HTTPException(status_code=500, detail=f"请求第三方API出错: {str(e)}")