我正在尝试使用pytube下载视频的音频,但是我不断收到我不理解的错误。
我的代码是:
from pytube import YouTube
lista_de_videos = ["https://www.youtube.com/watch?v=iYYRH4apXDo"]
for video in lista_de_videos:
yt = YouTube(video)
yt.streams.get_audio_only().download('/Users/applemacosx/Downloads')
我一直遇到的错误是:
/Users/applemacosx/PycharmProjects/pythonProject6/venv/bin/python /Users/applemacosx/PycharmProjects/pythonProject6/download.py
Traceback (most recent call last):
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 288, in apply_descrambler
stream_data[key] = [
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 290, in <listcomp>
"url": format_item["url"],
KeyError: 'url'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/applemacosx/PycharmProjects/pythonProject6/download.py", line 84, in <module>
yt = YouTube(video)
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/__main__.py", line 92, in __init__
self.descramble()
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/__main__.py", line 132, in descramble
apply_descrambler(self.player_config_args, fmt)
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 300, in apply_descrambler
cipher_url = [
File "/Users/applemacosx/PycharmProjects/pythonProject6/venv/lib/python3.8/site-packages/pytube/extract.py", line 301, in <listcomp>
parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
KeyError: 'cipher'
Process finished with exit code 1
有人可以向我解释我做错了吗?
答案 0 :(得分:1)
keyerror:'cipher'
问题早已在pytube存储库中修复。您只需要从存储库链接中重新安装pytube
pip uninstall pytube
pip install git+https://github.com/nficano/pytube
答案 1 :(得分:0)
尝试一下:
from pytube import YouTube
yt=YouTube(link)
t=yt.streams.filter(only_audio=True).all()
t[0].download(/path)
参考:-Download audio from YouTube using pytube
您要做的第一件事是:
pip3 uninstall pytube
`pip3 install pytube3`
您也可以尝试pytubex
到处寻找这个。这是我发现的唯一具有解决方案的线程。该问题似乎是由于pytube3文件夹中有两个文件,即extract.py和ciphers.py。您需要更改其中的一些代码。访问 https://github.com/nficano/pytube/issues/641