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"
Related videos on Youtube
Author by
Joseph John
Updated on September 18, 2022Comments
-
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 about 9 yearsThat gives
ERROR: Error in output template: unsupported format character 't' (0x74) at index 1 (encoding: 'UTF-8')
. -
Joseph John about 9 yearsStill the same error. Did you try the command and does it work for you?
-
Maythux about 9 yearsNo, but this is from
man youtube-dl
I'm seraching for a fix -
Joseph John about 9 yearsExcellent. This does exactly what I need. I'd tried the same command but I'd used
%(title).%(ext)s
instead. Thank you! -
Maythux about 9 years@JosephJohn check it now
-
Joseph John about 9 yearsIt 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 about 9 yearsCould you tell me what the
s
is for? I checked the manpage, but the page doesn't seem to explain that. -
Maythux about 9 yearsupdated now check it
-
Joseph John about 9 yearsI 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 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 about 9 yearsYes 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 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 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 about 9 yearsI 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 about 9 yearsI 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 about 8 years
s
indeed... World's most unnecessary delimiter. -
Antonello almost 8 yearswhat if I already have the filename and I want to bypass the template ?
-
Ben almost 8 years@Antonello just use -o without any variables. -o 'staticfilename.mp3'
-
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 about 4 yearsPlease add an explanation to this "Try this" answer.