Advertisement
yclee126

YouTube playlist to .mp3 downloader

Nov 12th, 2022
950
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. # YouTube playlist to .mp3 downloader
  2. # download_youtube: https://pastebin.com/c3dsukmk
  3.  
  4. from download_youtube import main as download
  5. from pytube import Playlist
  6. from pathvalidate import sanitize_filename
  7.  
  8. playlist = Playlist(input('Enter YouTube playlist URL: '))
  9. count = playlist.length
  10. title = sanitize_filename(playlist.title)
  11.  
  12. print(f'\nVideo count: {count}, Output folder name: {title}\n\n')
  13.  
  14. # start downloading
  15. error_list = []
  16. real_count = 0
  17. for i, url in enumerate(playlist.video_urls):
  18.     print(f'Video {i+1} of {count}')
  19.     try:
  20.         download(url, title)
  21.     except Exception as e:
  22.         error_string = f'Error on url {url}: {e}'
  23.         error_list.append(error_string)
  24.         print(error_string)
  25.    
  26.     real_count += 1
  27.  
  28. # check if there was unavailable videos
  29. if real_count != count:
  30.     error_list.append(f"One or more videos were unavailable: {count-real_count} video(s) missing")
  31.  
  32. # show errors
  33. if len(error_list) > 0:
  34.     print(f'{len(error_list)} error(s) occured: {error_list}')
  35.     input('Press enter to exit...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement