Bash … a new world / book2.de soundfile downloader

Yesterday I started to learn some bash basic programming because I needed to achieve a task and I knew that bash is the closest language to all my linux tools.

The task I needed to achieve was to download some sound files in different languages from book2.de, I needed those in order to polish a bit the languages I already know and to get some insight of their related sisters ;)
So basically, I wanted to make some sort of playlist that would be able to play the same ords/sentences in different languages one after another. Since book2.de offers 100 lessons each one containing 20 sound files, I have to get 2000 sound files per language for maximum 10 languages. Since I wanted no problems by messing around with tousands of files I decided to rename the files to be in the right place in my playlist by default.
So I started by diving in to bash for a couple of hours, and in the end I was able to build a pretty god (can always be better) bash script to do my job.
My first bash script :
#!/bin/bash
# script to download audio files from book2.de based on their locale
count=1
limit=2000
baseUrl=”http://www.goethe-verlag.com/book2/”
locale=$1
while [ $count -le $limit ]
do
if [ $count -lt 10 ]; then
wget -nv -O 000${count}${locale}.mp3 ${baseUrl}${locale}/SOUND/000${count}.mp3
elif [ $count -ge 10 ] && [ $count -lt 100 ]; then
wget -nv -O 00${count}${locale}.mp3 ${baseUrl}${locale}/SOUND/00${count}.mp3
elif [ $count -ge 100 ] && [ $count -lt 1000 ]; then
wget -nv -O 0${count}${locale}.mp3 ${baseUrl}${locale}/SOUND/0${count}.mp3
else wget -nv -O ${count}${locale}.mp3 ${baseUrl}${locale}/SOUND/${count}.mp3
fi
count=$(( $count + 1 ))

done

echo “Job done”
Usage: 1. save this script into a file, I called it b2down.sh
2. run ./b2down.sh EN to download all the english sounds (replace EN with your targeted locale)
3. drag the resulted files in your favourite player and you’re ready to become a polyglot
A few notes for bash beginners:
– pay attention to the spaces between and after [ ], this could drive you nuts
– protect your $variable with ${variable}
– make use of your CLI skills

Back on track

I’m back on track (at least I’m trying to be). I told myself I have to keep my blog alive, and keep the world up-to-date with my newest findings no matter how big or small they are, as long as they are focused and contain accurate info.

The main reason for not publishing anything in a long time is laziness which was fed up by some technical problems like my host database beeing hacked wiped and my last backup holded info from 2 weeks before.. (I was just at the beginning of setting the thing up). So now I’ll be more carefull about the security and backup, ups… I have to do one right after writing this entry (until I setup an automatic backup system).
So bottom line, my blog was not affected by the database wipe because moovable type kind of precompiles the whole stuff into html each time I update something… so notihing lost. I think I will loose some of my posts not covered by my backup with this update, but since I have a visual one… I just printed the curent page as a pdf, and with a bit of copy-paste and some date-hacking I’ll have my stuff back as before… enough with talking, let’s revive this monster.