Saturday, September 16, 2006

Hack your audio collection

DISCLAIMER: The code shown here is purely for educational purposes. The author does not suggest anyone to use this code....he himself hasn't used it. Everything that follows in the next paragraphs is a lie. This is just to demonstrate the versatility of the Perl language. Music piracy is a heinous crime and I urge everyone to pay for all the songs you download. All stunts performed here are done by professionals, please don't try them at home.

Well since this is the first time I am using red fonts on my blog, you would have guessed that I am up to something nasty(keep the disclaimer in mind). Coming right down to business, I wrote a Perl script( with a little BASH littered around) that downloads all the songs of any bollywood movie, fix their weird names and put them nicely in a directory. Also since the id3 tags are intact, they are perfectly well suited to be played from an mp3 player as well as from your computer.

Here's the script. Currently it runs only Linux and needs mp3info and LWP module for Perl installed (which.. if you use Ubuntu/Debian is just an apt-get away). Since they both are there on windoze too, readers are encouraged to go ahead and try it on Windows. Basically what it does is, it just goes to a free mp3 site and downloads all the songs. Later it reads the songs' title on the id3 tag and renames them.
E.g $./ fanaa
this would create a directory called fanaa and download all the songs from the movie fanaa in that folder. I downloaded 1 GB of bollywood songs yesterday...

I would specifically like to draw your attention to three lines of code that can create wonders

$realname=`mp3info -p\"\%t\" \"$filename\"`;
$realname=~ tr/" "/_/;
Now simply putting it, this tiny perl script reads the mp3 title from the ID3 tag of the song. The second line replaces spaces with underscores and the last line renames the file. Imagine having gigabytes of songs with stupid names that your friend though were funny.. now you can name them automatically. You can be as creative as you like.. I had a friend who dumped all his music collection in one folder and soon had an unmanageable mammoth collection of songs, I just modified this script a bit which auto-organized the songs into folders named after the album(again from ID3 tags). Dont you love Perl and Linux after this??


No comments:

Post a Comment