how can I set default download location in youtube-dl so that everything that I download with youtube-dl goes into that default directory?
-
Make an alias to `youtube-dl --output /path/to/your/dir`. I don't think there's a permanent way to set the output directory. – JAL Sep 09 '15 at 14:30
-
3I just downloaded an entire playlist, where did it put the files? – user101 Sep 09 '15 at 14:37
-
5In the directory where you ran the `youtube-dl` command. – JAL Sep 09 '15 at 14:37
-
Until they add a switch to set the output directory, you can use `pushd` and `popd` to switch to the output directory, call `youtube-dl` from its location, and switch back. – Synetech Apr 10 '16 at 23:18
-
dude! from terminal go to the folder you want your YouTube files to be downloaded to using cd command, then run the youtube-dl command. – ashubuntu Apr 07 '17 at 12:44
-
@Synetech I hope the `youtube-dl` team accepts my [feature request](https://github.com/ytdl-org/youtube-dl/issues/20502) for that :-) – SebMa Mar 29 '19 at 01:49
8 Answers
You need to use the -o
switch with the Configuration file
Output on youtube-dl
is handled with the --output
or -o
switch; pass it as an option, followed by the destination you want to save your downloads to:
youtube-dl -o "%USERPROFILE%\Desktop\%(title)s-%(id)s.%(ext)s" www.youtube.com/link/to/video
Note that -o
has a dual function in that it also sets a template for how your output files will be named, using variables. In this example, it will output the title of the original downloaded video followed by the file extension, which is my personal preference. For all of the variables that can be used in a filename, have a look at the youtube-dl documentation here.
youtube-dl
also allows use of a configuration file - a file that can be used to configure the switches you most frequently use so the program can pull them from there instead, saving you from having to explicitly call them each time you run it. This is what you'll need for the default download location that you're looking for. The configuration file can be used to set a default output destination so that you never have to explicitly set an output again.
To set up a configuration file for youtube-dl, assuming you have Windows:
In
%APPDATA%\Roaming
, create ayoutube-dl
folder if one doesn't already exist.Inside that folder, create a plain text file named
config.txt
.Place
youtube-dl
options in the file as you'd normally use them on the command line withyoutube-dl
, placing each one on a new line. For example, for the output switch, you'd use:-o %USERPROFILE%\Desktop
. For more on the Configuration file, read the documentation on it here.
Overriding the Configuration file
Even when an option is configured in a configuration file, it can be overridden by calling it explicitly from the command line. So, if you have -o
set in a configuration file to be the default location for downloads, but want to save downloads to somewhere else for a current job, simply calling -o
on the command line will override the configuration file for the current run of the program only.

- 4,074
- 5
- 38
- 68
-
5The problem is that using the `-o` switch requires specifying the filename template. I don’t want to do that and would rather use the default (which includes more than just the title). There really should be an option to specify just the output directory (especially since youtube-dl is based on wget which has the `-P` switch for this). – Synetech Apr 10 '16 at 23:17
-
12youtube-dl is not based on wget, and you can simply append `%(title)s-%(id)s.%(ext)s` to your output template to get the default basename. – phihag Sep 05 '16 at 13:24
-
@phihag - that's exactly what I needed. I saw this post last week. I'm glad I read the comments this time. I think that' why the answer was not chosen. You should add your comment to this solution (as an edit solution) as it would be most helpful and a sweet addition. – ejbytes Dec 14 '20 at 21:07
-
@phihag One more thing. I left a message above also. But, I just rant into a problem. I want to use -f options, but also -o and use your suggestion. It doesn't like that. You seem the right person to ask. Thx! – ejbytes Dec 14 '20 at 21:21
-
@phihag It was a bit more compolicated than just knowing the explicit command. I worked on it for a couple hours and realized that in order to use other parameters with this parameter you have to create a simple config file. I offered my solution as an answer for onlookers. – ejbytes Dec 15 '20 at 00:55
-
@ejbytes The reason this answer wasn't accepted by the questioner was likely because I posted it in 2016, a year after they last logged in. I have edited `youtube-dl`'s default filename into the answer as you requested, but you should remember that this is an arbitrary default that's used by `youtube-dl` when no `-o` option is specified - if you're setting `-o` anyway, you may as well set the output filename how you want. My answer also explains the config file in some detail, but there's no reason you would need one to do what you're trying to do, as demonstrated in my comment to your answer. – Hashim Aziz Dec 15 '20 at 21:23
-
@Prometheus - yeah, one hit wonders that never come back. It's why I stopped contributing a couple years ago. I was bashing my brains out trying to get this to work in a batch file. Via cmd is straight forward. But trying to get weird stuff into variables and then using them is so difficult in batch script writing. I tried int via command line, works like a charm. But in the batch file took me a couple more hours to figure it out. Like adding the extra % from % to %%, which is reverse logic because cmd is usually one % and batch two %%. Weird! – ejbytes Dec 15 '20 at 21:29
-
2It's ridiculous you have to specify the entire format. It should just allow you to output it to a directory in the default format – Levi H May 03 '21 at 21:18
-
I get an error when I add this to my code: youtube-dl --extract-audio --audio-format best --audio-quality 0 --embed-thumbnail --add-metadata --audio-format mp3 -o ' C:\Users\ruben\Spotify_playlists_downloads\%(title)s-%(id)s.%(ext)s' https://www.youtube.com/playlist?list=PL2dtgjRRrmS1LeAp_L3lthEp9AQq5Ns5O Cannot download a video and extract audio into the same file! Use "'.%(ext)s" instead of "'" as the output template – babipsylon Dec 29 '21 at 17:33
-
1This is very useful! I would like to add, as of January 2022, that an -o in a Windows file system needs you to have forward slashes. So -o c:\yt-transcripts = doesn't work, -o c:/yt-transcripts does. – aschultz Jan 21 '22 at 07:14
I find a way to directly download files in Downloads folder. I search for long hours. I copied my entire function then you can understand the context around. Here is my code it will maybe helpful for someone:
import os
def download_audio(request):
SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'outtmpl':SAVE_PATH + '/%(title)s.%(ext)s',
}
link = request.GET.get('video_url')
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://www.youtube.com/watch?v="+link])
Tell me if there is a problem.

- 3,577
- 1
- 14
- 28

- 201
- 2
- 6
-
Hi NiceOyester, How can I set the download directory to Google Cloud storage ? I am using Google Cloud functions with Nodejs. – Lydia halls Oct 17 '19 at 00:54
-
1`os.path.join()` would be a better cross platform suggestion. – Arpan Srivastava Nov 29 '20 at 12:33
According to the configuration documentation, you can configure youtube-dl
with a global or user-specific configuration file:
You can configure youtube-dl by placing any supported command line option to a configuration file. On Linux and macOS, the system wide configuration file is located at
/etc/youtube-dl.conf
and the user wide configuration file at~/.config/youtube-dl/config
. On Windows, the user wide configuration file locations are%APPDATA%\youtube-dl\config.txt
orC:\Users\<user name>\youtube-dl.conf
. Note that by default configuration file may not exist so you may need to create it yourself.
On linux, this would be your user config file:
# Save all my videos to the Videos directory:
-o ~/Videos/%(title)s.%(ext)s

- 318
- 2
- 14
-
if we set up `-o` output directory does it directly download to that location or downloads to different location temporarily and then move to the output directory ? – Chang Zhao Oct 20 '21 at 19:50
Depending on your needs, I think moving the file afterwards would be just as usefull:
--exec CMD Execute a command on the file after
downloading, similar to find's -exec
syntax. Example: --exec 'adb push {}
/sdcard/Music/ && rm {}'
By creating a function which will move the file

- 459
- 1
- 5
- 16
Here is the complete solution I use:
from youtube_dl import YoutubeDL
ydl_opts = {
'format': 'best',
'outtmpl': 'DIR-PATH-HERE%(title)s'+'.mp4',
'noplaylist': True,
'extract-audio': True,
}
video = "https://www.youtube.com/watch?v=SlPhMPnQ58k"
with YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video, download=True)
video_url = info_dict.get("url", None)
video_title = info_dict.get('title', None)
video_length = info_dict.get('duration')
# print(video_title)

- 191
- 1
- 12

- 193
- 4
- 6
-
Hello, Any idea about how can i download the video directly to client browser ? I using django, and currently when client hit the download url, video is downloaded inside my project. How can we download directly inside browser, any ideas ? – Ajji Mar 06 '23 at 14:53
I found there is an official comment by the authors about that specific question.
In the manual, here's what they say: (man youtube-dl
):
How do I put downloads into a specific folder?
Use the -o to specify an output template, for example -o "/home/user/videos/%(title)s-%(id)s.%(ext)s". If you want this for all of your downloads, put the option into your configuration file.
That filename pattern is the default, as per the man as well:
The current default template is %(title)s-%(id)s.%(ext)s.
I agree it would be nice to have the output folder decoupled from the default template in case the default changes one day, but I'm guessing the authors must have had a reason to have it this way.

- 12,810
- 7
- 47
- 57
In command line or in the bash file use the double quotes, like this:
"%userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s"
My bash command:
youtube-dl -c -i -f "mp4" -o "/home/Youtube_Downloads/%(title)s-%(id)s.%(ext)s" -a youtube_list
where 'youtube_list' - a raw text file with Youtube links, that goes line by line

- 21
- 1
This is the EXACT ANOTHER USEFUL method to download your video into a desired DIRECTORY, and also keep the native filename of the download.
- Decide where you want to create a configuration file.
- Create a file, "youtube-dl.conf". You can create a youtube-dl.txt first it it's easier, but the file must be "youtube-dl.conf".
- Here is a basic sample of a config file: this is where you want your downloads to go. This is all you have to put into the file. Where -o is the flag, %userprofile%/Desktop/DL/ is where I want the download to go, and %(title)s-%(id)s.%(ext)s is the command to keep the native filename.
This is your config file below:
-o %userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s
- The command paramaters:
%program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%"
Batch File setup:
::Variables: Set program="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\youtube-dl.exe" Set option=best SET MYPATH="%USERPROFILE%\Desktop\YOUTUBE-DL\v20201209\config" SET MYCONFIG="--config-location" SET MYDLDIR="%USERPROFILE%\Desktop\DL" SET INSTR='%%(title)s-%%(id)s.%%(ext)s' MKDIR "%USERPROFILE%\Desktop\DL" ::Ask user for input. Set /P youtubelink=[Past Link]: :: For use of config file, for default download location. %program% -f %option% "%youtubelink%" "%MYCONFIG%" "%MYPATH%" :: There are many ways to accomplish this: :: For Batch File, NOTE extra (%) character needed. :: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%%(title)s-%%(id)s.%%(ext)s %youtubelink% :: or this use of variable :: "%program%" -f "option" --merge-output-format mp4 -o "%MYDLDIR%"\%INSTR% %youtubelink%
NOTE: The use of "quotes" when there are spaces in your variable options.
Final Message:
Create the config file, put it in a folder (directory) that you wish to refer to it. Go to your youtube-dl.exe file and pass the "parameters" listed above to it using your CMD or a batch file. Done. (contribution, and being kind)

- 183
- 1
- 9
-
Apart from the default basename that I have now edited into my answer as requested, your answer doesn't seem to add anything that isn't already in my answer, and what's more seems to introduce a lot of inaccuracies in the process. Firstly, the config file does not have to end in `.conf` - only the user-specific config file does, which is only needed when you have several users using youtube-dl on the same machine *and* one of them wants to override the global config file. – Hashim Aziz Dec 15 '20 at 21:21
-
Secondly, the way you mention the "native" filename makes me think you believe it's YouTube's own default, so to clarify, the default filename /basename is just an arbitrary default that the `youtube-dl` uses when there's no `-o` option set, and if you're using `-o` anyway there's no reason you shouldn't just set it to the format you want. – Hashim Aziz Dec 15 '20 at 21:21
-
Lastly, there's no reason why you would need a config file for what you want to do here. I was able to run the following command without any issues: `youtube-dl -f best -o "%userprofile%/Desktop/DL/%(title)s-%(id)s.%(ext)s" --ignore-config https://www.youtube.com/watch?v=T6vKZhfI7qY` - note the last option is making sure I'm not using my config file at all, and I still get the download as expected. The output directory doesn't even need to exist because `youtube-dl` automatically creates it. – Hashim Aziz Dec 15 '20 at 21:22
-
2@Prometheus You seem to know a lot about this. I'm really glad for you. But it's frustrating when there is no person demonstrating the various methods for a NIFTY executable file like this. I'm contributing. I'll leave it at that. I do appreciate the partial constructive criticism though. Thanks Zeus, I mean Prometheus, or was it Creator? Just kidding, God Bless. – ejbytes Dec 15 '20 at 21:33