piaoquan_api.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import json
  2. import requests
  3. from tenacity import retry
  4. from requests.exceptions import RequestException
  5. from typing import Optional, Dict, List
  6. from applications.utils import request_retry
  7. retry_desc = request_retry(retry_times=3, min_retry_delay=2, max_retry_delay=30)
  8. @retry(**retry_desc)
  9. def fetch_piaoquan_video_list_detail(video_id_list: List[int]) -> Optional[Dict]:
  10. """
  11. 获取票圈视频详情信息
  12. :param: video_list: 视频id 列表
  13. :return: Detail
  14. """
  15. url = "https://longvideoapi.piaoquantv.com/longvideoapi/openapi/video/batchSelectVideoInfo"
  16. data = {"videoIdList": video_id_list}
  17. header = {
  18. "Content-Type": "application/json",
  19. }
  20. try:
  21. response = requests.post(url, headers=header, json=data, timeout=60)
  22. response.raise_for_status()
  23. return response.json()
  24. except RequestException as e:
  25. print(f"API请求失败: {e}")
  26. except json.JSONDecodeError as e:
  27. print(f"响应解析失败: {e}")
  28. return None
  29. @retry(**retry_desc)
  30. def fetch_piaoquan_account_video_list(account_id: str, page_id: int, page_size: int) -> Optional[Dict]:
  31. """
  32. 获取票圈账号视频信息
  33. :param: account_id: 账号id
  34. :return: account videos
  35. """
  36. import requests
  37. url = f"https://admin.piaoquantv.com/manager/video/page?uid={account_id}&pageNum={page_id}&pageSize={page_size}&categoryId=55&muid=7"
  38. headers = {
  39. 'accept': 'application/json, text/plain, */*',
  40. 'accept-language': 'zh,zh-CN;q=0.9',
  41. 'priority': 'u=1, i',
  42. 'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
  43. 'sec-ch-ua-mobile': '?0',
  44. 'sec-ch-ua-platform': '"macOS"',
  45. 'sec-fetch-dest': 'empty',
  46. 'sec-fetch-mode': 'cors',
  47. 'sec-fetch-site': 'same-origin',
  48. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
  49. 'Cookie': 'SESSION=NGMyMzhkNzQtZmUzMS00ZTAwLTkzMTEtZTYwZThiN2JhNWE3'
  50. }
  51. try:
  52. response = requests.get(url, headers=headers, timeout=60)
  53. response.raise_for_status()
  54. return response.json()
  55. except RequestException as e:
  56. print(f"API请求失败: {e}")
  57. except json.JSONDecodeError as e:
  58. print(f"响应解析失败: {e}")
  59. return None