Youtube download

Do you need some music downloads to listen before travel? I find a great program, youtube-dl, online. It is a command-line program to download videos from YouTube and many other video sites. For details, visit its official github.

There are various ways to install youtube-dl. You can visit its download page, https://ytdl-org.github.io/youtube-dl/download.html. I will briefly demonstrate how to isntall youtube-dl in Windows 10.

Install

  1. Download the lastest youtube-dl.exe at the download page.

download

  1. Download ffmpeg. Youtube-dl will use this program 1) to extract audio from video or 2) to merge video and audio for a higher quality video. Download a ffmpeg Windows build zip file and extract it. You will use all files (ffmpeg.exe, ffplay.exe, ffprobe.exe) inside the bin directory of the extract. For other OS, visit its download page.

ffmpeg

  1. Let's make a youtube-dl prorgram folder. I created a youtube-dl folder inside C://Program Files and copy all downloads into that folder.

yotube-dl-folder

  1. Add the youtube-dl program folder (C:\Program Files\youtube-dl) to your environment path, so that you can run youtube-dl in any folder inside your command console.

environ

One extra tip: If you have already installed it and encounter some errors after using the program for a while, try update youtube-dl, youtube-dl --update. This will fix any outdated errors.

How to Use

Command syntax: youtube-dl [options] url

  1. to download a video, run youtube-dl --merge-output-format mp4 "https://www.youtube.com/watch?v=gdZLi9oWNZg"

  2. to download an audio only, run youtube-dl --extract-audio --audio-quality 0 --audio-format mp3 "https://www.youtube.com/watch?v=gdZLi9oWNZg"

I downloaded a video in mp4 file format and extracted audio with the best quality in mp3 format. The download location is the same folder that I run the youtube-dl command. There are many other download options that you can specify for different download scenarios. However, it is not practical to remember all options. There is an easy way to preconfigure different download settings using a config.txt file.


Config.txt

Create a config file at %APPDATA%\youtube-dl\config.txt. The config file is called when you execute youtube-dl program, so that you set up how to download the video sources in that file. Here I will set up options for four different download cases. As you see, I also predefine download locations (Musics & Videos) for organizing the downloads better.

### Four Download Cases ###

#### AUDIO ####
## First, extract to a mp3 audio and download it in the Music folder 
# --extract-audio --audio-quality 0 --audio-format mp3 -o C:/Users/Seong/Music/youtube-dl/%(title)s.%(ext)s

## Second, extract a playlist to mp3 videos and download them in in the Music folder
# --extract-audio --audio-quality 0 --audio-format mp3 -o C:/Users/Seong/Music/youtube-dl/%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s --ignore-errors
 

#### VIDEO  ####
## Third, download a video into the Videos folder
# -o C:/Users/Seong/Videos/youtube-dl/%(title)s.%(ext)s --merge-output-format mp4

## Fourth, download playlist videos into the Videos folder
-o C:/Users/Seong/Videos/youtube-dl/%(playlist)s/%(playlist_index)s-%(title)s.%(ext)s --merge-output-format mp4 --ignore-errors

You will notice that I used output template. You can learn them for your own customizations.


What if I need options different than the ones in a config.txt:

In some cases, you want to use different options for special download cases. Then, you can pass --ignore-config like this. youtube-dl --ignore-config --playlist-items 2-3 "https://www.youtube.com/watch?v=IFYvVDxYmTg&list=PL_Cqw69_m_ywZzMrQO0Yv2CWxKFEs1c6N&index=2"

You can select a file

Do you know what? You can list downloadable formats. Uuse -F flag, youtube-dl -F "https://www.youtube.com/watch?v=gdZLi9oWNZg" And you can choose a format code, youtube-dl -f 140 "https://www.youtube.com/watch?v=gdZLi9oWNZg" or youtube-dl -f 140,137 "https://www.youtube.com/watch?v=gdZLi9oWNZg"

list