How do I enable youtube-dl to bypass the age restriction on YouTube?

27,830

Solution 1

yt-dlp looks like a fork of youtube-dl and works as expected. You can install it as follows (from the project's GitHub page):

UNIX users (GNU/Linux, macOS, BSD) can also install the latest release one of the following ways:

sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
sudo aria2c https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp

Solution 2

There is a workaround, but not exactly by using youtube-dl. Currently the best method to access Youtube's age-restricted videos (without logging in) is to use the Invidious network, which provides an alternate method of accessing Youtube's video content. For example you can use the main site of Invidious network, https://yewtu.be/ . Invidious network sites provide a download option under each video.

There is also an application called FreeTube that allows to view and download Youtube videos. It can automatically use Invidious servers in case it can't download the video from Youtube directly.

Solution 3

You can try this workaround using Python 3.x with the following command (I've added the --verbose flag in case of debugging):

python3 /usr/local/bin/youtube-dl -f bestvideo+bestaudio \
    --all-subs --cookies $PWD/youtube.com_cookies.txt \
    "https://www.youtube.com/watch?v=VIDEO_ID_HERE" --verbose

Make sure to do the following first:

  • Ensure the python3 is installed, that the command is working, and that it actually runs a version of Python 3.x.
  • Make sure that the path to your cookies file is correct.
  • Make sure that you have the latest version of youtube-dl installed (youtube-dl --version).
  • Ensure the absolute file path for the youtube-dl binary or installation (In a UNIX-like terminal use which youtube-dl).
Share:
27,830

Related videos on Youtube

Allan
Author by

Allan

Updated on September 18, 2022

Comments

  • Allan
    Allan almost 2 years

    I tried downloading a particular YouTube video using youtube-dl (in terminal) and got the following display:

    [youtube] 8_Ik8elX96w: Downloading webpage
    [youtube] 8_Ik8elX96w: Downloading embed webpage
    [youtube] 8_Ik8elX96w: Refetching age-gated info webpage
    ERROR: This video may be inappropriate for some users.
    

    The URL for the video is: https://www.youtube.com/watch?v=8_Ik8elX96w

    I've been told that this is to do with YouTube age restrictions and that I need youtube-dl to log in to my YouTube account to bypass the restriction; and this requires can be enabled by supplying the required cookie set for YouTube log-in in the command line. (youtube-dl does not access YouTube via my browser, so manually logging in through my browser does not bypass the restriction for youtube-dl.)

    If this is the correct way to bypass the restriction, please tell me how to find the cookie path to type into the command line and the procedure for entering it there. I am using Firefox; apparently the method of finding the required cookie text is different for each browser.

    • Admin
      Admin about 3 years
    • Admin
      Admin about 3 years
      Don't ask the same question twice.
    • Admin
      Admin about 3 years
      @heynnema The first question about was why it is happening. I also asked whether there is a work around, in the body of that question. This question is asking what the work-around is and how I do it. Nobody gave me specific instructions for this in response to the first question. So no, there is no answer posted for this to the first question. Did you bother to read it before wisecracking?
    • Admin
      Admin about 3 years
      Both questions are about a third-party program not supplied by Ubuntu, and a third-party YouTube video, also having nothing to do with Ubuntu. Both questions are actually off-topic on this web site. Do youtube-dl -h for more help.
  • reim
    reim over 2 years
    With youtube-dl version 2021.12.17 the --cookies option works indeed, you can export all of of your YouTube cookies in Netscape format with this chrome.google.com/webstore/detail/get-cookiestxt/… Chrome extension (make sure you run it on the tab where you have a logged in YouTube page).