Get Song Lyrics From LYRDB With ASP.NET MVC And JQuery

26. November 2011 14:59

API ASP.NET MVC  2 Comments

Most of the times I have seen people looking for song lyrics on online MP3 or lyrics database sites. Few of them provide API to fetch lyrics which is good for developers. has a powerful API but they don't provide any API call to fetch lyrics. The two most popular APIs on the web that I am aware of is WikiLyrics, LyricsDB (popularly known as LyrDB), there is another API from ChartLyrics but I don't find it as useful as the other two APIs. The WikiLyrics API works beautifully, but it has one drawback the lyrics fetched from the service is incomplete. I wrote a complete desktop application to fetch lyrics, album art, artist image, album name and album release date but never made it available to download for public. I am planning to release it to general users. But till then you can take a look at this simple little app which I created in my spare time to fetch lyrics from LyrDB.

This little simple application is in ASP.NET MVC. I am not a designer so I will take advantage of the default design. In the home controller I have a simple method named GetLyrics which accepts two parameters Artist Name and Song Name. The method returns results in JSON as it will be good for me to parse the results in JQuery. Take a look at the code:

public ActionResult GetLyrics(string ArtistName, string SongName)
            string response = string.Empty;
            string LyrURL = string.Empty;
            string url = "" + ArtistName + "|" + SongName + "&for=match";
            WebResponse wResp = (WebRequest.Create(url) as HttpWebRequest).GetResponse();
            using (StreamReader sReader = new StreamReader(wResp.GetResponseStream()))
                response = sReader.ReadToEnd();

            if (response == "")
                response = "No Lyrics found on LyrDB for " + SongName + " by " + ArtistName;
                goto Output;

            string[] lyrID = response.Split('\\');

            response = "";

            LyrURL = "" + lyrID[0]+"&callback=?";


            return Json(new
                success = true,
                Lyrics = LyrURL
The above code does not return the lyrics but the URL to get the lyrics. I am a big Jquery fan and as usual I will be using it here to make an AJAX call and load an IFRAME with the lyrics URL.
$(document).ready(function () {
        $("#btnSearch").click(function () {
            $("#btnSearch").attr('disabled', true);
            $("#LyrFrame").attr('src', '');
            var Artist = $("#txtArtistName").val();
            var Song = $("#txtSongName").val();
            var url = "/Home/GetLyrics?ArtistName=" + Artist + "&SongName=" + Song;
                url: url,
                type: "POST",
                dataType: "json",
                data: "{'ArtistName': " + Artist + ",'SongName': " + Song + "}",
                success: function (data) {
                    $("#lyrics").html("<iframe id=\"LyrFrame\" src=\"" + data.Lyrics + "\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" vspace=\"0\" hspace=\"0\" width=\"980\" height=\"750\"></iframe>");
                    $("#btnSearch").attr('disabled', false);


The URL in the above script calls GetLyrics method which is inside Home Controller takes artist and song name as query string. On the success of the call the IFRAME gets loaded with the lyrics URL. The output will look something like this:


You can download the application source code from the below link, but I want to tell you that it will not fetch each and every song lyrics for you. It's a database and it can provide us only information it has. But the desktop application I am will release in future will check around 2 lyrics API at least and I believe that my application guarantees 100% result. So follow my upcoming posts.

Download: (886.46 kb)

Related Links:

 No Rating

Comments (2)

Eric Barb Eric Barb
11/28/2011 11:18:32 PM #

Pretty cool stuff. I just started getting into this stuff and working on getting my Last.FM feed on my page. Enjoy reading your articles!

Prashant Prashant
11/28/2011 11:37:20 PM #

Thanks Eric. I have been using Last.Fm API to get other information. It's a pretty powerful API.

Add Comment

Visit to discover Indian blogs Computers Blogs