migu.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import requests
  2. class migu:
  3. def __init__(self, url):
  4. self.url = url
  5. self.headers = {
  6. "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¬"
  7. }
  8. self.cid = self.get_cid_or_mgdbId()
  9. def get_cid_or_mgdbId(self):
  10. if 'cid' in self.url:
  11. return self.url.split("?")[-1].split("=")[-1]
  12. return self.mgdbId_cover_pid(self.url.split("?")[-1].split("=")[-1])
  13. def get_params(self):
  14. return {
  15. "contId": self.cid,
  16. }
  17. def mgdbId_cover_pid(self, mgdbId):
  18. url = f"https://app-sc.miguvideo.com/vms-worldcup/v3/basic-data/all-view-list/{mgdbId}/2/3000060800"
  19. res = requests.get(url, headers=self.headers).json()['body']['replayList']
  20. if len(res) > 1:
  21. for k, i in enumerate(res):
  22. print(f'{k}->{i["name"]}')
  23. print("检测到多个视频请选择你要解析视频的序号-> ")
  24. pid = res[int(input("==> "))]['pID']
  25. return pid
  26. def str_cover_list(self, str):
  27. return list(str)
  28. def get_ddCalcu(self, puData_url):
  29. params_dict = {}
  30. query_string = puData_url.split("?")[-1]
  31. for i in query_string.split("&"):
  32. temp = i.split("=")
  33. params_dict[temp[0]] = temp[1]
  34. puData_list = self.str_cover_list(params_dict['puData'])
  35. p = 0
  36. result = []
  37. while (2 * p) < len(puData_list):
  38. result.append(puData_list[len(puData_list) - p - 1])
  39. if p < len(puData_list) - p - 1:
  40. result.append(params_dict['puData'][p])
  41. if p == 1:
  42. result.append('e')
  43. if p == 2:
  44. result.append(self.str_cover_list(params_dict['timestamp'])[6])
  45. if p == 3:
  46. result.append(self.str_cover_list(params_dict['ProgramID'])[2])
  47. if p == 4:
  48. result.append(self.str_cover_list(params_dict['Channel_ID'])[
  49. len(self.str_cover_list(params_dict['Channel_ID'])) - 4])
  50. p += 1
  51. return ''.join(result)
  52. def calc_url(self, url):
  53. ddCalcu = self.get_ddCalcu(url)
  54. return f"{url}&ddCalcu={ddCalcu}"
  55. def start(self):
  56. res = requests.get("https://webapi.miguvideo.com/gateway/playurl/v3/play/playurl", params=self.get_params(),
  57. headers=self.headers)
  58. puData_url = res.json()['body']['urlInfo']['url']
  59. url = self.calc_url(puData_url)
  60. print(url)
  61. if __name__ == '__main__':
  62. migu().start()