Youtube_dl : ERROR : YouTube said: Unable to extract video data

PythonPython 3.xDownloadYoutubeYoutube Dl

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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)

Solution 2 - Python

For ubuntu users:

sudo apt purge youtube-dl 
sudo pip3 install youtube-dl
hash youtube-dl

Solution 3 - Python

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.

Solution 4 - Python

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

Solution 5 - Python

If you are using youtube-dl command line on MacOsx update using this command :

sudo youtube-dl --update

Solution 6 - Python

If you have pip installed you can use it to update youtube-dl that helped me.

sudo pip install --upgrade youtube_dl

Solution 7 - Python

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.

Solution 8 - Python

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

Surce

Solution 9 - Python

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBastienView Question on Stackoverflow
Solution 1 - PythonManoj D BhatView Answer on Stackoverflow
Solution 2 - PythonhurelhuyagView Answer on Stackoverflow
Solution 3 - PythonAndrés HerasView Answer on Stackoverflow
Solution 4 - PythonHotDogCannonView Answer on Stackoverflow
Solution 5 - PythonAbderrazzak NejeouiView Answer on Stackoverflow
Solution 6 - PythonHamzaView Answer on Stackoverflow
Solution 7 - PythonGregory SmithermanView Answer on Stackoverflow
Solution 8 - PythonHugoBragaView Answer on Stackoverflow
Solution 9 - PythonouterSpaceView Answer on Stackoverflow