I'm making a little graphic interface with Python 3 which should download a youtube video with its URL.
I used the youtube_dl
module for that.
This is my code :
import youtube_dl # Youtube_dl is used for download the video
ydl_opt = {"outtmpl" : "/videos/%(title)s.%(ext)s", "format": "bestaudio/best"} # Here we give some advanced settings. outtmpl is used to define the path of the video that we are going to download
def operation(link):
"""
Start the download operation
"""
try:
with youtube_dl.YoutubeDL(ydl_opt) as yd: # The method YoutubeDL() take one argument which is a dictionary for changing default settings
video = yd.download([link]) # Start the download
result.set("Your video has been downloaded !")
except Exception:
result.set("Sorry, we got an error.")
operation("https://youtube.com/watch?v=...")
When I execute my code, I get this error:
ERROR: YouTube said: Unable to extract video data
I saw here that it was because it doesn't find any video info, how can I resolve this problem?
https
(you havehtps
) and second it should be/watch
rather than?watch
so your operation call line would becomeoperation("https://youtube.com/watch?v=...")
. I assume this is just a typo with the question, but I hope this resolves it (I could not reproduce your error) – Peanuts%(title)
with something as Windows won't like that as a path)? EDIT: in the future please @ me so it shows in my SO inbox thing – Peanutsimport youtube_dl
in your python shell there should be no problems with import. Can you download the video usingyoutube-dl
on the command line? And why do you pass the link as a list[]
? – Farron