I’m working on a podcasting project that requires me to extract the audio from multiple YouTube videos. So, I put together a little script that allows me to batch extract the audio from a comma-separated list of YouTube urls.
In case someone else might find this functionality useful, I’ve put together the instructions for creating and executing the script here. It requires that you’re a bit comfortable with the command-line, and assumes you’re on a UNIX-based system (such as Linux or OS X).
The script requires a command-line program called youtube-dl. You can download it here. (And make sure to follow the installation instructions in order to make it executable.)
Once that is downloaded, create a text file and name it ytmp3.sh:
for i in $(echo $1 | sed “s/,/ /g”)doyoutube-dl — extract-audio — audio-format=mp3 -t $idone
Once you’ve created the script, make it executable with the following:
sudo chmod a+rx ytmp3.sh
Then, you can move it to /usr/local/bin so that it’s executable from anywhere:
mv ytmp3.sh /usr/local/bin
Now you can execute run the script by passing to it a comma-separated list (no spaces), eg.:
ytmp3.sh https://www.youtube.com/watch?v=yGhm7NfDaz8,https://www.youtube.com/watch?v=UJl-rMSULrk,https://www.youtube.com/watch?v=nPU7rnYpSxc
It will cycle through each video, extract the audio, and convert it to an mp3 for you.
It’s a simple script, but I’m new to Bash-scripting, so I was quite impressed with myself. I hope someone can find it useful!