Easily Watch Technical YouTube Videos Offline
Tags: youtube, video, download
Published: 2020-03-21 13:08:40

I like watching lots of conference talks but watching them on YouTube is not always ideal. You can use [YouTube Premium](https://www.youtube.com/premium) (which I do) but it's limited to the official clients and sometimes I want to download one video, a playlist or a whole channel for research purposes :wink: This all a breeze with [youtube-dl](https://ytdl-org.github.io/youtube-dl/index.html).

{% github ytdl-org/youtube-dl %}

[youtube-dl][yt] is a nice tool for downloading videos from websites. Don't let the name fool you, it does work on lots of different sites but today we will only look at some of the YouTube bits. Below are examples of the most frequent variations of the command I use. I will be using the [freeCodeCamp.org YouTube channel](https://www.youtube.com/channel/UC8butISFwT-Wl7EV0hUK0BQ) for all examples.

```
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
```

## Downloading a Playlist

After opening up a playlist on the website, paste in the whole url that contains `list=`. 
```
youtube-dl https://www.youtube.com/watch\?v\=jWdEM6XLKqI\&list\=PLWKjhJtqVAbkXQS12WiLsH1oaNZBSoWuV
[youtube:playlist] Downloading playlist PLWKjhJtqVAbkXQS12WiLsH1oaNZBSoWuV - add --no-playlist to just download video jWdEM6XLKqI
[youtube:playlist] PLWKjhJtqVAbkXQS12WiLsH1oaNZBSoWuV: Downloading webpage
[download] Downloading playlist: Serverless
[youtube:playlist] playlist Serverless: Downloading 7 videos
[download] Downloading video 1 of 7
[youtube] jWdEM6XLKqI: Downloading webpage
[download] Destination: Intro to Cloud Computing and AWS-jWdEM6XLKqI.f136.mp4
[download]  11.4% of 17.55MiB at  5.37MiB/s ETA 00:02^C
```

## Downloading a Single Video

When you are watching a video on the YouTube website there is a parameter `v=...h` that you can use as the id with `YouTube-dl`

```bash
youtube-dl RBSGKlAvoiM
```

## Downloading a Whole Channel

Now to the most important one option. You have to enter a plane or will be offline for a while (9-26 hours). Before departing is a great opportunity to download someone's channel. 

```
youtube-dl https://www.youtube.com/channel/UC8butISFwT-Wl7EV0hUK0BQ
[youtube:channel] UC8butISFwT-Wl7EV0hUK0BQ: Downloading channel page
[youtube:playlist] UU8butISFwT-Wl7EV0hUK0BQ: Downloading webpage
[download] Downloading playlist: Uploads from freeCodeCamp.org
[youtube:playlist] UU8butISFwT-Wl7EV0hUK0BQ: Downloading page #1
[youtube:playlist] UU8butISFwT-Wl7EV0hUK0BQ: Downloading page #2
[youtube:playlist] UU8butISFwT-Wl7EV0hUK0BQ: Downloading page #3
[youtube:playlist] UU8butISFwT-Wl7EV0hUK0BQ: Downloading page #4
```

This command might take a long time depending on the channel size. First, it gets the pages then, figures out how many videos there are before moving on to download.

## Audio File From Video 

Sometimes a technical talk is just more enjoyable as a podcast or you want to review it without all of the visual noise. For those, I download them as mp3 files and listen while taking a walk

```
youtube-dl --extract-audio --audio-format mp3 RBSGKlAvoiM
```

## Summary

Aborting `youtube-dl` is harmless. It can easily resume downloading after being stopped. To avoid any issues with the terminal you can escape your links or easier wrap them in double quotation marks `""` when they contain special characters.

To be honest, I have not bothered reading the manual so there are probably lots of cool things I am not aware of. If you want to do something that is not mentioned here like getting the video in a specific resolution, then check out the various options from `youtube-dl --help`.

I hope you learned something new :) I personally use this great tool to learn better at my own time but please don't abuse it for other purposes and use at your own risk 👌🏾

---
Thanks for reading.

[yt]: https://ytdl-org.github.io/youtube-dl/index.html