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.

  • Pingback: Get lyrics for any song using XMPP and PHP right into your IM … | Coder Online()

  • Cool idea, but when I try to contact gtalkbots.com over XMPP, I get “remote server not found”.

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

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

    • Alright, in that case its only for those services that can talk with jid’s on gtalk servers. For e.g. i guess AIM users can.

    • Probably, if i find time will move to a self hosted jabber server keeping in mind that other xmpp network are currently cut off from all gtalkbots apps

    • Aha, I discovered that I can add [email protected] to my buddy list on gmail.com but not my buddy list on jabber.org. Perhaps there is a server-to-server issue. I’ll try from a third server, too…

    • Yeah right, i guess they allow s2s with AIM since i can see notifications on gtalk to add aim users.

  • jak

    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?

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

  • Pingback: abcphp.com()

  • Varun

    Cool Stuff Bhaiya!!!!

  • arre kahin se list dekhne ka option bhi hona chahiye… laid to rest nahi mila

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

  • 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 🙂

    Thanks

  • i love this song and i love you put it on here

  • brandon beauchamp

    I LOVE METALLICA, ITS IN MY TOP 3 FAVOURITE IN THE WORLD!!!

  • Announcing Jaxl v3.x – asynchronous, non-blocking I/O, event based PHP client/server library – http://abhinavsingh.com/blog/2012/07/announcing-jaxl-v3-x-asynchronous-non-blocking-io-event-based-php-clientserver-library/