Guest User

Untitled

a guest
Jul 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. # Cool script. Not sure if you are still improving it but I see one thing right away that you could create a dl_video method to eliminate the duplicate download video code. E.g.:
  2.  
  3. def dl_video(link):
  4. download_video = link.streams().first()
  5. print('Download Started')
  6. download_video.download('videos/')
  7.  
  8. # And while you're at it, a dl_audio:
  9.  
  10. def dl_audio(link):
  11. download_mp3 = link.streams.filter(only_audio=True).first()
  12. print('Download Started')
  13. download_mp3.download('audio/')
  14.  
  15. # So it'll look like this:
  16.  
  17. ...
  18.  
  19. while True:
  20. user = input('To Download Video/Audio Y/n: ')
  21. if user == 'Y':
  22. url = input('Enter Url: ')
  23. link = YouTube(url)
  24. form = input('Do you want to download video or audio: ')
  25. if form == 'video':
  26. dl_video(link)
  27. elif form == 'audio':
  28. warn = input('Audio Downloads take longer Do you want to Continue Y/n: ')
  29. if warn == 'Y':
  30. dl_audio(link)
  31. elif warn == 'n':
  32. vid = input('To Download Vid Y/n ')
  33. if vid == 'Y':
  34. dl_video(link)
  35. elif vid == 'n':
  36. exit()
  37.  
  38. ...
Add Comment
Please, Sign In to add comment