瀏覽代碼

完全版

Cloudmistery 7 月之前
父節點
當前提交
79960eef71

+ 6 - 0
README.md

@@ -17,6 +17,12 @@
 ###2024/9/19
 `用分离请求头方法重写中,还有部分错误`
 
+###2024/9/20
+`完全版`
+
+`为何会出错?
+每个模块都应当独立出来,可以不作为一个文件,也必须def方法`
+
 ##阅读文档
 `1.设置原网址url,格式为番号后缀删除;设置文件地址`
 

+ 3 - 2
utils/Clip_bili.py

@@ -4,11 +4,12 @@
 # @File    : Clip_bili.py
 from bilibili_files.utils.setting import Audio_path,Audio_format,Synth_path,Video_format,Video_path
 from moviepy.editor import VideoFileClip, AudioFileClip
-from bilibili_files.utils.GetVideoInfo import GetVideoInfo,GetAudioInfo
+from bilibili_files.utils.GetVideoInfo import GetVideoInfo,GetAudioInfo,GetTitile
 from bilibili_files.utils.Save_bili import Saveaudio,Savevideo
 
 def Clip_bilibili():
-    title, video_url = GetVideoInfo()
+    title = GetTitile()
+    video_url = GetVideoInfo()
     Savevideo(title, video_url)
     audio_url = GetAudioInfo()
     Saveaudio(title, audio_url)

+ 2 - 6
utils/GetResponse.py

@@ -10,12 +10,8 @@ headers_bili_video = {
     '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',
-    'TE': 'Trailers',
-    'Range': 'bytes=0-',
-    'Origin': base_url,
-    'Connection': 'keep-alive',
-    'DNT': '1',
-    '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'
+    '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'
 }
 
 headers_bili_audio = {

+ 10 - 18
utils/GetVideoInfo.py

@@ -19,34 +19,26 @@ def GetVideoInfo() -> str:
 
     video_url = json_data_video['data']['dash']['video'][0]['baseUrl']
 
-    title = re.findall('<title data-vue-meta="true">(.*?)</title>', 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)
+    return video_url
 
 def GetAudioInfo() -> str:
     response_audio = GetResponse_audio(url = url)
 
     html_audio = response_audio.text
 
-    info_audio = re.findall('<script>window.__playinfo__=(.*?)</script>', html_audio)[0]
+    info_audio = re.findall(r'<script>window.__playinfo__=(.*?)</script>', html_audio)[0]
 
     json_data_audio = json.loads(info_audio)
 
     audio_url = json_data_audio['data']['dash']['audio'][0]['baseUrl']
 
+    return audio_url
+
+def GetTitile():
+    response_audio = GetResponse_audio(url = url)
+
+    html_audio = response_audio.text
+
     title = re.findall('<title data-vue-meta="true">(.*?)</title>', html_audio)
 
     title = title[0]
@@ -61,8 +53,8 @@ def GetAudioInfo() -> str:
         return None
 
     title = remove_illegal_chars(title)
+    return title
 
-    return (title,audio_url)
 
 
 # # 测试代码

二進制
utils/__pycache__/Clip_bili.cpython-39.pyc


二進制
utils/__pycache__/GetResponse.cpython-39.pyc


二進制
utils/__pycache__/GetVideoInfo.cpython-39.pyc