Leave a comment


 

Michael said on April 8th, 2009 at 11:15 pm :

Hey Leo,

Where’s the download link for the Lyrics Retriever?

Thanks!
–Michael

 

Cesar said on April 25th, 2009 at 2:00 pm :

i can’t see it too

Jun 26, 2008 | AJAX Lyrics Retriever

Lyrics Retriever v1.0

I am happy to announce the release of Lyrics Retriever 1.1 (beta, still), a free AJAX script that allows you to retrieve lyrics based on a particular artist, title, or both.

See it in action here.

It is now offered as a commercial release.

Cogwheel How it works: Getting the results

The current implementation is just one of many that can be done, precisely because what I am doing is parsing XML data from Leo's Lyrics, which is one of the few databases that provides an API. For example, if you're looking for a song by the Red Hot Chili Peppers, visiting the page

http://api.leoslyrics.com/api_search.php?auth=duane&artist=Red%20Hot%20Chili%20Peppers

gives you all the titles it finds. Alternatively, if you have the title as well, you can add an extra "songtitle" portion to obtain

http://api.leoslyrics.com/api_search.php?auth=duane&artist=Red%20Hot%20Chili%20Peppers&songtitle=Otherside

which gives you just the one song. Now the key to retrieving the lyrics lies in the hid which you'll see as part of the <result> tag. A simple XML parser would not return a particular "id", so I resorted to using xml2array, which returns an array containing all the data in the XML file. For you developer's its key to note that

For the title of the song
$result[leoslyrics][searchResults][result][$x][title][value]

Is it an exact match?
$result[leoslyrics][searchResults][result][$x][attr][exactMatch]

For the artist's name
$result[leoslyrics][searchResults][result][$x][artist][name][value]

Now also it is necessary to note that if it is an exact match, $result[leoslyrics][searchResults][result] does not have multiple entries, and so a count of its contents will actually return 4: that is, title, feat (which apparently serves no purpose), artist and name.

Cogwheel How it works: Getting the lyrics

Similarly to above, the query

http://api.leoslyrics.com/api_lyrics.php?auth=duane&hid=VxwOBYpM3iY=

will return all the data relevant to a particular song, including an album logo and the entire text of the lyrics.

Specific functions of each file

  1. index.php - main index file. Contains AJAX wrapper that displays results.
  2. array.php - lists results from search and allows for querying particular lyrics. Can also be expanded to include lyrics already in results and displaying it dynamically, or using another AJAX call to make things cooler.
  3. getlyrics.php - twin of array.php, but has $hid as an input.

A heartfelt thank you to the folks at Leo's Lyrics, and I hope you enjoy this script.

This entry was posted on Thursday, June 26th, 2008 at 11:45 pm, EST under the category of Coding. You can leave a response, or trackback from your own site.