KeyError:' list'使用Pytube向用户询问输入()的URL之后

发布于 2025-02-05 20:49:16 字数 2468 浏览 2 评论 0原文

我尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海似她心 2025-02-12 20:49:16
  url = input(“ https://youtube.com/playlist?list=plvxmnucog69uwwg59uvuyj9solrhe78kp”)
 

如果仅按Enter,这并不意味着url现在是字符串“ https://youtube.com/playlist?list=plvxmnucog69uwwg59uwwg59uvuyj9solrhe78kp”

相反,input()函数将URL显示为a 提示向用户显示并返回用户输入的内容,因此在这种情况下:没有。因此,url实际上是一个空字符串。因此,Pytube无法从(空)URL解析播放列表ID。

您的意思是:

url = input("Enter the URL: ")

然后当程序运行时,您必须输入URL并按Enter。

或者:

url = "https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp"

程序只使用固定的URL而不询问用户。

url = input("https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp")

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. So url actually is an empty string. Therefore, pytube fails to parse the playlist ID from the (empty) URL.

What you meant was either:

url = input("Enter the URL: ")

and then when the program runs you have to enter the URL and press Enter.

Or:

url = "https://youtube.com/playlist?list=PLVxmNUcoG69uwwG59UVUyJ9SoLRHE78kp"

where the program just uses a fixed URL and does not ask the user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文