"AttributeError: no attribute 'download " With PyTube

Question:

I have a problem with pytube when use YouTube

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

this error shows

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

and when I use playlist

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()

Shows the same error

AttributeError: 'Playlist' object has no attribute 'download_all'
Asked By: Mohamed Samir

||

Answers:

You need to get the first stream from the Stream of the YouTube object that you created. If you look at the documentation you could have know this.

Try this for downloading the video:

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

For the playlist try this:

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()
Answered By: funie200

Youtube function doesn’t have function "download" i.e using Youtube we cannot download a video.

Eg:
yt = YouTube(url).download()
#output = error

Only using streams we can download a video. It is not needed to import stream.

Eg:
yt = YouTube(url).streams.download()
#output = success

Answered By: shaila
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.