ObjectiveDownload YouTube videos from the command line using youtube-dl.
DistributionsYoutube-dl is a Python script that's usable on any distribution.
- A Linux install with root access.
- Pip Python package manager
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
IntroductionPeople have wanted to download videos from YouTube since the very beginning. Several methods have worked over the years, but youtube-dl provides the most direct and reliable approach.
Youtube-dl is a Python script that pulls videos straight from YouTube and can format them on your computer. It can also separate audio or subtitles from videos.
Install YouTube-dlYoutube-dl is available from a lot of distributions' repositories, but it tends to lag somewhat behind the upstream releases. Normally, that wouldn't be a problem, but YouTube changes, and those changes can break youtube-dl.
It's best to stay current. You can do that by using Pip to manage youtube-dl as a Python package instead of a distribution one.
Install Python and PipStart off by installing Pip and Python through your distro.
$ sudo apt install python python3 python-pipFedora
# dnf install python2 python3 python-pipOpenSUSE
# zypper install python python3 python-pipArch Linux
# pacman -S python python2 python-pipGentoo
# emerge dev-python/pip
Using PipPip is a Python package manager. There are a bunch of ways to use it, but in this case, a system-wide install is best. As root, you can use Pip like your distribution's normal package manager.
# pip install youtube-dlThat's it. When it finishes, you're ready to use youtube-dl.
Downloading VideosDownloading a video is very simple. All you need to do is give youtube-dl a URL, and it'll do the rest.
$ youtube-dl https://www.youtube.com/watch?v=yVpbFMhOAwEThe file names aren't the best, but you can easily rename them.
You can specify a file format, and youtube-dl will use FFMPEG to convert the video automatically.
$ youtube-dl --recode-video mp4 https://www.youtube.com/watch?v=yVpbFMhOAwE
SubtitlesYou can also embed a video's subtitles in it when you download.
$ youtube-dl --embed-subs https://www.youtube.com/watch?v=yVpbFMhOAwEIf you want the subtitles separate from a video, you can do that too.
$ youtube-dl --get-subs https://www.youtube.com/watch?v=yVpbFMhOAwEThat video actually doesn't have subtitles, but you can get the automatically generated ones from YouTube.
$ youtube-dl --get-auto-subs https://www.youtube.com/watch?v=yVpbFMhOAwE
AudioYoutube-dl is fully capable of extracting the audio from videos with the help of FFMPEG.
$ youtube-dl -x https://www.youtube.com/watch?v=yVpbFMhOAwEYou can specify the output format too.
$ youtube-dl -x --audio-format flac https://www.youtube.com/watch?v=yVpbFMhOAwEIf you're concerned with audio quality, youtube-dl uses a scale of 0-9 to specify quality. Zero produces the highest grade output.
$ youtube-dl -x --audio-format flac --audio-quality 0 https://www.youtube.com/watch?v=yVpbFMhOAwE
Closing ThoughtsIt's probably a good time to mention that youtube-dl supports way more than just YouTube downloads. You can find the whole list on the youtube-dl Github page
Youtube-dl also has options for logins and spoofing a browser, if you need to.
Youtube-dl is simple, elegant, and powerful. Everything considered, it's easily the best tool for pulling video content from the Internet.