【问题标题】:"AttributeError: no attribute 'download " With PyTube“AttributeError: no attribute 'download” 使用 PyTube
【发布时间】:2020-11-19 07:07:47
【问题描述】:

我在使用 YouTube 时遇到了 pytube 问题

from pytube import YouTube
url = str(input("Youtube video url :"))
youtube = YouTube(url)
stream = youtube.streams()
video.download(0)

这个错误显示

AttributeError: 'YouTube' object has no attribute 'download'

当我使用播放列表时

from pytube import Playlist
playlist = Playlist('https://www.youtube.com/playlist?list=PLRfY4Rc-GWzhdCvSPR7aTV0PJjjiSAGMs')
print('Number of videos in playlist: %s' % len(playlist.video_urls))
playlist.download_all()

显示同样的错误

AttributeError: 'Playlist' object has no attribute 'download_all'

【问题讨论】:

标签: python pytube


【解决方案1】:

您需要从您创建的YouTube 对象的Stream 中获取第一个流。如果您查看the documentation,您可能会知道这一点。

试试这个下载视频:

from pytube import YouTube
url = str(input("Youtube video url :"))
youtube = YouTube(url)
youtube.streams.first().download()

对于播放列表,试试这个:

from pytube import Playlist
playlist = Playlist('https://www.youtube.com/playlist?list=PLRfY4Rc-GWzhdCvSPR7aTV0PJjjiSAGMs')
print('Number of videos in playlist: %s' % len(playlist.video_urls))

# Loop through all videos in the playlist and download them
for video in playlist.videos:
    video.streams.first().download()

【讨论】:

    【解决方案2】:

    Youtube 功能没有“下载”功能,即使用 Youtube 我们无法下载视频。

    例如: yt = YouTube(url).download() #输出=错误

    只有使用流,我们才能下载视频。不需要导入流。

    例如: yt = YouTube(url).streams.download() #输出=成功

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 2022-12-01
      • 2020-04-26
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 2022-12-15
      • 2022-12-27
      • 1970-01-01
      相关资源
      最近更新 更多