I like watching lots of conference talks but watching them on YouTube is not always ideal. You can use YouTube 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 😉 This all a breeze with youtube-dl.
ytdl-org / youtube-dl
Command-line program to download videos from YouTube.com and other video sites
youtube-dl - download videos from youtube.com or other video platforms
- INSTALLATION
- DESCRIPTION
- OPTIONS
- CONFIGURATION
- OUTPUT TEMPLATE
- FORMAT SELECTION
- VIDEO SELECTION
- FAQ
- DEVELOPER INSTRUCTIONS
- EMBEDDING YOUTUBE-DL
- BUGS
- COPYRIGHT
INSTALLATION
To install it right away for all UNIX users (Linux, macOS, etc.), type:
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
If you do not have curl, you can alternatively use a recent wget:
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
Windows users can download an .exe file and place it in any location on their PATH except for %SYSTEMROOT%\System32
(e.g. do not put in C:\Windows\System32
).
You can also use pip:
sudo -H pip install --upgrade youtube-dl
This command will update youtube-dl if you have already installed it. See the pypi page for more information.
macOS users can install youtube-dl with Homebrew:
brew install youtube-dl
Or with MacPorts:
sudo port install youtube-dl
Alternatively, refer to…
youtube-dl 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 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
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.
Top comments (2)
And you can use mpv to directly play videos using youtube-dl in the background, just
And to add even more fun, you can add your prefered channels to an RSS feed reader (I use Newsboat)
you can duckduckgo the procedure. ;)
Neat, I will try using mpv.
Sounds like a good idea with the RSS feed, especially if you have a media station with lots of storage 😄
Thanks.