ClearCode

demo project

Mar 24th, 2022
2,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from pytube import YouTube
  2. from colorama import init, Fore
  3.  
  4. def on_complete(stream, filepath):
  5.     print('download complete')
  6.     print(filepath)
  7.  
  8. def on_progress(stream, chunk, bytes_remaining):
  9.     progress_string = f'{round(100 - (bytes_remaining / stream.filesize * 100),2)}%'
  10.     print(progress_string)
  11.  
  12. init()
  13. link = input('Youtube link: ')
  14. video_object = YouTube(link, on_complete_callback = on_complete, on_progress_callback = on_progress)
  15.  
  16. # information
  17. print(Fore.RED + f'title:  \033[39m {video_object.title}')
  18. print(Fore.RED + f'length: \033[39m {round(video_object.length / 60,2)} minutes')
  19. print(Fore.RED + f'views:  \033[39m {video_object.views / 1000000} million')
  20. print(Fore.RED + f'author: \033[39m {video_object.author}')
  21.  
  22. # download
  23. print(
  24.     Fore.RED + 'download:' +
  25.     Fore.GREEN + '(b)est \033[39m|' +
  26.     Fore.YELLOW + '(w)orst \033[39m|' +
  27.     Fore.BLUE + '(a)udio \033[39m| (e)xit')
  28. download_choice = input('choice: ')
  29.  
  30. match download_choice:
  31.     case 'b':
  32.         video_object.streams.get_highest_resolution().download(r'C:\Users\Christian\Downloads')
  33.     case 'w':
  34.         video_object.streams.get_lowest_resolution().download(r'C:\Users\Christian\Downloads')
  35.     case 'a':
  36.         video_object.streams.get_audio_only().download(r'C:\Users\Christian\Downloads')
Advertisement
Add Comment
Please, Sign In to add comment