7

How do I setup youtube-dl to default download to ~/Downloads instead of the home folder?

1
  • This question is not specific to OS X. youtube-dl is pretty much cross-platform application. I think it must be moved to Superuser. – Display Name May 6 '16 at 15:34
15

youtube-dl Config File

To set a default download location, create a youtube-dl configuration file at:

~/.config/youtube-dl/config

Within this file enter the line:

-o ~/Downloads/%(title)s-%(id)s.%(ext)s

You can create this file using the following two commands:

mkdir -p ~/.config/youtube-dl/
echo "-o ~/Downloads/%(title)s-%(id)s.%(ext)s" > ~/.config/youtube-dl/config

The first command mkdir, creates the folders leading to the configuration file. The second command echo writes the output option into the file.

Options set within your configuration file are applied to every call to youtube-dl. Use the --ignore-config option to disable reading of the configuration file.

3
  • 1
    I like grahams solution better than mine for use with youtube-dl. My version works for every application, though. – bot47 May 6 '16 at 11:08
  • 1
    Thank you! This is the solution. But now I’m getting mkv instead of mp4 files. – Sebastian Semmler May 6 '16 at 12:27
  • 1
    Add the following line to your config file to either request mp4 files or have youtube-dl convert after downloading to mp4: --format mp4 – Graham Miln May 6 '16 at 12:39
2

It doesn't download to your home, but to the current working directory. Change it before you want to download. If you're using bash, you might want to create a function in your .bashrc like this:

function youtube-dl ()
{
    cd ~/Downloads/ && {
        `which youtube-dl` "$@"
        cd - > /dev/null
    }
}

This changes the working directory to the Downloads folder in your home, runs the original youtube-dl with the command line arguments you passed to the function and then changes the directory back.

You also may want to have a look at this: How do I run a program with a different working directory from current, from Linux shell? as this also applies to OS X.

10
  • Did you test whether the which youtube-dl part works? Doesn't this expand to the function once it (the function) is defined? – nohillside May 6 '16 at 11:33
  • 1
    No. Functions are not in the scope of which. Which searches in PATH. I also tested the script a few times ;) – bot47 May 6 '16 at 11:49
  • 2
    To expand functions by name, use typedef -F or -f – bot47 May 6 '16 at 11:50
  • Hmm, which is aliased to type -p here which returns nothing if type -t wouldn't return file (which is doesn't as it is a function now). Great if it works in your case, strange nevertheless. – nohillside May 6 '16 at 15:23
  • whichs manpage states the following: "locate a program file in the user's path". which which also returns an executable under PATH. alias which returns nothing for me, neither on the old-age bash OS X shipped version nor on a current one. Besides, as youtube-dl can take more than one argument, I intentionally didn't add quotation marks around $@. – bot47 May 6 '16 at 15:32
1

There is no way of setting a default folder. Instead, you have to append the option -o every time.

 -o ~/Downloads/%(title)s-%(id)s.%(ext)s
  • %(title)s-%(id)s.%(ext)s is the default filename format for every download.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .