我希望使用 PyTube 下载 YouTube 播放列表图书馆。目前,我一次只能下载一个视频。我一次无法下载多个视频。
目前,我的实现是
import pytube
link = input('Please enter a url link\n')
yt = pytube.YouTube(link)
stream = yt.streams.first()
finished = stream.download()
print('Download is complete')
这会导致以下输出
>> Download is complete
YouTube 文件已下载。当我尝试使用播放列表链接 ( An example ) 时,只会下载第一个视频。没有错误输出。
我希望能够在不重新提示用户的情况下下载整个播放列表。
请您参考如下方法:
您可以导入 Playlist 来实现这一点。尽管在 GitHub repo found here 中有一个部分,但在 redoc 中没有提到播放列表。 .脚本的源代码在 repo here 中。 .
from pytube import Playlist
playlist = Playlist('https://www.youtube.com/watch?v=58PpYacL-VQ&list=UUd6MoB9NC6uYN2grvUNT-Zg')
print('Number of videos in playlist: %s' % len(playlist.video_urls))
playlist.download_all()
注意:我发现支持方法 Playlist.video_urls 不起作用。然而,视频仍在下载,as evidenced here
