12

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?

11

Try the command

youtube-dl --extract-audio --audio-format mp3 --output "%(uploader)s%(title)s.%(ext)s" http://www.youtube.com/watch?v=rtOvBOTyX00
  • That gives ERROR: Error in output template: unsupported format character 't' (0x74) at index 1 (encoding: 'UTF-8'). – Joseph John May 30 '15 at 7:36
  • Still the same error. Did you try the command and does it work for you? – Joseph John May 30 '15 at 7:41
  • No, but this is from man youtube-dl I'm seraching for a fix – Maythux May 30 '15 at 7:42
  • @JosephJohn check it now – Maythux May 30 '15 at 7:46
  • It still gives an error youtube-dl: error: Cannot download a video and extract audio into the same file! Use "/%(uploader)s/%(title)s.%(ext)s" instead of "/%(uploader)s/%(title)s" as the output template. But Ben's answer works fine! – Joseph John May 30 '15 at 7:47
9

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
  • 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 7:46
  • 2
    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 7:48
  • @Maythux: It's not a copy-paste. – Joseph John May 30 '15 at 7:50
  • 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 7:51
  • 1
    s indeed... World's most unnecessary delimiter. – Tom May 22 '16 at 14:09
0

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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.