Youtube_dl : ERROR : YouTube said: Unable to extract video data
Question:
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?
Answers:
You could try adding a cookie file as some videos are age restricted. Use this plugin Chrome plugin Cookie.txt to download your cookies in a txt file then use these --cookies /path/to/cookies/file.txt
flags not forgetting to put the right path to the file of your cookies.txt.
Sample:
youtube-dl -n --cookies ~/Downloads/cookies.txt https://www.youtube.com/watch?v=h7Ii7KKapig
Updating youtube-dl helped me. Depending on the way you installed it, here are the commands:
youtube-dl --update
(self-update)
pip install -U youtube-dl
(via python)
brew upgrade youtube-dl
(macOS + homebrew)
choco upgrade youtube-dl
(Windows + Chocolatey)
If you are using youtube-dl command line on MacOsx update using this command :
sudo youtube-dl --update
I had the same error on Ubuntu 20.04.
I solved it by updating youtube-dl by downloading a .deb from:
https://packages.debian.org/sid/all/youtube-dl/download
Though you can also get the update on youtube-dl’s official site.
If you have pip installed you can use it to update youtube-dl
that helped me.
sudo pip install --upgrade youtube_dl
For ubuntu users:
sudo apt purge youtube-dl
sudo pip3 install youtube-dl
hash youtube-dl
The only thing that worked for me on Ubuntu was to install using the Debian package / .deb file:
wget http://ftp.de.debian.org/debian/pool/main/y/youtube-dl/youtube-dl_2021.02.04.1-1_all.deb
sudo apt install ./youtube-dl_2021.02.04.1-1_all.deb
The youtube-dl package is using python code and it’s looking for the correct python version to run. If you have python3 then enter:
sudo sed -i '1s/python/python3/' /usr/local/bin/youtube-dl
Ubuntu Users:
The simplest & quickest way to solve this issue without running around and trying a thousand different solutions is to completely remove Youtube-dl and reinstall it using the .deb file & apt. First, purge it from your system.
sudo apt purge youtube-dl
OR
sudo pip3 uninstall youtube-dl
Next, go HERE (http://ftp.us.debian.org/debian/pool/main/y/youtube-dl/youtube-dl_2021.12.17-1_all.deb) to download the .deb file. Once the file is downloaded, install using apt with the command below. This will solve your issue. Obviously you will make sure your version number & file name are correct.
sudo apt install ./youtube-dl_2021.12.17-1_all.deb
If this solution works for you PLEASE vote it up so that others can easily find it.
Save yourself time and install yt-dlp instead using pip with python 3.7+:
python -m pip install -U yt-dlp
then
yt-dlp video_url
for example:
yt-dlp https://www.youtube.com/watch?v=gKCvphbCpPE -o ~/Videos/my_video.mp4
Quoted from the package repo:
yt-dlp is a youtube-dl fork based on the now inactive youtube-dlc. The main focus of this project is adding new features and patches while also keeping up to date with the original project
Worked for me after nearly 1 painful hour of searching.
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?
You could try adding a cookie file as some videos are age restricted. Use this plugin Chrome plugin Cookie.txt to download your cookies in a txt file then use these --cookies /path/to/cookies/file.txt
flags not forgetting to put the right path to the file of your cookies.txt.
Sample:
youtube-dl -n --cookies ~/Downloads/cookies.txt https://www.youtube.com/watch?v=h7Ii7KKapig
Updating youtube-dl helped me. Depending on the way you installed it, here are the commands:
youtube-dl --update
(self-update)pip install -U youtube-dl
(via python)brew upgrade youtube-dl
(macOS + homebrew)choco upgrade youtube-dl
(Windows + Chocolatey)
If you are using youtube-dl command line on MacOsx update using this command :
sudo youtube-dl --update
I had the same error on Ubuntu 20.04.
I solved it by updating youtube-dl by downloading a .deb from:
https://packages.debian.org/sid/all/youtube-dl/download
Though you can also get the update on youtube-dl’s official site.
If you have pip installed you can use it to update youtube-dl
that helped me.
sudo pip install --upgrade youtube_dl
For ubuntu users:
sudo apt purge youtube-dl
sudo pip3 install youtube-dl
hash youtube-dl
The only thing that worked for me on Ubuntu was to install using the Debian package / .deb file:
wget http://ftp.de.debian.org/debian/pool/main/y/youtube-dl/youtube-dl_2021.02.04.1-1_all.deb
sudo apt install ./youtube-dl_2021.02.04.1-1_all.deb
The youtube-dl package is using python code and it’s looking for the correct python version to run. If you have python3 then enter:
sudo sed -i '1s/python/python3/' /usr/local/bin/youtube-dl
Ubuntu Users:
The simplest & quickest way to solve this issue without running around and trying a thousand different solutions is to completely remove Youtube-dl and reinstall it using the .deb file & apt. First, purge it from your system.
sudo apt purge youtube-dl
OR
sudo pip3 uninstall youtube-dl
Next, go HERE (http://ftp.us.debian.org/debian/pool/main/y/youtube-dl/youtube-dl_2021.12.17-1_all.deb) to download the .deb file. Once the file is downloaded, install using apt with the command below. This will solve your issue. Obviously you will make sure your version number & file name are correct.
sudo apt install ./youtube-dl_2021.12.17-1_all.deb
If this solution works for you PLEASE vote it up so that others can easily find it.
Save yourself time and install yt-dlp instead using pip with python 3.7+:
python -m pip install -U yt-dlp
then
yt-dlp video_url
for example:
yt-dlp https://www.youtube.com/watch?v=gKCvphbCpPE -o ~/Videos/my_video.mp4
Quoted from the package repo:
yt-dlp is a youtube-dl fork based on the now inactive youtube-dlc. The main focus of this project is adding new features and patches while also keeping up to date with the original project
Worked for me after nearly 1 painful hour of searching.