Youtube_dl : ERROR : YouTube said: Unable to extract video data
Asked Answered
V

10

132

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?

Vulgate answered 9/9, 2020 at 17:38 Comment(13)
You will get more traction with this question if you are able to boil it down a bit to the specific section that is throwing this error. I’m often worried about not including enough data but people are generally more likely to engage if its a simple question, versus something which at first glance looks like ‘do this for me’. I’m not casting any aspersions about you, but people will click, glance, and hit back on these quite a lot.Goodden
Is the error raised for any video or a specific one? (I think I read somewhere on Reddit that this can happen because of the age-gate)Peanuts
@SolebaySharp Sorry it's just because I was not sure if something external to youtube_db could block my programVulgate
@MinionJim I tested my program with multiple videos and always got the same errorVulgate
I just tested your code and it works except for the fact that the url is wrong. Firstly, you misspelt https (you have htps) and second it should be /watch rather than ?watch so your operation call line would become operation("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
Sorry it was only typing errors. It doesn't resolve the problem. I think the problem come from the windows interpreter because when I try to run my program directly in the windows command, it tells me "No module named youtube_dl" while I already installed it ...Vulgate
But I still don't know how to resolve this problem ...Vulgate
Ok, I'm running out of ideas :-( Do you have multiple Python interpreters installed (this is more for the ImportError than a solution to the question)? Is it because your path starts with a forward-slash (again, I presume you substitute %(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 thingPeanuts
@MinionJim No I'm only using python 3.8.3Vulgate
And the path starting with a slash (does removing it fix the issue)?Peanuts
@MinionJim No same error ...Vulgate
As long as you don't get errors when you type import youtube_dl in your python shell there should be no problems with import. Can you download the video using youtube-dl on the command line? And why do you pass the link as a list []?Farron
use sudo youtube-dl link to download video . Use the sudo before youtube-dl command.Alban
S
208

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)
Silberman answered 10/12, 2020 at 8:30 Comment(13)
pip install -U youtube-dlBrnaba
brew upgrade youtube-dl in my case.Darwin
choco upgrade youtube-dl in my caseAphonic
If you're coming from Ubuntu/debian, you may as well not rely on the apt repository and instead install by another means, as documented on the youtube-dl github: github.com/ytdl-org/youtube-dl#installationElectrocautery
Don't forget to run "youtube-dl --update" with writing "sudo" first, otherwise, you can get an error like: "ERROR: no write permissions on /usr/local/Cellar/youtube-dl/2020.03.24/bin/youtube-dl". It's caused by permission status, not by youtube-dlHutchinson
pip3 install iU youtube-dl for python3Thirzi
In my case I use home-manager. I declared: unstable = import (fetchGit { name = "nixpkgsDarwinSandbox"; url = "https://github.com/NixOS/nixpkgs"; ref = "refs/heads/master"; rev = "31014c4a2888cd4f782b0cba246f3b8036d63b30"; }) {}; ... home.packages = with pkgs; [ unstable.youtube-dl ... ] Bathsheb
Can also download an updated version here: https://ytdl-org.github.io/youtube-dl/index.htmlPohl
@NormanBreau I normally find it is best to do the initial install with apt as that way all the dependancies install correctly, then you can use --update to allow it to work.Mildred
youtube-dl: error: youtube-dl's self-update mechanism is disabled on Debian. while updatingFlabby
There is an up2date snap package that works for me on KDE Neon, so probably any Ubuntu based distribution.Chainplate
i'm getting the error even after updating youtube-dl to the latest version!Hiphuggers
@shripalmehta Try the new replacement fork yt-dlp.Extemporaneous
V
93

For ubuntu users:

sudo apt purge youtube-dl 
sudo pip3 install youtube-dl
hash youtube-dl
Voyeurism answered 3/2, 2021 at 9:37 Comment(4)
If you get error: "ERROR: ffprobe/avprobe and ffmpeg/avconv not found. Please install one." , you can simply resolve it with: sudo apt install ffmpegUlla
A third command you might want: hash youtube-dlTyrothricin
@BrentBaccala This should be added in the answer.Meltage
Again, this fails with the same error.Treadmill
S
15

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.

Sejm answered 27/12, 2020 at 9:54 Comment(1)
please include your code solution as text rather than an imageVereeniging
G
12

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
Gouache answered 7/2, 2021 at 20:29 Comment(1)
@CharithJayasanka the .deb file gets updated every once and a while... just download & install the most recent one, such as (as of today) http://ftp.de.debian.org/debian/pool/main/y/youtube-dl/youtube-dl_2021.02.10-1_all.debGouache
F
11

Install yt-dlp as an alternative to youtube-dl

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 -o /path/to/output.mp4

for example:

yt-dlp https://www.youtube.com/watch?v=gKCvphbCpPE -o ~/Videos/my_video.mp4

Why use yt-dlp?

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.

Festivity answered 22/2, 2023 at 4:16 Comment(4)
Fails with the same error. So no.Treadmill
@Treadmill have you uninstalled the previously installed youtube-dl? If you're on Ubuntu, try which youtube-dl to see if you still have youtube-dl installed. Use yt-dlp video_url?Festivity
Tracked down the problem: the machine I was running it on is still using Python 3.6, and the latest, working versions of both yt-dlp & youtube-dl have dropped support for that version. I switched to a different machine with Python 3.8 & yt-dlp works. Haven't tried with youtube-dl, but since yt-dlp is behaving correctly I might not bother.Treadmill
This worked. Many other solutions mentioned here failed for me.Berezniki
P
10

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.

Peshawar answered 31/1, 2022 at 18:53 Comment(0)
L
7

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

sudo youtube-dl --update

Lapstrake answered 21/12, 2020 at 9:55 Comment(1)
Please add a comment instead of writing a new answer. Because it answered already by Manoj D Bhat, Dec 10 '20 at 8:30, 11 days before yours.Hutchinson
W
6

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

sudo pip install --upgrade youtube_dl

Waldemar answered 22/1, 2021 at 16:37 Comment(0)
A
4

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

Abrasive answered 5/10, 2020 at 11:17 Comment(4)
your link [Chrome plugin Cookie.txt][chrome.google.com/webstore/detail/cookiestxt/… is deadMotet
this wout do: chrome.google.com/webstore/detail/get-cookiestxt/…Motet
Is the -n option needed? Without it is not working...Ascidium
ERROR: 0TYq9RjdYYU: YouTube said: Invalid parameters.Brottman
F
1

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

Friendship answered 25/8, 2021 at 0:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.