|
@@ -1,69 +1,9 @@
|
|
|
|
|
|
|
|
|
-import json
|
|
|
-import requests
|
|
|
-import re
|
|
|
-from moviepy.editor import VideoFileClip, AudioFileClip, CompositeVideoClip
|
|
|
-
|
|
|
-url = 'https://www.bilibili.com/video/BV1Pt421u7dL/?spm_id_from=pageDriver&vd_source=f6247aa12dae1ff1bce74ef0af381757'
|
|
|
-
|
|
|
-Audio_format = '.mp3'
|
|
|
-Video_format = '.mp4'
|
|
|
-
|
|
|
-Audio_path = 'D:/pyp/bilibili_pachong/bilibili_files/Audio/'
|
|
|
-Video_path = 'D:/pyp/bilibili_pachong/bilibili_files/Video/'
|
|
|
-Synth_path = 'D:/pyp/bilibili_pachong/bilibili_files/Files/'
|
|
|
-
|
|
|
-def GetResponse(url):
|
|
|
- headers = {
|
|
|
- 'accept': 'text / html, application / xhtml + xml, application / xml;q = 0.9, image / avif, image / webp, image / apng, * / *;q = 0.8, application / signed - exchange;v = b3;q = 0.7',
|
|
|
- 'accept - encoding': 'gzip, deflate',
|
|
|
- 'accept - language': 'zh - CN, zh;q = 0.9, en;q = 0.8, en - GB;q = 0.7, en - US;q = 0.6',
|
|
|
- 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
|
|
|
- 'Referer':'https://search.bilibili.com/all?vt=44591831&keyword=%E8%B0%81%E7%94%B5%E5%90%89%E4%BB%96%E8%B0%B1&from_source=webtop_search&spm_id_from=333.1007&search_source=2'
|
|
|
- }
|
|
|
- response = requests.get(url = url,headers = headers)
|
|
|
- return response
|
|
|
-
|
|
|
-def GetVideoInfo() -> str:
|
|
|
- response = GetResponse(url = url)
|
|
|
- html = response.text
|
|
|
-
|
|
|
- info = re.findall('<script>window.__playinfo__=(.*?)</script>', html)[0]
|
|
|
- json_data = json.loads(info)
|
|
|
-
|
|
|
- audio_url = json_data['data']['dash']['audio'][0]['baseUrl']
|
|
|
- video_url = json_data['data']['dash']['video'][0]['baseUrl']
|
|
|
-
|
|
|
-
|
|
|
- title = re.findall('<title data-vue-meta="true">(.*?)</title>', html )
|
|
|
- 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)
|
|
|
-
|
|
|
- print("title:",title)
|
|
|
-
|
|
|
- return (title, audio_url, video_url)
|
|
|
-
|
|
|
-def Save(title,audio_url,video_url):
|
|
|
- audio_content = GetResponse(url = audio_url).content
|
|
|
- video_content = GetResponse(url = video_url).content
|
|
|
-
|
|
|
- with open(Audio_path + title + Audio_format, mode='wb') as audio:
|
|
|
- audio.write(audio_content)
|
|
|
-
|
|
|
- with open(Video_path + title + Video_format, mode='wb') as video:
|
|
|
- video.write(video_content)
|
|
|
+from .utils.setting import Audio_path,Audio_format,Synth_path,Video_format,Video_path
|
|
|
+from moviepy.editor import VideoFileClip, AudioFileClip
|
|
|
+from .utils.GetVideoInfo import GetVideoInfo
|
|
|
+from .utils.Save_bili import Save
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
title,audio_url,video_url = GetVideoInfo()
|
|
@@ -75,11 +15,8 @@ if __name__ == '__main__':
|
|
|
video_path = fr"{Video_path}{title}{Video_format}"
|
|
|
video_clip = VideoFileClip(video_path)
|
|
|
|
|
|
-
|
|
|
audio_clip = audio_clip.set_duration(video_clip.duration)
|
|
|
|
|
|
-
|
|
|
video_clip_with_audio = video_clip.set_audio(audio_clip)
|
|
|
|
|
|
-
|
|
|
video_clip_with_audio.write_videofile(fr"{Synth_path}{title}{Video_format}", codec="libx264", audio_codec="aac")
|