DouYu.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import execjs
  2. import requests
  3. import re
  4. import time
  5. class DouYu:
  6. def __init__(self, room_id):
  7. self.room_id = room_id
  8. self.int_time = int(time.time())
  9. self.did = "3966acse00dd10qer895bdca00031601"
  10. def get_ub98484234(self):
  11. res = requests.get(f"https://www.douyu.com/{self.room_id}").text
  12. ub98484234 = re.findall("(function ub98484234.*?})var", res)[0]
  13. var = re.findall("var\sv\s=\s(.*?)[.]slice", ub98484234)[0]
  14. var1 = re.findall(f"(var {var}=.*?);", res)[0]
  15. return f"var CryptoJS = require('crypto-js');{var1};{ub98484234}"
  16. def get_sign(self):
  17. js = execjs.compile(self.get_ub98484234())
  18. res = js.call("ub98484234", self.room_id, self.did, self.int_time)
  19. return res.split("sign=")[-1]
  20. def get_params(self):
  21. return {
  22. 'v': f'2201{time.strftime("%Y%m%d", time.localtime())}',
  23. 'did': self.did,
  24. 'tt': self.int_time,
  25. 'sign': self.get_sign(),
  26. 'cdn': "tct-h5",
  27. 'rate': '0',
  28. 'ver': 'Douyu_221041305',
  29. 'iar': '0',
  30. 'ive': '1',
  31. 'hevc': '0',
  32. 'fa': '1',
  33. }
  34. def start(self):
  35. res = requests.post(f"https://www.douyu.com/lapi/live/getH5Play/{self.room_id}", data=self.get_params()).json()
  36. print(res)
  37. if __name__ == '__main__':
  38. DouYu().start()