Let’s do some stuff …

I’ve written a simple Bash script that downloads music from youtube. After the music has been downloaded by the script, the flv file (Youtube flash format) will be automatically converted to mp3. Of course the script its last task is to remove your .flv file.

The script requires you have youtube-dl and vbrfix. If you don’t already have them, you have to install them with your package manager. I suppose you have a music folder in your /home directory, if this is not the case you can either create one or you can change the script according to your own needs.


#!/bin/bash
# checking whether you have youtube-dl
if [ ! -x `which youtube-dl`  ];then
echo “Error! youtube-dl isn’t installed.”
exit 0
fi

#checking whether you have vbrfix
if [ ! -x `which vbrfix`  ];then
echo “Error! vbrfix isn’t installed.”
exit 0
fi

#download video(s)
for URL in $*; do
youtube-dl -t “$1&fmt=18″
done

#process
for VIDEO in `ls *.flv`; do
OUTPUT=${VIDEO:0:${#VIDEO}-4}”.mp3″
ffmpeg -i $VIDEO -acodec copy $OUTPUT

#move video
mv $OUTPUT /home/$USER/music
vbrfix /home/$USER/music/$OUTPUT /home/$USER/music/$OUTPUT
rm -rf vbrfix.log vbrfix.tmp
#clean-up
rm -rf $VIDEO
done
echo “Done.”

Save the script as converter. Of course you have to make the script executable by setting the right permissions: chmod a+x converter

If you want to use it: ./converter youtube-link

phar0z.

Advertisements