Reputation: 403
I am trying to download the audio of a video using pytube, but I keep getting an error that I don't understand.
My code is:
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')
The error that I keep getting is:
/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
Can someone explain to me what I am doing wrong, please?
Upvotes: 0
Views: 1016
Reputation:
the keyerror:'cipher'
issue was fixed on the pytube repository a long time ago. You just need to reinstall pytube from the repository link
pip uninstall pytube
pip install git+https://github.com/nficano/pytube
Upvotes: 1
Reputation: 2227
Try it this way:
from pytube import YouTube
yt=YouTube(link)
t=yt.streams.filter(only_audio=True).all()
t[0].download(/path)
Reference:- Download audio from YouTube using pytube
First thing you have to do is:
pip3 uninstall pytube
`pip3 install pytube3`
You can try pytubex
as well
After looking all over for this. This is the only thread I found which has solutions. This problem seems to be because of two files in the pytube3 folder, namely, extract.py and ciphers.py. You need to change some code in them. Visit https://github.com/nficano/pytube/issues/641
Upvotes: 0