Simple Downloader!

I come across this very nice site http://www.dwarkadheeshvastu.com/ which has a collection of excellent MP3s (Devotional Music). I congratulate the maintainer of that site for the excellent collection of texts/mp3s in multiple languages. So the site is more or less static with mp3s arranged inside folders starting from 000.mp3 to the .mp3. And you want to download them all.

Layman way is to keep right clicking on each link and do save as. But we are lazy programmers. We will just give our job to the computer to increment the URL and download the file for us. This can very simply be done in a bash script. Below is a snippet. I will not go into explaining all the details, just that the script takes in 3 parameters (start of the count, end of count and the absolute URL of the folder). Run the script and get all the mp3s that you need. One can extend the script to pass in the kind of file we are interested in (like mp3, pdf, etc.). But that is left as a user exercise. The folder path can be got by looking at the HTML code (in case you are wondering how I got it).

Example invocation to get the whole of Ram-Charit-Manas in Avdhi language:

./getRamayan.sh 0 195 http://parthtechsolutions.com/001-MData/Ram-Charit-Manas-Avdhi

Enjoy the code below. PS: Of course it is bash and it runs on Linux. Create a windows batch file and post it in comments.

 #!/bin/bash

i=$1
while [ $i -lt $2 ];
 do
 if [ $i -gt 99 ]; then
   wget -O "$i.mp3" "$3/$i.mp3"
 elif [ $i -lt 10 ]; then
   wget -O "00$i.mp3" "$3/00$i.mp3"
 elif [ $i -gt 9 ]; then
   wget -O "0$i.mp3" "$3/0$i.mp3"
 fi
 ((i+=1))
done

echo "Enjoy!"