MGTV.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import base64
  2. import requests
  3. import uuid
  4. import time
  5. class MGTV:
  6. def __init__(self, url):
  7. self.url = url
  8. def get_video_id(self):
  9. return self.url.split("/", 5)[-1].split(".")[0]
  10. def get_pm2(self):
  11. did = "e6e13014-393b-43e7-b6be-2323e4960939"
  12. suuid = uuid.uuid4()
  13. pno = "1030"
  14. # tk2 = self.encode_tk2(did, pno)
  15. params = {
  16. "did": did,
  17. "suuid": suuid,
  18. "cxid": "",
  19. "tk2": self.encode_tk2(did, pno),
  20. "type": "pch5",
  21. "video_id": self.get_video_id(),
  22. "_support": "10000000",
  23. "auth_mode": "1",
  24. "src": "",
  25. "abroad": "",
  26. }
  27. res = requests.get("https://pcweb.api.mgtv.com/player/video", params=params).json()
  28. return res['data']['atc']['pm2']
  29. def encode_tk2(self, did="e6e13014-393b-43e7-b6be-2323e4960939", pno="1030"):
  30. tk2 = bytes(f"did={did}|pno={pno}|ver=0.3.0301|clit={int(time.time())}".encode())
  31. tk2 = base64.b64encode(tk2).decode().replace("/\+/g", "_").replace("/\//g", "~").replace("/=/g", "-")
  32. tk2 = list(' '.join(tk2).split())
  33. tk2.reverse()
  34. return "".join(tk2)
  35. def start(self):
  36. params = {
  37. "_support": "10000000",
  38. "tk2": self.encode_tk2(),
  39. "pm2": self.get_pm2(),
  40. "video_id": self.get_video_id(),
  41. "type": "pch5",
  42. "auth_mode": "1",
  43. "src": "",
  44. "abroad": "",
  45. }
  46. res = requests.get("https://pcweb.api.mgtv.com/player/getSource", params=params).json()
  47. print(res)
  48. return res
  49. if __name__ == '__main__':
  50. MGTV().start()