GetVideoInfo.py 1002 B

123456789101112131415161718192021222324252627282930313233343536
  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
  8. from .setting import url
  9. def GetVideoInfo() -> str:
  10. response = GetResponse(url = url)
  11. html_audio = response.text
  12. info = re.findall('<script>window.__playinfo__=(.*?)</script>', html_audio)[0]
  13. json_data = json.loads(info)
  14. audio_url = json_data['data']['dash']['audio'][0]['baseUrl']
  15. video_url = json_data['data']['dash']['video'][0]['baseUrl']
  16. title = re.findall('<title data-vue-meta="true">(.*?)</title>', html_audio)
  17. title = title[0]
  18. if title:
  19. illegal_chars = fr'<|>\/:"*?'
  20. def remove_illegal_chars(title_ill):
  21. for char in illegal_chars:
  22. title_ill = title_ill.replace(char, "")
  23. return title_ill
  24. else:
  25. return None
  26. title = remove_illegal_chars(title)
  27. print("title:",title)
  28. return (title, audio_url, video_url)