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