How to specify a filename while extracting audio using youtube-dl?

112,836

Solution 1

Try the command

youtube-dl --extract-audio --audio-format mp3 --output "%(uploader)s%(title)s.%(ext)s" http://www.youtube.com/watch?v=rtOvBOTyX00

Solution 2

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

Solution 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"
Share:
112,836

Related videos on Youtube

Joseph John
Author by

Joseph John

Updated on September 18, 2022

Comments

  • Joseph John
    Joseph John almost 2 years

    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
    Joseph John about 9 years
    That gives ERROR: Error in output template: unsupported format character 't' (0x74) at index 1 (encoding: 'UTF-8').
  • Joseph John
    Joseph John about 9 years
    Still the same error. Did you try the command and does it work for you?
  • Maythux
    Maythux about 9 years
    No, but this is from man youtube-dl I'm seraching for a fix
  • Joseph John
    Joseph John about 9 years
    Excellent. This does exactly what I need. I'd tried the same command but I'd used %(title).%(ext)s instead. Thank you!
  • Maythux
    Maythux about 9 years
    @JosephJohn check it now
  • Joseph John
    Joseph John about 9 years
    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
    Joseph John about 9 years
    Could you tell me what the s is for? I checked the manpage, but the page doesn't seem to explain that.
  • Maythux
    Maythux about 9 years
    updated now check it
  • Joseph John
    Joseph John about 9 years
    I don't need the uploader information in the filename. Ben's solution works fine for me, but thank you nonetheless. Have a great day! :)
  • Maythux
    Maythux about 9 years
    Christina Perri - A Thousand Years [Official Music Video].mp3 you stated that,,, Christina Perri is the uploader, so indeed you ask for the uploader
  • Ben
    Ben about 9 years
    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
    Ben about 9 years
    @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.
  • Maythux
    Maythux about 9 years
    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
  • Joseph John
    Joseph John about 9 years
    I just need whatever video title is there as the filename. It doesn't always have to be the uploader's name at the beginning.
  • Ben
    Ben about 9 years
    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.
  • Tom
    Tom about 8 years
    s indeed... World's most unnecessary delimiter.
  • Antonello
    Antonello almost 8 years
    what if I already have the filename and I want to bypass the template ?
  • Ben
    Ben almost 8 years
    @Antonello just use -o without any variables. -o 'staticfilename.mp3'
  • phil294
    phil294 almost 5 years
    @Ben this doesnt work, the output file then is broken, larger than the other one, and not recognized by vlc for example.
  • mickmackusa
    mickmackusa about 4 years
    Please add an explanation to this "Try this" answer.