Hindi songs online

Click here to search for Hindi songs.
This is an article on how I wrote the search engine.

I find it a nuisance to have to go to Raaga, search for a song, not find it, then go to MusicIndiaOnline, not find it, then go to Musicplug.in, and so on until Google.

So I got the list of songs from some of these sites, put it together in one place, and implemented a find-as-you-type.

Just go to s-anand.net/hindi and type a song or movie name.

Update: How I created this is a very long story, spanning over two years. And here it is.


Over the last 5 years, my MP3 collection had grown quite large. Most of these were from MP3 CDs I had bought, songs I’d downloaded, or songs I’d recorded. In any case, the file names were a mess. In early 2005, I decided to organise the collection and put them all into one big directory per language, and name the files in the format “Movie.Song.mp3″.

People think I’m crazy to use a single large directory. But I prefer one directory with 5,000 files to 1000 directories with 5 files for a simple reason. Searching in one directory is easier than in multiple directories. You can just sort everything by name, date modified, size, whatever. On the command prompt, you can type “DIR dil*.txt” to see all movies starting with “Dil”.

I chose the “Movie.Song.mp3″ format because the movie name and the song name were really the only two things I knew about every song I had. I didn’t always know the music director, singers or year of the movie. And I placed “Movie” before “Song” because I often browse songs within a single movie, and it’s useful to sort by name in Windows Explorer and see all the songs in a movie. I’ve never had a need to sort by song name. If I wanted to find a song that started with, say, “pehla”, I’d just type “DIR *pehla*” on the Command Prompt. (As you might have guessed, I have a Command Prompt window always open.)

So, having very rationally organised my music collection, I was happy.

Soon the problem shifted to song discovery. I’d heard the familiar songs in my collection many times. Of the unfamiliar songs, but I didn’t know which to pick. I knew I liked some music directors more than others, and had a hunch I liked older songs. (My subsequent analysis of song preferences confirmed this.) But I didn’t know the year or music director for any of my songs.

Since Raaga had a decent collection of songs, along with the year and music director, I decided to download this information and tag my files with this information. There were two problems. Firstly, the data in Raaga needs to be parsed. I need to hunt through each file to find the year and music director. The second was worse: my song names were spelt differently from Raaga’s.

Step 1: download the HTML and parse it. Perl is pretty much the only programming language I know. I used Perl’s LWP library to download the movie index of Raaga. Each movie in the index always has the URL http://www.raaga.com/channels/hindi/movie/something.html. So I extracted these patterns and downloaded all these URLs as well. (Others have a recognisable pattern as well: http://www.musicindiaonline.com/music/hindi_bollywood/s/movie.some_number/, http://www.musicplug.in/songs.php?movieid=some_number, http://ww.smashits.com/music/hindi_film/songs/some_number, etc.)

You probably realise that I downloaded a fair bit of the entire Raaga.com site’s HTML. Actually, it’s not that big. The 800-odd files in the Hindi collection didn’t take more than 40MB of space, and a few hours to download. Here’s what the code looks like:

# Get the list of movies HTML file
my $index = get("http://www.raaga.com/channels/hindi/movies.asp");

# Extract the list of movies from that into a hash (movie, url pairs)
my %movie = ($index =~ m|<a href="/channels/hindi/movie/([^"]*).html" class="[^"]*">([^>]*)</a>|gsi);
 
# Loop through each movie
for my $file (keys %movie) {
  # Get the song HTML file
  my $html = get("http://www.raaga.com/channels/hindi/movie/$file.html");
 
  # Year is typically like this: Movie_Name (1983)
  my $year = ($html =~ m|<b>$movie{$file}\s+\((\d*)\)</b>|) ? $1 : "";
 
  # Music director always has the URL /channels/hindi/music/something
  my $md = ($html =~ m|<a href="http://www.raaga.com/channels/hindi/music/[^"]*" class="black">(.*?)</a>|) ? $1 : "";
  for (split /\n/, $html) {
 
    # Now get individual songs and rating. They always have an onClick="setList(something)"
    if (m|onClick="setList1\((\d*)\)[^>]*>(.*?)<\/a>.*?"http://images.raaga.com/.*?.gif" alt="RATING: ([\d\.]*)"|) {
    $song = $2;
    $rating = $3;
    print join("\t", $movie, $song, $year, $md, $rating), "\n";
  }
}

Incidentally, I’m showing you a simplifed version. I actually wrote the script in a way that I could resume where I left off. The ability to resume was probably the single most useful time-saver in the entire process.

Step 2: match the song names with those on my list. This is tricky. I hate doing it manually. So I developed a set of rules that could compare two spellings of a movie and decide if they were the same or not (see my earlier post on matching misspelt movie names). For Hindi songs and movies, here are my rules (in JavaScript):

w=w.toUpperCase();                      // Convert to upper case
w=w.replace(/\s+/, " ");                // All whitespaces = 1 space
w=w+" ";                                // Ensure there's a space after every word
w=w.replace(/W/g, "V");                 // V=W
w=w.replace(/Z/g, "J");                 // Z=J
w=w.replace(/PH/g, "F");                // PH=F
w=w.replace(/([KGCJTDPBS])H/g, "$1");   // Ignore H after most consonants
w=w.replace(/(.)\1/g, "$1");            // Ignore repeated letters
w=w.replace(/Y/g, "");                  // Ignore Y
w=w.replace(/([AEIOU])N /g, "$1");      // Ignore trailing N after vowel (hein, mein)
w=w.replace(/[AEIOU]/g, "");            // Ignore vowels
w=w.replace(/ /g, "");                  // Ignore spaces

These are the rules, incidentally, that I use in my Hindi quizzes. Even if you type in a different spelling, the rules above will match the correct answer.

I extended these programs over 2006 to cover MusicIndiaOnline, Musicplug.in and Smashits. (I’ve hit a point of diminishing returns, I think, so I’m not too keen on expanding this list.)

Now, with a database of song information, I needed a good media player to view this in. I’ve used several media players over time: WinAmp, Windows Media Player, RealPlayer, iTunes, and MediaMonkey. I’m a big WinAmp fan, but I’ve been forced to Media Monkey now. WinAmp has a 10 second delay before playing any song on my new laptop. MediaMonkey’s not bad, though. The lack of advanced filters is countered by the heavy programmability (I can use Javascript to update MP3 ID3 tags on MediaMonkey). Plus, I get all the WinAmp plugins. As for the other media players, I think they’re junk.

There are five things I want in a perfect media player:

  1. Find as I type. I shouldn’t have to type the entire song, or press a “Go” button. I’ll just type. It should show all matches instantly. WinAmp does this, and that’s why I loved it. (Today, most media players can do this.)
  2. Advanced filters. Instead of manually creating playlists, I’d rather create filters, like “Highly rated songs in the 2000s I haven’t heard recently”. (See How I listen to music.)
  3. Enqueable playlists. When I click on a song, I don’t want my current song to be interrupted. Just play it next.
  4. Global hotkeys. I want to pause the song when someone says something — without having to go to the application, search for the pause button, etc. WinAmp does this brilliantly with its global hotkeys.
  5. Online and offline integration. I want to be able to search online collections, like Raaga. Unfortunately none of the media players can do this. They have their own collections (radio stations, really), but even these aren’t really searchable.

Since my favourite media players (WinAmp and MediaMonkey) lack only one of these features, I thought I might be able to build them in.

But no such luck. It was almost easier to build my own media player. So I started to build my two weeks ago. My hope was to cover as many of my favourite requirements, beginning with find as you type.

The key to find-as-you-type is speed. You can’t afford many calls back and forth between the browser and the server. Even if people have a fast connection, my server is not fast enough. (A good part of the reason why I use Google applications is speed. Google’s server is blazingly fast, and the design of their applications complements that.) To make find-as-you-type fast, ideally the entire database should be loaded. Then, as you type, I just need to check with the database in memory. But downloading an entire database takes ages! (My full music database is 7MB right now.)

Step 3: compress the database. Rathern than load the full 4MB, I managed to get the page to start after loading 100KB of data. First, I cut down less important fields. Most searches are for a song or movie, rarely for a year or music director. So I took only the movie and song names. That brought the data down to ~2MB.

I don’t need to repeat the movie name across songs. If I have something like this:

Movie1  Song1
Movie1  Song2
Movie1  Song3
Movie2  Song1
Movie2  Song2

I can store this instead as:

Movie1  Song1   Song2   Song3
Movie2  Song1   Song2

I can also eliminate duplicate names. This brings down the space requirements to ~500KB.

The next step was the clever one. I don’t need to load the full database before you start searching! It’s enough to load a reasonable subset, and let you start searching while the rest loads in the background. So my hindi song search engine loads about 100KB of the data from one Javascript file, lets you search, and in the background loads the 400KB Javascript file. As soon as that finishes loading, it displays results from that set as well. (The initial portion is really songs on Raaga. I figured it would represent a decent search set.)

Step 4: find-as-you-type. This is quite easy, actually. I send the onkeyup event to my search function.

<input id="inp" onkeyup="csearch()">

The csearch() function goes through all the songs, checks if there’s a match, and prints all those results.

// Create a case-insensitive regular expression
var re = new RegExp(search, "i");
for (var i in songs) {
  if (re.test(songs[i)) { str += songs[i]; }
}
library.innerHTML = str;

But that, unfortunately, takes ages to finish. If you implemented this as is, you would have to wait 1 – 1.5 seconds between each key stroke. So I made two modifications. Firstly, I restrict the number of results displayed to 100. When you start typing, (for example, you’d go ‘c’… ‘ch’… ‘chu’…) there are several songs early on that match the string, so I don’t have to search through the whole list. This speeds up the search for small strings.

When the search gets bigger, (‘chupke chu’… ‘chupke chupk’…), there aren’t 100 results. So the search has to cover the full list, and that takes 1-1.5 seconds between each keystroke. So I took another clever step. I broke the search into chunks of 5000 songs. That takes a fraction of a second. I search successive chunks of 5000 songs. If I find any results, I add them. Then I wait for a keystroke. If nothing happens, I continue searching the next 5000 after 50 milliseconds, and so on. If you press a key in the meantime, I stop searching for the original word, and start searching for the new word. This makes the application appear a lot faster.

There are ways I could make this even faster. For example, people type more often than delete. A typical sequence would be (‘chupke ch’… ‘chupke chu’… ‘chupke chupk’…) rather than the reverse. Backspace is not pressed very often. So, instead of re-searching the whole list, I could just search the already-searched list in such cases. But right now, the search works fast enough, so I’ll leave it at that.

The next step is advanced filters. I’m working on that right now. Hopefully you’ll see in a while.

  1. sundar says:

    Anand, not sure if this is already on cards. It would be great if you can add more Carnatic/Tamizh isai songs to the database

  2. Raja.S says:

    Hey Anand, Excellent man.. I got rare songs I was looking for a long time. Thanks a ton. Love Raja

  3. Sanketh says:

    Man, your search algo is pretty decent too. Was just searching for ‘elangaathu’ and typed it as elankaa.. and it still showed the right song.

  4. S Anand says:

    Sundar, Carnatic music search is already live at s-anand.net/carnatic and I’m planning to add to the (currently somewhat sparse) collection.

  5. Kalpesh says:

    I really liked the site & idea. I am not sure that I am being naive, is it possible for me to select multiple songs & play them one by one?

  6. Smitha says:

    Excellent site very cool.

  7. S Anand says:

    Kalpesh, playing multiple songs is not possible right now. I’m trying. It’s difficult, though. Don’t know if I’ll be able to do it. Will keep trying.

  8. மதி says:

    அண்ணன் என்னடா தம்பி என்னடா…. பாடலைக் கேட்டேன் இதனை எப்படி தரவிறக்கம் செய்து கேட்பது எனத் தெரியவில்லை, அருமையான பாடலைத் தந்தமைக்கு மிக்க நன்றி

  9. S Anand says:

    Mathy, search for “Annan Ennada” at s-anand.net/tamilmp3

  10. Krishnamurthy says:

    you worked very very hard make such a search tool, its really amazing keep well , keep doing good work

  11. Sundar says:

    Anand, it would be great if we can have some site preferred over others (something like appearing on Top). Because as I observed oosai & Music-Plugin has got good sound quality over others. I also found my favorite carnatic songs in the carnatic page. Thanks again!!

  12. Chirag Mehta says:

    Hey Anand , Really Good Site I liked it What was ur idea behind this Site development is the same which i was facing. Thanx for a ready made solution for me Added Link to ur Site as a post on my site http://www.chiragmehta.info/chirag/2007/03/21/hindi-songs-online-search-engine/

  13. S Anand says:

    Sundar, how about this order: MusicPlug.in > Oosai > Musicindiaonline > Raaga > Smashits?

  14. Shekhar says:

    Good site. I am searching for koyil pura film song ‘vedam nee’ n surfed the whole net without success. Please help

  15. S Anand says:

    Shekhar, search for “koyil pura” on s-anand.net/tamilmp3 and you’ll find Vedham nee

  16. Shekhar says:

    Thanks Anand. I tried for almost an hour but could not able to download the song as it always says the network is busy

  17. S Anand says:

    Shekhar, I’m having some trouble at cooltoad as well. Usually, I wait a day and it’s fine.

  18. Shekhar says:

    Tried whole day but without luck. Any other option.

  19. Aqua says:

    aWesoME TOOL.

  20. sundar says:

    Anand, Thanks for considering my request. That order would be great.

  21. Varun says:

    Hi! Awesome search…just like Winamp…lot of effort put..good going!!

  22. shilpa says:

    hi! Congrats…. amazing search. Could you add other regional songs to the list??

  23. பாலச்சந்தர் முருகானந்தம் says:

    நல்ல கருவி

  24. Prasun says:

    I came here searching for music. Your tool is awesome. It would be nice if this were extended to playlist creation etc – I think it would probably be not very hard if all songs are from a single site. Oh, and I spent a couple of hours in your writings section!

  25. Varun says:

    Great tool anand!

  26. Seshan says:

    Anand, just happened to visit this page. Awesome. Couple of songs that I found it difficult to get were made so easy with your tool. (Sorgame endralum, solladi bharatha maatha to name a couple). Great work.

  27. Seshan says:

    Anand – For carnatic songs, can’t the search be made on ‘ragam’. It would be cool to have it. Just a suggestion.

  28. Roopa says:

    Hi!!…Superb job! Good going..

  29. Anonymous says:

    hai friends.. its not working

  30. Shekhar says:

    After continuous effort I managed to download koyil pura songs. Many thanks Anand for making my day. Keep up the great job

  31. Vishal says:

    Anand ,I have forgotten all other hindi song websites now.

  32. Venkat says:

    Good keep it up I advocate open source can u think of simple tools for day to day money management and account management with banks

  33. Kannan says:

    First of all good work !!! I keep referring to this whenever I have to get some movie names for songs. I personally have a 17Gig songs collection, I would like to know if you have encountered an API to change properties of a mp3 file like title, album title etc. programmatically (preferably in Java or Groovy or Ruby or Perl) ???

  34. abbas says:

    good job man,thanks alot.

  35. Anu says:

    Hi Anand…this is really a great job…i need a help…i find that tamil and hindi songs are available at your site for download…Can you please help me out with the carnatic songs too….for now it would be great if i have ‘Sachmara ramavani’ atleast….i have been trying to get this song for such a long time…thanks so much for the great work!

  36. Viju says:

    Interesting work. Is there a similar serach tool for carnatic/hindi radio? There is a similar search site for lyrics…at lyricsdir.com.

  37. ramkrishna says:

    hindi song

  38. ramkrishna says:

    Kachche Dhaage’s songs

  39. Kavitha says:

    That was a wonderful tool Anand. I found it very useful… :)

  40. Pradeep says:

    hello bro awesome work da. can u pls find me a song from Prem Qaidi – I live for u.

  41. jagannath says:

    awesome job, Anand could you also upload kannada. Will You

  42. Nainesh says:

    Superb, and fast i like the idea, Keep it up, i found it useful.

  43. sameer jain says:

    awesome anand but can please help me in finding one song from maine pyaar kiya ..its aate jaate i am not able to hear it ..please help .. but one thing is for sure ..u really did a gr8 job ..get this gud work going all the way up ..all the best

  44. Anonymous says:

    awesome job…..

  45. Manikandan says:

    I guess there are some issues. Webpage is loaded with errors. Also, Why cant we have Punnagai Mannan Theme Music?

  46. animesh says:

    Hey Anand….u are genius…great idea…nicely implemented…..all of us (i.e. people like me) are greatful to u for making this tool and letting us use it…..one idea (if u have some free time) that u can try ….let users create a playlist using ur site….

  47. Hemant B. says:

    Thanks Annand you have created very useful site for music lovers. wish you best luck for your new creation.

  48. jitendrasharma says:

    jitu

  49. thuva says:

    wow nice and great i will give you 90% for this website tthat tamil sitet downloading for free i love it and your the best fro my life ok then take care and good luck best of luck and great and great good site and 90% rating

  50. your name says:

    awesome collection!!