Skip to content

Instantly share code, notes, and snippets.

@basperheim
Last active January 19, 2022 12:23
Show Gist options
  • Save basperheim/b23c03d302a7782b26c12399bbdddcc4 to your computer and use it in GitHub Desktop.
Save basperheim/b23c03d302a7782b26c12399bbdddcc4 to your computer and use it in GitHub Desktop.
Download age-restricted YouTube videos with youtube-dl

Download age-restricted videos on YouTube

2022 UPDATE: It's better to use the YT-DLP fork of youtube-dl at this point. You can always make an alias for yt-dlp like so: alias youtube-dl='/usr/local/bin/yt-dlp' (make sure to replace /usr/local/bin/ with your actual yt-dlp path).

YouTube has recently blocked age-restricted videos from being downloaded. You can use the youtube-dl's --cookies flag to pass your stored cookie preferences to the command to bypass this.

  • Install a Chrome extension like Get Cookies.txt to get your browser's cookies.
  • Install youtube-dl from source, or use Python 3's PIP package manager to install it.
  • Obtain a copy of your browser cookies stored as a .txt file.

Install youtube-dl

Download youtube-dl and install the command-line tool for your operating system. You can also use Python's PIP package manager to install youtube-dl, which is recommended.

Download the latest version of youtube-dl. On macOS you can put the binary in the /usr/local/bin directory, or you install it using pip3.

In a UNIX-like terminal you can use the which youtube-dl command to verify it's installed, or use the youtube-dl --version command to see which installed version is associated with the command.

Install youtube-dl using Python's PIP

Use the which pip or which pip3 command to ensure that PIP for Python is installed.

Make sure to use the version of PIP that's associated with Python 3.x, and then execute the following command:

pip3 install youtube-dl

Install youtube-dl on macOS with Homebrew

brew install youtube-dl

Download an age-restricted YouTube video with cookies file

Basic youtube-dl command is as follows:

youtube-dl "https://www.youtube.com/watch?v=VIDEO_ID_GOES_HERE"

Download a YouTube video with the cookies flag

youtube-dl "https://www.youtube.com/watch?v=VIDEO_ID_GOES_HERE" --cookies path/to/cookies.txt

NOTE: These commands should work in Windows command prompt, or in a UNIX-like terminal on macOS and Linux. Make sure to use \ instead in Windows command prompt.

Run the youtube-dl command using Python 3 with the --verbose and --all-subs options:

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

Use this last command in case you get an AttributeError: 'bool' object has no attribute 'split' error and you need to explicitly use Python 3. In a Windows 10 command prompt you'll probably need to use the py command instead of python3.

The -f bestvideo+bestaudio option will download the best quality possible.

@basperheim
Copy link
Author

youtube-get-cookies-export-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment