Python Pytube progress for playlist download
Question:
I am writing a program in python using pytube, and I want to indicate progress when downloading a playlist. When downloading a single video I can do:
YouTube(url, on_progress_callback=progressFunction)
but that doesn’t work when downloading a playlist:
Playlist(url, on_progress_callback=progressFunction)
I get the following error:
TypeError: __init__() got an unexpected keyword argument 'on_progress_callback'
Is there any way to get the progress when downloading a playlist?
Answers:
According to the source code, the Playlist
class doesn’t need on_progress_callback
keyword argument, but only the url
one.
Hey you can get all the urls from the Playlist and then call download one by one.
this works for me all the best.
def getAllLinks(playList):
'''
: This function take a link of playlist and return the link of each videos
:param playList:
:return: A list of all Url links
'''
allLinks = []
youtubeLink = 'https://www.youtube.com'
pl = Playlist(playList)
for linkprefix in pl.parse_links():
allLinks.append(youtubeLink + linkprefix)
return allLinks
from this you will get all the urls and then
def downloadPlaylist(playlistLink):
linkArray = getAllLinks(playlistLink)
for link in linkArray:
downloadVideo(link)
You can use the register_on_progress_callback function to register a download progress callback function post initialization.
An example of this would be:
p = Playlist('https://www.youtube.com/playlist?list=PLetg744TF10BrdPjaEXf4EsJ1wz6fyf95')
for v in p.videos:
v.register_on_progress_callback(progressFunction)
# proceed to downloading...
from pytube import Playlist
from pytube.cli import on_progress
yt_playlist = Playlist(url)
for video in yt_playlist.videos:
video.register_on_progress_callback(on_progress)
video.streams.first().download()
I am writing a program in python using pytube, and I want to indicate progress when downloading a playlist. When downloading a single video I can do:
YouTube(url, on_progress_callback=progressFunction)
but that doesn’t work when downloading a playlist:
Playlist(url, on_progress_callback=progressFunction)
I get the following error:
TypeError: __init__() got an unexpected keyword argument 'on_progress_callback'
Is there any way to get the progress when downloading a playlist?
According to the source code, the Playlist
class doesn’t need on_progress_callback
keyword argument, but only the url
one.
Hey you can get all the urls from the Playlist and then call download one by one.
this works for me all the best.
def getAllLinks(playList):
'''
: This function take a link of playlist and return the link of each videos
:param playList:
:return: A list of all Url links
'''
allLinks = []
youtubeLink = 'https://www.youtube.com'
pl = Playlist(playList)
for linkprefix in pl.parse_links():
allLinks.append(youtubeLink + linkprefix)
return allLinks
from this you will get all the urls and then
def downloadPlaylist(playlistLink):
linkArray = getAllLinks(playlistLink)
for link in linkArray:
downloadVideo(link)
You can use the register_on_progress_callback function to register a download progress callback function post initialization.
An example of this would be:
p = Playlist('https://www.youtube.com/playlist?list=PLetg744TF10BrdPjaEXf4EsJ1wz6fyf95')
for v in p.videos:
v.register_on_progress_callback(progressFunction)
# proceed to downloading...
from pytube import Playlist
from pytube.cli import on_progress
yt_playlist = Playlist(url)
for video in yt_playlist.videos:
video.register_on_progress_callback(on_progress)
video.streams.first().download()