Get lyrics for any song using XMPP and PHP right into your IM – Add [email protected]

XMPP is soon finding it’s way into real time applications other than just chat. I have combined JAXL (Jabber XMPP client library written in PHP) and the API from lyricsfly.com to build a real time chat bot which can assist you with lyrics for any song. You can start using it by simply adding [email protected] to your IM account (e.g. Gtalk, Jabber etc). In this blog post, I will explain in brief the working of lyricsfly bot and how you can integrate XMPP into your own application.

Try out [email protected]
Follow the following steps to get the bot working for you:

  • Login to your gtalk account using any of the IM available
  • Press Add Contact
  • Add [email protected] as your chat buddy
  • Send a chat message in following format “Song Title – Song Artist” e.g. “one – metallica”
  • You should see something like this: lyricsfly@gtalkbots.com Demo for "one-metallica"

Working of [email protected] with Jaxl
Here is in brief the working of lyricsfly bot using Jaxl client library:

  • When someone sends a message like “one – metallica” to the bot, eventMessage() method is called inside jaxl.class.php
  • eventMessage then extracts the song title and artist name from the message using PHP explode. Filter the title and artist names for allowed characters.
  • eventMessage also calls lyricsfly API and fetch the lyrics. Finally it sends the lyrics as message to requester.
  • eventMessage also uses memcached to cache the lyrics. It decreases both response time and load on lyricsfly servers
  • Bot also keeps a count of number of queries from a particular user. Since it is still under development, currently there is a limit on number of lyrics you can fetch in a single day.

Making your own custom bot

  • Checkout latest from the trunk
    sabhinav$ svn checkout http://jaxl.googlecode.com/svn/trunk/ jaxl-read-only
  • Edit config file with your bot username, password and jabber servers
  • Run from command like
    php index.php
  • To customize the bot modify eventMessage and eventPresence methods of Jaxl class inside jaxl.class.php

For a full fledged running bot example code, edit index.php and include jaxl4dzone.class.php instead of jaxl.class.php and re-run the bot.

Have fun and enjoy singing songs along with the lyrics.

18 thoughts on “Get lyrics for any song using XMPP and PHP right into your IM – Add [email protected]

    1. Yeah gtalkbots.com uses google talk server for all communication. I didn’t want to manage and spend much into server hosting, hence using talk.google.com through google apps integration.

    2. That doesn’t answer my question — is your service available on the full XMPP network or perhaps is it available only from Google Talk?

  1. This is just excellent stuff, what other development are you talking about in the post? Also is it’s code including with current jaxl trunk?

    1. Hi Jak,

      No this code is not included currently under trunk. Infact this is just a replica of jaxl4dzone.class.php, where instead of dzone api it uses lyricsfly api. And instead of flat file cache it uses memcached.

      Other development include auto lyrics support when you play music on itunes and other media players and you have your gtalk status update synchronized with the current song playing.

  2. Pingback: abcphp.com
    1. yup, tried to get the basic feature out. Rest of the enhancement will soon be added, including getting auto lyrics if you are listening to songs on itunes or winamp which automatically update ur status on song change.

  3. Hi,

    I’m interested in converting my current gtalk id to a bot (autoresponder?) when I stay offline with a status message that bot is now online not the boss 😛 or some thing like that.
    ‘ll use it for more better purposes like receiving an SMS to my mobile once I figure out the way.

    I know little php and I own a webhosting service. So, hosting it isn’t a problem 😀 Your help is appreciated 🙂


Comments are closed.