How to download and play YouTube and other videos on Linux

The youtube-dl tool makes it very easy to download both webm and mp4 files on Linux systems. You just need the tool and the right URLs.

A user video conferences via tablet. [teleconference / online meeting / digital event]
Alvarez / Getty Images

Who would have imagined that there’s a Linux tool available for downloading YouTube videos? Well, there is and it works for Linux as well as for other operating systems. So, if you need to watch some of the available videos even when your internet connection is flaky or you need to be offline for a while, this tool can be especially handy.

The tool for downloading videos is called youtube-dl. (The “dl” portion undoubtedly means “download”.) It’s very easy to use and drops webm or mp4 files onto your system. Both formats provide compressed, high-quality video files that you can watch whenever you like.

The youtube-dl tool is a Python-based command-line tool. On Linux, it requires Python (2.6, 2.7, or 3.2+). The command to install it on Ubuntu and related systems is:

$ sudo apt-get install youtube-dl

Once installed, you can use a command like this to download a video after selecting the URL from YouTube or some other source:

$ youtube-dl <video URL>

Here is an example that can serve as a quick test:

$ youtube-dl

After you successfully run the test you can try downloading a video of your own choosing. Depending on the size of the file, the download might take a couple of minutes or longer. If you watch the screen, you’ll see updates on the expected time remaining.

Once a video is downloaded, you can play it by double-clicking on the icon in your file manager or you can kick it off on the command line using totem. Totem is a GNOME desktop movie player based on GStreamer and likely already on your system.

$ which totem
$ totem 'Gather the Spirit music & lyrics-CWnrwetbrbc.webm'

Note that youtube-dl works not just for youtube videos, but videos from many sources. A very short Crazy Frog mp4 video could be downloaded with a command like this one. Notice that this short download only took eight seconds.

$ youtube-dl
[dailymotion] Downloading Access Token
[dailymotion] x3b4gfs: Downloading media JSON metadata
[dailymotion] x3b4gfs: Downloading metadata JSON
[dailymotion] x3b4gfs: Downloading m3u8 information
[download] Destination: Crazy Frog The Original Crazy Frog Song HD Quality!-x3b4gfs.mp4
[download] 100% of 9.74MiB in 00:08
$ ls -l Crazy*
-rw-rw-r-- 1 shs shs 10216863 Jan 25  2019 'Crazy Frog The Original Crazy Frog Song HD Quality!-x3b4gfs.mp4'

While downloaded videos can prove very useful, you should probably be wary of potential legal issues should you go beyond the most modest use of them. You must be careful to avoid copying, reproducing, distributing, transmitting, broadcasting, displaying, selling, licensing, or otherwise exploiting any content without the prior written consent of the owner(s). These constraints are fairly typical, though some videos may not involve copyrights or legal restrictions.

Now see:

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2020 IDG Communications, Inc.

SD-WAN buyers guide: Key questions to ask vendors (and yourself)