YouTube-dl - a stupid and quick guide

Introduction

YouTube is the biggest video site in the world. Terabytes of new material are uploaded every day from music, to reviews, tutorials, trailers or even full movies/episodes of TV series. However, this content can usually be accessed online. Usually, because often videos become unavailable, most often due to copyright claims. You may also just want to view something offline. Maybe you’re going on a trip and won’t have internet. Or maybe you found this cool song that you want to add to your phone. Downloading these videos is possible, but often the programs used to do it are hard to use with a screen reader, are inaccessible, or stop working due to internal Youtube changes. They can also come with piles of bloatware like toolbars which will just slow down your computer or web browser. There are also websites that give you this functionality, but they also have limitations - they are slow, and usually limit the length of a video that can be processed. You can’t also download entire channels or playlists. Thankfully, there is a solution.

Enter YouTube-dl

youtube-dl is a small command-line program to download videos from YouTube.com and a few more sites. It requires the Python interpreter (2.6, 2.7, or 3.3+), and it is not platform specific. It should work in your Unix box, in Windows or in Mac OS X. It is released to the public domain, which means you can modify it, redistribute it or use it however you like.

This is how briefly YouTube-dl’s site describes the program/script. You can go here to read the not all that helpful documentation or for download links. On Linux and the Mac, the program can also be downloaded using curl or wget, which is also described on the download page. So I will now assume you have installed the program.

How do we use this thing?

YouTube-dl is a command line program. This means that it does not open any windows and you talk to it using text commands. It, likewise, talks back with just plain text. THis makes it very accessible, but does give it a learning curve which, trust me, is worth it. ANyway, you will need to enter your computer’s command prompt. On windows, the quickest way is to enter cmd into the run dialog (Windows+R). On the Mac, you have to open the terminal, which is found in your utilities folder, found under Applications or pressing Command-shift-U. If you installed the program to where it’s already in your path, you’re all set. If not, EG you got the windows binary and just extracted it somewhere, you will first need to go to that folder with the “cd” command (EG cd C:\users\JohnSmith\desktop) or add it to your path. If you followed the instructions to download the program with curl on OS X, then youtube-dl is in your path so no worries.

The next step is to find what ever you want to download. It can be anything, from a single video, to an entire playlist or even channel. Find it, then copy the address out of your web browser and return to your command prompt/terminal. At this point, if YouTube-dl is in your path, you can go to any folder you want for your downloads, with the cd command (which works the same on Mac and Windows. If it’s not in your path you will need to stay in the folder it’s in. To download a vide, you first proceed your command with youtube-dl, followed by any commands, and lastly the address. To paste the video address, on the mac you can just command-v as normal, but in windows you will need to hit alt+space to open the system menu, then e which opens edit, and finally p to paste the clipboard contents. Running youtube-dl and just giving it the address will download the video in the highest quality possible. It may look something like this.

Piotrs-MacBook-Pro:~ Piotr$ youtube-dl https://www.youtube.com/watch?v=aP3gzee1cps [youtube] Setting language [youtube] aP3gzee1cps: Downloading webpage [youtube] aP3gzee1cps: Downloading video info webpage [youtube] aP3gzee1cps: Extracting video information [download] Destination: Cat gets caught barking by a human and resumes meowing-aP3gzee1cps.mp4 [download] 100% of 1003.76KiB in 00:01

This gave us an almost 2MB mp4 file. This particular video is very old and was available only in 360P, so it’s not that big. However, higher quality and longer videos will give you much bigger files. You may also just need to get just the audio out of a video, again, in its highest quality. This can be done very easily using the “-x” parameter. that’s a single dash followed by a lowercase x. You need to pay attention to the capitalisation of these commands, because they are case sensitive.

Piotrs-MacBook-Pro:~ Piotr$ youtube-dl -x https://www.youtube.com/watch?v=aP3gzee1cps [youtube] Setting language [youtube] aP3gzee1cps: Downloading webpage [youtube] aP3gzee1cps: Downloading video info webpage [youtube] aP3gzee1cps: Extracting video information [download] Destination: Cat gets caught barking by a human and resumes meowing-aP3gzee1cps.m4a [download] 100% of 354.70KiB in 00:00 [youtube] Post-process file Cat gets caught barking by a human and resumes meowing-aP3gzee1cps.m4a exists, skipping

Aha, 360kb. Much better. You could get by with really just that 1 command, but a few other useful ones are “–console-title”, which will change the title of the window to progress information (useful for large operations), –add-metadata which will add things like the artist or year to the audio/video file’s metadata (requires ffmpeg), or -i, which ignores errors, again useful for large operations where a single deleted video can cause YouTube-dl to completely stop any further downloads.

Lastly, I will briefly explain how to download the video in a different format. MP4/M4a will usually play on any hardware, but sometimes you may want a different format, like ogg, opus, wav or MP3. THankfully, this can be done using the –audio-format and –audio-quality commands. FOr example, this will download the video and then convert it to a 64k MP3.

Piotrs-MacBook-Pro:~ Piotr$ youtube-dl -x –audio-format mp3 –audio-quality 64K https://www.youtube.com/watch?v=aP3gzee1cps [youtube] Setting language [youtube] aP3gzee1cps: Downloading webpage [youtube] aP3gzee1cps: Downloading video info webpage [youtube] aP3gzee1cps: Extracting video information [download] Cat gets caught barking by a human and resumes meowing-aP3gzee1cps.m4a has already been downloaded [ffmpeg] Destination: Cat gets caught barking by a human and resumes meowing-aP3gzee1cps.mp3 Deleting original file Cat gets caught barking by a human and resumes meowing-aP3gzee1cps.m4a (pass -k to keep)

Notice that ffmpeg was needed to do this command, so you will need to install it and put it in your path if you’re planning to be converting video formats this way.

And this is pretty much it for YouTube-dl. I encourege you do read the full list of available commands and experiment yourself, and I think you will see just why I like this program so much. Lastly, I have included the full command list in a much easier to read format (note that if any commands appear with an m-dash, in actuality oyu need to enter 2 dashes.

Commands

Options:

General Options:

Video Selection:

Download Options:

Filesystem Options:

Verbosity / Simulation Options:

Video Format Options:

Subtitle Options:

Authentication Options:

Post-processing Options: