49

I can create an mp3 of a YouTube video with the following command:

youtube-dl --extract-audio --audio-format mp3 http://www.youtube.com/watch?v=rtOvBOTyX00

It creates an mp3 with the following filename:

Christina Perri - A Thousand Years [Official Music Video]-rtOvBOTyX00.mp3

I don't need the video ID part (rtOvBOTyX00) at the end and would like to have just the following:

Christina Perri - A Thousand Years [Official Music Video].mp3

Is this achievable with youtube-dl's options? If not, what's the next best solution?

Joseph John
  • 731
  • 1
  • 7
  • 11

4 Answers4

49

Try the command

youtube-dl --extract-audio --audio-format mp3 --output "%(uploader)s%(title)s.%(ext)s" http://www.youtube.com/watch?v=rtOvBOTyX00
Maythux
  • 82,867
  • 54
  • 239
  • 271
25

As you could reed in the youtube-dl manpage the corresponding option would be -o :

youtube-dl --extract-audio --audio-format mp3 -o "%(title)s.%(ext)s" http://www.youtube.com/watch?v=rtOvBOTyX00
Ben
  • 603
  • 5
  • 14
  • Excellent. This does exactly what I need. I'd tried the same command but I'd used `%(title).%(ext)s` instead. Thank you! – Joseph John May 30 '15 at 07:46
  • 4
    Could you tell me what the `s` is for? I checked the manpage, but the page doesn't seem to explain that. – Joseph John May 30 '15 at 07:48
  • 1
    Yes the lowercase s is part of the "special sequence" without the percentage the brackets and the 's' it would try to take the text after the -o as the literal filename. – Ben May 30 '15 at 07:51
  • @Maythux I didn't - on the one hand you added the %uploader which wasn't requested, and on the other you added '/' where they shouldn't be. Espacally the first '/' before the uploader makes it an absolute path what you definetly won't want. – Ben May 30 '15 at 07:53
  • `Christina Perri - A Thousand Years [Official Music Video].mp3` The OP sted that,,, `Christina Perri` is the uploader, so indeed he asks for the uploader – Maythux May 30 '15 at 07:57
  • I can't see stating that this is the uploader - but that doesn't matter. The important part is that he get's said output without any formatting so he useses the default one which hasn't the uploader in it. Second you wouldn't get that output that way either apart from the very bad '/' in the beginning which refers to the / of your filesystem you have another - as seperator you would need ' - ' if you wanted that output. – Ben May 30 '15 at 08:05
  • 2
    `s` indeed... World's most unnecessary delimiter. – Tom May 22 '16 at 14:09
  • what if I already have the filename and I want to bypass the template ? – Antonello Jun 27 '16 at 20:20
  • @Antonello just use -o without any variables. -o 'staticfilename.mp3' – Ben Jun 28 '16 at 09:13
  • @Ben this doesnt work, the output file then is broken, larger than the other one, and not recognized by vlc for example. – phil294 Aug 10 '19 at 13:49
3

You can specify name by using argument --output and then specifying the name in the following syntax in place of specific_name

youtube-dl https://www.youtube.com/watch?v=iuJDhFRDx9M -x --audio-format mp3 --output "specific_name.%(ext)s"
0

Escape your percent signs, so %(title)s becomes %%(title)s. I had this issue myself.