KeyError:' list'使用Pytube向用户询问输入()的URL之后
我尝试在YouTube中下载整个播放列表并使用此代码。
我还更新了Pytube,pip,python,并尝试更改代码,但我不知道如何。
这是我第一次编码,我需要一个好的YouTube转换器。
from pytube.contrib.playlist import Playlist
from pytube import YouTube
from pytube.cli import on_progress
url = input("https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp")
playlist = Playlist(url)
print("Total Videos: ", len(playlist.video_urls))
for video_url in playlist.video_urls:
yt = YouTube(video_url, on_progress_callback=on_progress)
stream = yt.streams.get_highest_resolution()
print(yt.title)
stream.download(filename=yt.title + ".mp4")
这是我的错误。当我在链接显示后链接插入文本后,单击Enter时。
https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp
-- Click Enter
Traceback (most recent call last):
File "/Users/jonasmaier/Desktop/downi you/codes/playlist.py", line 7, in <module>
print("Total Videos: ",len(playlist.video_urls))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/helpers.py", line 89, in __len__
self.generate_all()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/helpers.py", line 105, in generate_all
next_item = next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 281, in url_generator
for page in self._paginate():
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 118, in _paginate
json.dumps(extract.initial_data(self.html))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 58, in html
self._html = request.get(self.playlist_url)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 48, in playlist_url
return f"https://www.youtube.com/playlist?list={self.playlist_id}"
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 39, in playlist_id
self._playlist_id = extract.playlist_id(self._input_url)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/extract.py", line 151, in playlist_id
return parse_qs(parsed.query)['list'][0]
KeyError: 'list'
I try to download a whole playlist in Youtube and use this code.
I also updated pytube, pip, Python, and try to change the code, but I don't know how.
It's my first time to code and I need a good Youtube converter.
from pytube.contrib.playlist import Playlist
from pytube import YouTube
from pytube.cli import on_progress
url = input("https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp")
playlist = Playlist(url)
print("Total Videos: ", len(playlist.video_urls))
for video_url in playlist.video_urls:
yt = YouTube(video_url, on_progress_callback=on_progress)
stream = yt.streams.get_highest_resolution()
print(yt.title)
stream.download(filename=yt.title + ".mp4")
And this is my error. When I click enter after the link plops up the text after the link shows up.
https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp
-- Click Enter
Traceback (most recent call last):
File "/Users/jonasmaier/Desktop/downi you/codes/playlist.py", line 7, in <module>
print("Total Videos: ",len(playlist.video_urls))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/helpers.py", line 89, in __len__
self.generate_all()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/helpers.py", line 105, in generate_all
next_item = next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 281, in url_generator
for page in self._paginate():
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 118, in _paginate
json.dumps(extract.initial_data(self.html))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 58, in html
self._html = request.get(self.playlist_url)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 48, in playlist_url
return f"https://www.youtube.com/playlist?list={self.playlist_id}"
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/contrib/playlist.py", line 39, in playlist_id
self._playlist_id = extract.playlist_id(self._input_url)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pytube/extract.py", line 151, in playlist_id
return parse_qs(parsed.query)['list'][0]
KeyError: 'list'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果仅按Enter,这并不意味着
url
现在是字符串“ https://youtube.com/playlist?list=plvxmnucog69uwwg59uwwg59uvuyj9solrhe78kp”
。相反,
input()
函数将URL显示为a 提示向用户显示并返回用户输入的内容,因此在这种情况下:没有。因此,url
实际上是一个空字符串。因此,Pytube无法从(空)URL解析播放列表ID。您的意思是:
然后当程序运行时,您必须输入URL并按Enter。
或者:
程序只使用固定的URL而不询问用户。
If you just press Enter, this does not mean that
url
is now the string"https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp"
.Rather, the
input()
function displays the URL as a prompt to the user and returns what the user enters, so in this case: nothing. Sourl
actually is an empty string. Therefore, pytube fails to parse the playlist ID from the (empty) URL.What you meant was either:
and then when the program runs you have to enter the URL and press Enter.
Or:
where the program just uses a fixed URL and does not ask the user.