Watch YouTube videos at the Linux terminal

Thought video content was just for your GUI? Think again.
Register or Login to like
Linux toy: youtube-dl

Jason Baker

We're almost to the end of our 24-day-long Linux command-line toys advent calendar. Hopefully, you've been following along, but if not, start back at the beginning and work your way through. You'll find plenty of games, diversions, and oddities for your Linux terminal.

And while you may have seen some toys from our calendar before, we hope there’s at least one new thing for everyone.

Today we're going to double-down on yesterday's toy, MPlayer, and add in one more, youtube-dl.

As its name would imply, youtube-dl is a command-line utility for downloading YouTube videos, but it can capture video from a number of other sites as well, and it's a really quite full-featured application with thorough documentation to make video acquisition easy. A note: please don't use youtube-dl in any context that would violate the copyright laws in your jurisdiction.

youtube-dl is licensed under a public domain dedication known as the Unlicense that's similar to Creative Common's CC0. There are some interesting legal opinions out there about where public domain dedication fits into the open source landscape, but it's generally considered compatible with existing open source licenses even by organizations who don't recommend its use.

In its simplest form, we're going to use youtube-dl to grab a video for playback in our terminal. First, install it using a method appropriate for your distribution. For me, in Fedora, it was packaged in my repositories, so installation was as simple as:

$ sudo dnf install youtube-dl

Then, let's grab a video. YouTube allows you to search by license, so today, we're going to take a look at a fireplace video from Gemmy's Videos available under a Creative Commons attribution license. For YouTube videos, you can download with the file ID alone, like this, and we'll specify an output file name as well. I intentionally picked a short video, since long videos can get quite large!

$ youtube-dl pec8P5K4s8c -o fireplace.mp4

If you didn't install MPlayer yesterday, go ahead and do that, and you may need to install libcaca for your system as well if you did not install it previously. If you just use MPlayer to launch the video from the command line as-is ($ mplayer fireplace.mp4), it will play, but in a window all of its own; not exactly what we were going for.

First, I set my libcaca settings to force it to use ncurses as the display driver, keeping the output in my terminal, with:

$ export CACA_DRIVER=ncurses

Then, I zoomed way out in my terminal (the more "pixels", the better), and played the file with the following (forcing the use of libcaca and silencing text output from MPlayer):

$ mplayer -really-quiet -vo caca fireplace.mp4

And, there you go!

Linux toy: youtube-dl

Do you have a favorite command-line toy that we should have included? It's a little late to submit a suggestion for this year, but we'd still love to feature some cool command-line toys in the new year. Let me know in the comments below, and I'll check it out. And let me know what you thought of today's amusement.

Be sure to check out yesterday's toy, Listen to the radio at the Linux terminal, and come back tomorrow for another!

What to read next
Jason was an Opensource.com staff member and Red Hatter from 2013 to 2022. This profile contains his work-related articles from that time. Other contributions can be found on his personal account.

6 Comments

That's bloody dope!!!!

What makes this specific to Linux?

Nothing, and nowhere does it say that it's Linux only. This article is part of a series on fun things you can do at the Linux command line. Linux is just the focus in this instance.

In reply to by John Klos (not verified)

Flashback to 15 years ago, to the tools and solutions of that time.

Seriously: mplayer is long defunct, it's successor mpv is so much better, well maintained and everything. The video quality is also much better than libcaca. I used your solution years ago, cannot imagine using this now, I hated it in earlier times, and there was so much progress in the meantime.

Your target: Video in the terminal.

Todays solution: Install mpv (comes with youtube-dl), run it like so:

mpv --vo=tct --loop-file 2>/dev/null

done. This gives you a niced looped fireplace video with sound. In the terminal. Happy holidays!

In the middle of this article, it should be **$ mplayer fireplace.mp4** not **$ mplayer fireplace.webm** ;-)

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.