Cloudmistery hace 9 meses
padre
commit
1f956cec7e

+ 8 - 0
.gitignore

@@ -0,0 +1,8 @@
+*.mp3
+*.aac
+Audio
+Files
+*.mp4
+Video
+
+down

+ 4 - 67
Bilibili.py

@@ -1,69 +1,9 @@
 # -*- coding: UTF-8 -*-
 
-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('<span data-v-492c8232="" class="title-text">(.*?)</span>', html )
-    title = re.findall('<title data-vue-meta="true">(.*?)</title>', html )
-    title = title[0]
-    # print(title)
-
-    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")

+ 16 - 1
utils/GetResponse.py

@@ -1,4 +1,19 @@
 # -*- coding: utf-8 -*-
 # @Author  : ChenZhaoyuchen
 # @Time    : 2024/9/13 15:03
-# @File    : GetResponse.py
+# @File    : GetResponse.py
+
+import requests
+
+headers_bili = {
+    '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://www.bilibili.com/?spm_id_from=333.337.0.0'
+}
+
+def GetResponse(url):
+    headers = headers_bili
+    response = requests.get(url = url,headers = headers)
+    return response

+ 33 - 1
utils/GetVideoInfo.py

@@ -1,4 +1,36 @@
 # -*- coding: utf-8 -*-
 # @Author  : ChenZhaoyuchen
 # @Time    : 2024/9/13 15:02
-# @File    : GetVideoInfo.py
+# @File    : GetVideoInfo.py
+
+import json
+import re
+from .GetResponse import GetResponse
+from .setting import url
+
+def GetVideoInfo() -> str:
+    response = GetResponse(url = url)
+    html_audio = response.text
+
+    info = re.findall('<script>window.__playinfo__=(.*?)</script>', html_audio)[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_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)
+    print("title:",title)
+
+    return (title, audio_url, video_url)

+ 14 - 1
utils/Save_bili.py

@@ -1,4 +1,17 @@
 # -*- coding: utf-8 -*-
 # @Author  : ChenZhaoyuchen
 # @Time    : 2024/9/13 15:02
-# @File    : Save_bili.py
+# @File    : Save_bili.py
+
+from .setting import Audio_path,Audio_format,Video_format,Video_path
+from .GetResponse import GetResponse
+
+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)

BIN
utils/__pycache__/GetResponse.cpython-39.pyc


BIN
utils/__pycache__/GetVideoInfo.cpython-39.pyc


BIN
utils/__pycache__/Save_bili.cpython-39.pyc


BIN
utils/__pycache__/__init__.cpython-39.pyc


BIN
utils/__pycache__/setting.cpython-39.pyc


+ 10 - 1
utils/setting.py

@@ -1,4 +1,13 @@
 # -*- coding: utf-8 -*-
 # @Author  : ChenZhaoyuchen
 # @Time    : 2024/9/13 14:13
-# @File    : setting.py
+# @File    : setting.py
+
+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/'
+
+url = 'https://www.bilibili.com/video/BV1WT421Y7XQ/?spm_id_from=333.337.search-card.all.click&vd_source=f6247aa12dae1ff1bce74ef0af381757'