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

Leave a Reply

Your email address will not be published. Required fields are marked *