Advertisement
FanaticExplorer

my_download_code

Oct 15th, 2021
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. from yt_dlp import YoutubeDL
  2. import os
  3.  
  4.  
  5. ydl_opts = {
  6.             'outtmpl':"%(title)s.mp4",
  7.             'format': 'best',
  8.             'noplaylist' : True
  9. }
  10.  
  11. def download_video(link):
  12.     with YoutubeDL(ydl_opts) as ydl:
  13.         result = ydl.extract_info("{}".format(link), download=False)
  14.         filename=ydl.prepare_filename(result)
  15.         if os.path.isfile(filename):
  16.             os.remove(filename)
  17.         ydl.download([link])
  18.         return filename
  19.  #i made "rerurn filename" because i need to get the name of the file so i can do this
  20. your_video_was_saved='Your video was saved as %s'
  21. my_video=download_video('https://www.youtube.com/watch?v=O0QDEXZhow4')
  22. print(your_video_was_saved % my_video)
  23. #or
  24. videonote = open(download_video('https://www.youtube.com/watch?v=RsQT4_acf2M'), 'rb')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement