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.

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

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

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

for VIDEO in `ls *.flv`; do
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
rm -rf $VIDEO
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