GetVideoInfo.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 utils.GetResponse import *
  8. from pprint import pprint
  9. video_json = {
  10. }
  11. def GetVideoInfo() -> str:
  12. response_video = GetResponse_AV()
  13. html_video = response_video.text
  14. info_video = re.findall('<script>window.__playinfo__=(.*?)</script>', html_video)[0]
  15. json_data_video = json.loads(info_video)
  16. video_url = json_data_video['data']['dash']['video'][0]['baseUrl']
  17. return video_url
  18. def GetAudioInfo() -> str:
  19. response_audio = GetResponse_AV()
  20. html_audio = response_audio.text
  21. info_audio = re.findall('<script>window.__playinfo__=(.*?)</script>', html_audio)[0]
  22. json_data_audio = json.loads(info_audio)
  23. audio_url = json_data_audio['data']['dash']['audio'][0]['baseUrl']
  24. return audio_url
  25. def GetTitile() -> str:
  26. # response_audio = GetResponse_AV()
  27. # html = response_audio.text
  28. # title = re.findall('<title data-vue-meta="true">(.*?)</title>', html)[0]
  29. # print("原件名称:",title)
  30. # video_json[title] = title
  31. html = GetResponse_AV().text
  32. title = re.findall('title="(.*?)"', html)[0]
  33. # if not title:
  34. # title = '未知'
  35. if title:
  36. illegal_chars = fr'<|>\/:"*?'
  37. def remove_illegal_chars(title_ill):
  38. for char in illegal_chars:
  39. title_ill = title_ill.replace(char, "")
  40. return title_ill
  41. title = remove_illegal_chars(title)
  42. else:
  43. return None
  44. # elif len(title) > 30:
  45. # title = title[:30]
  46. print('合法名称:',title)
  47. return title
  48. # 仅用作测试
  49. def GetHTML():
  50. response = GetResponse_AV()
  51. html = response.text
  52. return html
  53. # # 测试代码
  54. if __name__ == '__main__':
  55. A = GetAudioInfo()
  56. print(A)
  57. B = GetVideoInfo()
  58. print(B)
  59. C = GetTitile()
  60. print('修饰过后名字为:',C)
  61. D = GetHTML()
  62. pprint(D)