GetVideoInfo.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. # @Author : ChenZhaoyuchen
  3. # @Time : 2024/9/13 15:02
  4. # @File : GetVideoInfo.py
  5. import json
  6. import re
  7. from GetResponse import GetResponse_video,GetResponse_audio
  8. from setting import url
  9. def GetVideoInfo() -> str:
  10. response_video = GetResponse_video(url = url)
  11. html_video = response_video.text
  12. info_video = re.findall('<script>window.__playinfo__=(.*?)</script>', html_video)[0]
  13. json_data_video = json.loads(info_video)
  14. video_url = json_data_video['data']['dash']['video'][0]['baseUrl']
  15. return video_url
  16. def GetAudioInfo() -> str:
  17. response_audio = GetResponse_audio(url = url)
  18. html_audio = response_audio.text
  19. info_audio = re.findall(r'<script>window.__playinfo__=(.*?)</script>', html_audio)[0]
  20. json_data_audio = json.loads(info_audio)
  21. audio_url = json_data_audio['data']['dash']['audio'][0]['baseUrl']
  22. return audio_url
  23. def GetTitile():
  24. response_audio = GetResponse_audio(url = url)
  25. html_audio = response_audio.text
  26. title = re.findall('<title data-vue-meta="true">(.*?)</title>', html_audio)
  27. title = title[0]
  28. if title:
  29. illegal_chars = fr'<|>\/:"*?'
  30. def remove_illegal_chars(title_ill):
  31. for char in illegal_chars:
  32. title_ill = title_ill.replace(char, "")
  33. return title_ill
  34. else:
  35. return None
  36. title = remove_illegal_chars(title)
  37. return title
  38. # # 测试代码
  39. # if __name__ == '__main__':
  40. # A = GetAudioInfo()
  41. # B = GetVideoInfo()
  42. # print(A,B)