Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pytube import YouTube, Playlist
- import progressbar
- pl = Playlist(url= "") # Enter YouTube playlist link here.
- pl.populate_video_urls()
- print("[INFO] Number of Links: {}".format(len(pl.video_urls)))
- widgets = ["[INFO] Downloading Video: ", progressbar.Percentage(), " ", progressbar.Bar(), " ", progressbar.ETA()]
- def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None):
- #Gets the percentage of the file that has been downloaded.
- current_value = file_size - remaining
- pbar.update(current_value)
- for i, url in enumerate(pl.video_urls[:]):
- flag = 0
- counter = 0
- while flag is 0:
- try:
- yt = YouTube(url= url, on_progress_callback=progress_Check)
- print(i, yt.title)
- type_vid = yt.streams.filter(only_audio= True, mime_type= "audio/mp4").first()
- file_size = type_vid.filesize
- pbar = progressbar.ProgressBar(maxval= file_size, widgets= widgets)
- pbar = pbar.start()
- type_vid.download()
- flag= 1
- pbar.finish()
- except ConnectionResetError:
- counter += 1
- print("[INFO] Error Counter: {}".format(counter), end= " ")
Add Comment
Please, Sign In to add comment