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