Guest User

Untitled

a guest
Nov 16th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. from pytube import YouTube, Playlist
  2.  
  3. import progressbar
  4.  
  5. pl = Playlist(url= "") # Enter YouTube playlist link here.
  6. pl.populate_video_urls()
  7.  
  8. print("[INFO] Number of Links: {}".format(len(pl.video_urls)))
  9.  
  10. widgets = ["[INFO] Downloading Video: ", progressbar.Percentage(), " ", progressbar.Bar(), " ", progressbar.ETA()]
  11.  
  12. def progress_Check(stream = None, chunk = None, file_handle = None, remaining = None):
  13. #Gets the percentage of the file that has been downloaded.
  14. current_value = file_size - remaining
  15. pbar.update(current_value)
  16.  
  17. for i, url in enumerate(pl.video_urls[:]):
  18. flag = 0
  19. counter = 0
  20. while flag is 0:
  21. try:
  22. yt = YouTube(url= url, on_progress_callback=progress_Check)
  23. print(i, yt.title)
  24. type_vid = yt.streams.filter(only_audio= True, mime_type= "audio/mp4").first()
  25. file_size = type_vid.filesize
  26. pbar = progressbar.ProgressBar(maxval= file_size, widgets= widgets)
  27. pbar = pbar.start()
  28. type_vid.download()
  29. flag= 1
  30. pbar.finish()
  31. except ConnectionResetError:
  32. counter += 1
  33. print("[INFO] Error Counter: {}".format(counter), end= " ")
Add Comment
Please, Sign In to add comment