Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from yt_dlp import YoutubeDL
- import os
- ydl_opts = {
- 'outtmpl':"%(title)s.mp4",
- 'format': 'best',
- 'noplaylist' : True
- }
- def download_video(link):
- with YoutubeDL(ydl_opts) as ydl:
- result = ydl.extract_info("{}".format(link), download=False)
- filename=ydl.prepare_filename(result)
- if os.path.isfile(filename):
- os.remove(filename)
- ydl.download([link])
- return filename
- #i made "rerurn filename" because i need to get the name of the file so i can do this
- your_video_was_saved='Your video was saved as %s'
- my_video=download_video('https://www.youtube.com/watch?v=O0QDEXZhow4')
- print(your_video_was_saved % my_video)
- #or
- videonote = open(download_video('https://www.youtube.com/watch?v=RsQT4_acf2M'), 'rb')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement