youtube-dl is a small application written with python to download youtube provided media content like video and audio. What makes youtube-dl so popular are simple, works and rich feature set. youtube-dl currently supports
- Google Video
We will look in detail how to use youtube-dl provided features. youtube-dl can run Windows, Linux like Ubuntu,Fedora,Debian, Mac OS X operating systems.
Download and Install youtube-dl
youtube-dl can be get different ways like pip, package manager, manual download etc. We will look most easy and recent one ways.
Windows binary can be downloaded from link below. And installed with Next-Next
Linux (Ubuntu, Debian)
Ubuntu and Debian packages can be installed with apt command like below.
$ apt install youtube-dl
$ yum install youtube-dl
Pip provides operating system independent python package and library management. By using pip youtube-dl can be downloaded like below.
$ pip install youtube-dl
Youtube-dl has a long help page which contains all details of its features. Help page can be listed like below.
$ youtube-dl -h
Man page provides more detailed information about youtube-dl usage.
$ man youtube-dl
Update scenario can change according to our installation method. IF we have installed with package manager like apt, yum or pip we should use these tools to update. If we have installed manually following command can be used to update.
$ youtube-dl --update
Download Video With Url
The most popular usage of youtube-dl is downloading videos by providing their urls. While providing urls to prevent bash related errors use double quote.This will download the video and save most appropriate format to our local computer.
$ youtube-dl "https://www.youtube.com/watch?v=9KsnFWejpQg"
If we are only interested with audio part and not video part -x parameter will extract audio from video. The format will be
mp3 in this situation.
$ youtube-dl -x "https://www.youtube.com/watch?v=9KsnFWejpQg"
YouTube provides videos as playlist too where these videos are related. Youtube-dl can download playlist videos one by one like following command.
$ youtube-dl "https://www.youtube.com/watch?v=9KsnFWejpQg&list=PLH15HpR5qRsXcnfTOLOA3yYSd0CmYwOHS"
List Supported Video Formats
Youtube provides videos on different formats and resolution. To get all formats and resolutions about a video -F option can be provided with url like below.
$ youtube-dl -F "https://www.youtube.com/watch?v=9KsnFWejpQg"
Download Video As Mp4
From supported formats list select mp4 extension and intended resolutions format code.
$ youtube-dl -f 22 "https://www.youtube.com/watch?v=9KsnFWejpQg"
Download Video As Webm
Similar to the mp4 example webm format code should be provided from supported video formats.
$ youtube-dl -f 247 "https://www.youtube.com/watch?v=9KsnFWejpQg"
Download With All Subtitles
Some video service providers also provides subtitles about videos in different languages. These sub titles are low in size and can be downloaded like below.
$ youtube-dl --all-subs "https://www.youtube.com/watch?v=9KsnFWejpQg"
Download Batch File
Download file urls can be provided from interactive command line what we have done up to now or from a file. This file should contains links line by line like example below.
and downloads can be started like below.
$ youtube-dl -a mylist.txt
Downloading video files will consume a lot of bandwidth because of the video nature. To prevent network congestion bandwidth usage limit can be set for youtube-dl like below. -r 1000 sets bandwidth as 1000 byte/second.
$ youtube-dl -r 1000 "https://www.youtube.com/watch?v=J5g0udW2jMQ"
Resume Even Errors
Sometimes errors occur in different ways like video not available for your country or video is deleted. By default this type of errors will stop download especially in playlist download. To prevent download stopping from errors -i option is provided to ignore errors.
$ youtube-dl -i "https://www.youtube.com/watch?v=J5g0udW2jMQ"