Get lyrics for any song using XMPP and PHP right into your IM – Add

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 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: 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 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.


  1. Pingback: Get lyrics for any song using XMPP and PHP right into your IM … | Coder Online

    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:

  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.