Command-Line Interface

youtube-dl: Download Video and Audio Files From Streaming Sites

Last Updated on October 26, 2020

youtube-dl is a cross-platform, open source, command-line program to download videos. Its name belies the fact it supports tons of streaming sites besides YouTube. I’d never heard of half of them.

The software is written in the Python programming language and needs the Python interpreter (2.6, 2.7, or 3.2+).

One of youtube-dl’s most popular functions is to enable users with poor internet connections download HD content that would otherwise be impossible for them to stream live.

Another key virtue of youtube-dl, like other command-line software, is the ability to embed the software in other applications. Why reinvent the wheel? For example, I covered the Persepolis Download Manager which relies on youtube-dl for video downloading.

The developers of youtube-dl are keen to respect copyright laws, refusing to add support for sites that blatantly infringe copyright.

Installation

Given the popularity of youtube-dl, it should come as little surprise to learn you’ll likely find a youtube-dl package in your distribution’s repositories. Installation of the software will therefore be straightforward. However, your distribution’s repositories may have a very outdated version, so it’s worth checking what version you are running (type “youtube-dl –version” at a shell prompt).

The standard repositories for Ubuntu, at the time of this article, offer version 2018.03.14. That’s about 4 months behind the latest version release.

I prefer using the latest version. and it’s effortless to upgrade. At a shell, type:

sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl

This downloads the latest version to /usr/local/bin/

Then make the youtube-dl file executable:

sudo chmod a+rx /usr/local/bin/youtube-dl

The site’s GitHub installation section has other ways of obtaining the latest release if you want to download with wget or pip.

In operation

To download a video, just type at a shell:

youtube-dl filename

youtube-dl

By default the software automatically downloads the best available quality for a specific video. The image above shows a 20 minute 4K video downloading. It weighs in at a hefty 2.78GB. That’s totally unsuitable for watching on my tablet or phone. But there’s a whole raft of options available to download media suitable for a particular device or purpose. For example, let’s say I want to download the best available quality but constrained to a file size of 200MB or less.

youtube-dl-2

The original video has a resolution of 3840×2160, whereas the second download resolution is 640×360. That’s much more suitable for playback on my creaking tablet.

There are a whole raft of other options such as setting limits on the resolution, and different quality presets.

It’s also possible to download complete playlists or an entire YouTube channel’s content, with filtering rules, with a single command.

Other Features include:

  • Wide range of supported sites.
  • Extractor features support for playlists and the workarounds that are available to support certain websites. If a URL contains a playlist, youtube-dl is able to download the entire playlists. These playlists can be filtered based on different available meta-data such as view count, duration, liked, titles, etc. The workarounds allow the user to specify custom header fields (like a browser) to work around some security measures that might have been taken by the site to avoid downloading the content.
  • Download features ability to use a proxy, authentication and quality selection. The latter one allows you to download the file with exactly the quality that you require (if available). Authentication allows users to specify credentials that can be used to work around permission issues. Authentication is also possible by using a user-defined cookie (in the case that regular authentication is not supported or fails). The use of a proxy allows a user to access content that is not available from the users normal connection (think of geo-limitations).
  • Post-processing features – tweak the downloaded file to your preference. A user can choose to embed subtitles and convert the content. The user can specify a subtitle source, which then will be embedded in a video file. The user can also specify the desired output format. The post-processor in question will convert the downloaded file into the desired format.
  • Formats supported – 3gp, aac, flv, m4a, mp3, mp4, ogg, wav, and webm.
  • Supports most of current streaming techniques: HTTP progressive, AdobeHDS, AppleHLS (including AES-128), and MPEG-DASH (without encryption).
  • Built-in testing system using the Tox testing tool for Python.
  • Cross-platform support – runs under Linux, MacOS, and Windows operating systems.

Summary

When conversation turns to indispensable command-line multimedia software, youtube-dl inevitably gets a mention. It’s brimmed with genuinely useful features, and supports a ton of streaming sites. If you need to consume video offline, you’ll love youtube-dl. The project offers good documentation which helps makes the software quick and easy to master.

Website: ytdl-org.github.io
Support: GitHub code repository
Developer: youtube-dl developers
License: Free and unencumbered software released into the public domain

youtube-dl is written in Python. Learn Python with our recommended free books and free tutorials.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Please read our FAQ before making a comment.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Anon
Anon
6 years ago

Once it’s installed, run ‘sudo youtube-dl -U’ and it will update to the latest version. Do it frequently, the developers and Google engineers are apparently working at odds.