# -*- coding: utf-8 -*-
# @Author : ChenZhaoyuchen
# @Time : 2024/9/13 15:02
# @File : GetVideoInfo.py
import json
import re
from GetResponse import GetResponse_video,GetResponse_audio
from setting import url
def GetVideoInfo() -> str:
response_video = GetResponse_video(url = url)
html_video = response_video.text
info_video = re.findall('', html_video)[0]
json_data_video = json.loads(info_video)
video_url = json_data_video['data']['dash']['video'][0]['baseUrl']
title = re.findall('
(.*?)', html_video)
title = title[0]
if title:
illegal_chars = fr'<|>\/:"*?'
def remove_illegal_chars(title_ill):
for char in illegal_chars:
title_ill = title_ill.replace(char, "")
return title_ill
else:
return None
title = remove_illegal_chars(title)
return (title,video_url)
def GetAudioInfo() -> str:
response_audio = GetResponse_audio(url = url)
html_audio = response_audio.text
info_audio = re.findall('', html_audio)[0]
json_data_audio = json.loads(info_audio)
audio_url = json_data_audio['data']['dash']['audio'][0]['baseUrl']
title = re.findall('(.*?)', html_audio)
title = title[0]
if title:
illegal_chars = fr'<|>\/:"*?'
def remove_illegal_chars(title_ill):
for char in illegal_chars:
title_ill = title_ill.replace(char, "")
return title_ill
else:
return None
title = remove_illegal_chars(title)
return (title,audio_url)
# # 测试代码
# if __name__ == '__main__':
# A = GetAudioInfo()
# B = GetVideoInfo()
# print(A,B)