Home > Enterprise >  Change name of audio file downloaded from youtube-dl
Change name of audio file downloaded from youtube-dl

Time:02-14

I am writing a shell script to download audio.

I used youtube-dl -f 'bestaudio[ext=m4a]' <myurl> The resulting file is the title along with-mSc76Q90C4.m4a where m4a is the format

I would like to set the filename during download and also have it in .wav format

PS: To covert to .wav, I tried youtube-dl -f 'bestaudio[ext=wav]' <myurl> but it did not seem to work. Error thrown is basically - cannot use specified format.

Here is the relavent part of my shell script

   `read -p "Copy and paste the YouTube url" URL
    echo $URL
    read -p "Enter the song name" SONG
    youtube-dl -f 'bestaudio[ext=m4a]' $URL`  

I would like the string in $SONG to be the filename.

So if $SONG = "mysongname" I want the file to be mysongname.wav

CodePudding user response:

In the documentation of youtube-dl you'll find a --output option that lets you set the filename directly:

youtube-dl -f 'bestaudio[ext=m4a]' -o "$SONG" "$URL"

There's also a --audio-format option that seems to convert the extracted audio stream from a video to a given audio format but I'm not sure that it'll work for non-video files.

  • Related