ke_qq.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import requests
  2. import re
  3. class KeQq:
  4. def __init__(self, url):
  5. self.url = url
  6. self.headers = {
  7. "Referer": "https://ke.qq.com/",
  8. "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36¬",
  9. "Cookie": ""
  10. }
  11. self.taid = re.findall("taid=(\d+)", self.url)[0]
  12. self.vid = ""
  13. def getParams(self):
  14. vid = re.findall("vid=(\d+)", self.url)
  15. if vid:
  16. return self.url.split("#")[0].split("/")[-1], vid[0]
  17. html = requests.get(self.url, headers=self.headers)
  18. params = re.findall(f"data-tid=(\d+)\sdata-taid={self.taid}\sdata-vid=(\d+)", html.text)
  19. return params[0]
  20. def getSign(self):
  21. term_id, fileId = self.getParams()
  22. self.vid = fileId
  23. res = requests.get("https://ke.qq.com/cgi-bin/qcloud/get_token", params={"term_id": term_id, "fileId": fileId},
  24. headers=self.headers).json()
  25. return res["result"]
  26. def start(self):
  27. params = self.getSign()
  28. res = requests.get(f"https://playvideo.qcloud.com/getplayinfo/v2/1258712167/{self.vid}",
  29. params=params, headers=self.headers)
  30. print(res.text)
  31. return res.json()
  32. if __name__ == '__main__':
  33. KeQq("").start()