Note: This guide is targeted towards computers running Windows 10
In this guide, you will both learn how to download Youtube videos, and develop a basic understanding of how to use command-line programs. They can be scary to use at first, but I hope by the end of this guide you can see how simple to use they can be after learning the basics.
For this guide, we will be using a piece of software named yt-dlp.
Direct download for the Windows version of yt-dlpyt-dlp is a piece of command-line software that can download video and audio from the internet. Its mainly used for downloading youtube videos, but also supports sites like niconico or bilibili. A full list of supported sites is available on github.
Optional: You can visit the github page of yt-dlp to download the program if the above download link doesn't work. On the github page, scroll down until you get to the table of contents of the README section, then click on the link labelled "installation." From there you can click on the button labeled "Windows x64" to download it
Create a new folder on your computer. It can live anywhere and be named anything, though a name without any spaces in it is preferrable. Copy the yt-dlp.exe
file into this new folder.
This folder will basically be used as "scratch space" for running yt-dlp and for storing the downloaded files. For that reason, we'll be calling this our scratch folder.
As an example, I'm going to show how to download this silly kitty youtube video :3
First, you'll want to open Windows Powershell in your new scratch folder. You can do this in one of two ways:
This should open a powershell window in the current folder. Powershell is a tool that you can use to run command-line programs. Command-line programs are run by typing their name, and then typing all the parameters you want to give to them.
./yt-dlp.exe https://youtu.be/XZ1klqk-WOE
A breakdown of what this command means:
./
is a series of characters that represents the inside of the current folder. In other words, it lets us target and run a .exe
file inside the current folder.yt-dlp.exe
is the name of the program. Because we wrote ./
before it, it targets the program inside the current folder. You can choose to omit the .exe
part, if you wish, as it is optional. Anything written after the name of the program will be given to it as a program parameter that it will use.https://youtu.be/XZ1klqk-WOE
is the only parameter we are giving to our program, which is the URL to which the video resides. This could be replaced with any URL!In short, to download a video, you should first type the identifier of the program, ./yt-dlp.exe
, and then after a space, paste in the URL of any youtube video.
Important: When pasting a URL, you'll want to make sure it's just the base minimum URL, with no extra data added on. For example, if a youtube URL is part of a playlist, then you'll end up downloading the whole playlist! In the case of youtube URLs, you'll want to remove first &
symbol and everything after it.
In addition to this playlist issue, Powershell doesn't like it when you have &
symbols in your command that aren't wrapped in quotes, and will give an error when this happens. In case you actually want to download an entire playlist, you'll have to wrap your URL in quotes to fix the error.
./yt-dlp https://www.youtube.com/watch?v=mWPNZ_agAZs&list=PLy22iKf8SNXg9YcbkS5dRtkz1Gd9Q_dqT&index=2
./yt-dlp "https://www.youtube.com/watch?v=mWPNZ_agAZs&list=PLy22iKf8SNXg9YcbkS5dRtkz1Gd9Q_dqT&index=2"
./yt-dlp https://www.youtube.com/watch?v=mWPNZ_agAZs
If you've been following along, you'll have downloaded a .webm
file into your scratch folder. (Assuming this is still the default at the time you're reading this.) But, oh no! What if we needed an .mp4
file instead of a .webm
?
To solve this issue, we'll need to use a flag. A flag is a parameter given to a program used to change specific options. In our case, we want the -f
flag, which stands for format. This flag takes one input, the name of the format, written with a space after the flag.
In other words, the format flag takes the form of -f FORMAT
, where FORMAT
is replaced with your desired file type. Flags can go anywhere after the program name, so it doesn't matter if it's before or after the URL.
.mp4
file:./yt-dlp https://youtu.be/XZ1klqk-WOE -f mp4
However, in our modern internet ecosystem, selecting a format may not be so simple. Only certain formats are available, often in many different resolutions, and some formats splitting up audio and video, only to be zipped back together when it reaches the user. Fortunately, yt-dlp lets us look behind the curtain and see what exactly a website is serving us.
-F
flag (note the capital letter), also known as --list-formats
, lets us look at what what formats are available in that given video URL. It doesn't take any inputs. This command stop the act of downloading the video, and instead shows us a chart of all the available formats. Here is an example of what an output might look like:./yt-dlp https://youtu.be/XZ1klqk-WOE -F
[youtube] Extracting URL: https://youtu.be/XZ1klqk-WOE
...
[info] Available formats for XZ1klqk-WOE:
ID EXT RESOLUTION FPS │ FILESIZE TBR PROTO │ VCODEC VBR ACODEC
────────────────────────────────────────────────────────────────────────────────
sb0 mhtml 48x27 14 │ mhtml │ images
233 mp4 audio only │ m3u8 │ audio only unknown
234 mp4 audio only │ m3u8 │ audio only unknown
269 mp4 192x144 30 │ ~108.67KiB 127k m3u8 │ avc1.4D400C 127k video only
229 mp4 320x240 30 │ ~182.49KiB 214k m3u8 │ avc1.4D400D 214k video only
230 mp4 480x360 30 │ ~363.84KiB 426k m3u8 │ avc1.4D401E 426k video only
605 mp4 480x360 30 │ ~280.29KiB 328k m3u8 │ vp09.00.21.08 328k video only
The green numbers under the ID
column are codes corresponding to different audio and video files that are on youtube's servers. These numbers can be used with -f
to select a specific file. As you can see in the chart, there are no files that contain both video and audio, so they will have to be combined.
[info] XZ1klqk-WOE: Downloading 1 format(s): 605+234
./yt-dlp https://youtu.be/XZ1klqk-WOE -f 605+234
The yt-dlp github page has more information on selecting formats, but two special codes that are good to know are bestvideo
and bestaudio
. They can stand in for file IDs to automatically select the best video/audio file.
There are many other flags that you may find useful when downloading videos. For a complete list, see the "Usage and Options" section on the yt-dlp github page.
One of the most important flags to know is the -U
flag, which stands for update. Whenever a video download has a strange error, you should use it to make sure you have the most up-to-date version, as sites like youtube tend to enjoy messing with downloader programs.
./yt-dlp -U
Flag | Description |
---|---|
-U |
Update yt-dlp. Always try first when download fails. |
--update-to CHANNEL |
Used to update to the nightly channel, or downgrade to the stable channel |
--cookies-from-browser BROWSER |
Use login cookies for site from chosen browser. |
-f FORMAT |
Download video in available format (or format code) |
-F |
List available formats (with format codes) |
-o FILENAME |
Output to specific file. See output template |
In order to use the following flags, you will need to follow the installations instructions of ffmpeg in the next section.
Flag | Description |
---|---|
-x |
Extract audio from video. |
--audio-format FORMAT |
Convert audio from -x |
--remux-video FORMAT |
Change video container, without reencoding it. |
--recode-video FORMAT |
Reencode video to another format. |
In order to extract audio from a video, you will need a copy of ffmpeg, which is a program that yt-dlp uses to convert videos to different formats.
ffmpeg-master-latest-win64-gpl
folder, and then into the bin
folder.ffmpeg.exe
and ffprobe.exe
into the scratch folder you made earlier.At the end, your scratch folder should look something like this:
Now, yt-dlp will automatically use these programs for advanced functions, like audio handling. You can access features like this using new flags that you can add to your command. Here is a list of the ones relevant to extracting audio:
-x
stands for extract audio, and is the flag that marks that the program should save the audio and throw away the video. It has no parameters, so it doesn't require anything else to work. The resulting audio file's type will be the default audio codec for the video you have selected.--audio-format FORMAT
will change the type of file that the -x
flag outputs. FORMAT
should be replaced with the type of file you want../yt-dlp https://youtu.be/XZ1klqk-WOE -x
./yt-dlp https://youtu.be/XZ1klqk-WOE -x --audio-format mp3
Downloading ffmpeg also unlocks a few other useful flags, such as --remux-video FORMAT
and --recode-video FORMAT
. You may check the github page for information on these as well.
ffmpeg is a complete video and audio handling program in its own right, and you may find it useful if you work heavily with either. Googling "convert video in ffmpeg" or "resize video in ffmpeg" or anything similar should yeild good results if you need something done fast. For more details, see the official ffmpeg wiki or the full documentation.
If you plan to use ffmpeg this way in conjuction with yt-dlp, you may also want to know that pressing Tab in Powershell will autocomplete any file you have started to type in.
When using command-line software, it can be annoying to have to open a specific folder just to use the program, especially if you're going to want to copy those files elsewhere afterwards. To fix this, we're going to take advantage of the Windows Path
variable to let us run yt-dlp anywhere on your computer.
First, you're going to want to create another new folder. It can be in any location and be named anything, but I'm going to use the example folder C:\MyPath
in this guide. You should copy all your .exe
files to it that you had in your previous scratch folder, and it should not contain anything else.
We're going to need to copy the exact file path of this new folder, and you can do that in one of two ways:
Now that you have the folder path copied, you'll have to find the place where you tell Windows that you want to use that folder as a special Path
Variable folder.
First, search for "environment variables" in your start menu. Click on the entry marked "Edit the system environment variables."
Then, click on the "Environment Variables" button on the bottom right.
In the window that pops up, find the variable named "Path" in either the User variables section or System variables section. It doesn't matter which one, the only difference is the "User variables" section will only affect your own account, and the "System variables" section will affect the account of everyone who uses your computer.
When you find the "Path" variable, select it and then click "Edit" in its corresponding box.
In this window, you should see a list of all file paths in your Path variable, assuming you have any. Click on the New button in the top right, and then paste in the folder path you copied earlier. Be sure to press enter after you paste the folder path, and then press OK in the bottom right. If you don't do both of these things, your changes will not be saved.
Now, after opening and closing Powershell, you will be able to use yt-dlp inside of any folder in your computer, and it will download the files in whatever folder you open Powershell in! You will have to slightly change your commands, though.
./
portion of the command, as that part was just to tell Powershell to run the program in the current folder. Now that the program is available anywhere, you don't need it anymore:yt-dlp.exe https://youtu.be/XZ1klqk-WOE
.exe
portion as well:yt-dlp https://youtu.be/XZ1klqk-WOE
Keep in mind your newly created path folder should not be used to download any videos, as it is only supposed to contain runnable programs.
If you happen to download any other standalone command-line programs after reading this guide, placing them into your path folder (in my case C:\MyPath
) will allow them to run anywhere as well.