我有一个问题时,从pytube模块下载视频,我尝试更新pytube,再次下载,仍然不工作,我使用的是python 3.11,这是我的代码:
'定义进程函数(流,块,剩余字节):打印(“下载”)def完成函数(流,文件路径):print(“下载完成”)messagebox.showinfo(title=“下载完成”,message=“视频下载成功”)
def下载():用户输入=字符串(链接.get())yt = YouTube(用户输入,进度回调=进度函数,完成回调=完成函数)打印(yt.标题)打印(yt.缩略图url)视频= yt.流.get_highest_resolution()video.download()'
这就是错误所在:Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\---\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\main.py", line 30, in download video = yt.streams.get_highest_resolution() ^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\__main__.py", line 296, in streams return StreamQuery(self.fmt_streams) ^^^^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\__main__.py", line 181, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\extract.py", line 409, in apply_signature cipher = Cipher(js=js) ^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\cipher.py", line 29, in __init__ self.throttling_plan = get_throttling_plan(js) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\cipher.py", line 404, in get_throttling_plan transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1) ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'span'
使用pytube下载youtube视频。
1条答案
按热度按时间yqkkidmi1#
这是
pytube
库中的一个错误。这是由于YouTube对其JavaScript代码进行了一些更改而导致的。要修复它,请查看pytube
Github中的此建议。进入你的
pytube
库文件夹,找到cipher.py
文件,修改第411行:该正则表达式是引发错误的正则表达式,请改为:
最终
pytube
将发布更新并修复此错误。