Recent Listening on WordPress

I’ve reconnected to Last.FM to capture what I’m listening to. You can see the results on the sidebar under “Recent Listening”.

I listen to most of my music on iTunes on my Mac, and also on my iPod. Damaged has written a plugin for iTunes which takes note of my listening and sends the tracks to Last.FM, who display it on my profile. (Last.FM then do various things with the information, like display who is listening to similar music.)

Marc Hodges has written a plugin for WordPress, the software which runs this site, called WP-AudioScrobbler*; WP-Audioscrobbler communicates with Last.FM and displays my Last.FM recent tracks listing on my site. (* Part of Last.FM used to be called AudioScrobbler.)

As excellent as WP-Audioscrobbler is, there were a couple of issues I had with how it worked. Firstly it wouldn’t let me easily display my listening as a list, and secondly it occasionally delayed the loading of the page by up to a minute.

In HTML when you want to show a bulleted or numbered list, you have to start with some code which says, effectively, “start list” and finish with some code which says “end list”. I’ve added two new configuration options which allow me to specify text before and after the track listing.

The second issue was a side effect of Last.FM being overloaded, and sometimes slow to respond. My site isn’t set to check the recent listening data everytime someone visits; it’s not that important and I don’t want to pass on additional load to their servers. Instead my site checked for updates every 15 minutes, so far so good. However, if you were the first visitor in fifteen minutes my site would delay showing you the page until it had updated from Last.FM… even if this took a long time. I’ve made a further amendment to WP-Audioscrobbler whereby I can set it to check a local file for my recent listening rather than attempt to download it from Last.FM. Now I get no delay as accessing a local file is much quicker than getting one from Last.FM, next I needed to ensure that this local file was reasonably current.

I set up a scheduled job on my server which downloads a new copy of my Last.FM recent listening every 15 minutes, independently of whether someone is looking at my site or not. The command I’m using to download the file is below:
curl -sS ws.audioscrobbler.com/1.0/user/[lastfm_username]/recenttracks.xml
I’ve entered it as a cron job, see here for an explanation of setting up cron jobs; cron jobs are tasks which are scheduled to occur at certain times, every 15 minutes in this case.

You are welcome to view, or use, my amended WP-AudioScrobbler code: to use it you will need to create a directory in your /wp-content/plugins folder called “wpaudioscrobbler” and pop classes.php and wpaudioscrobbler.php into it. The original, and majority, credit for the code lies with Marc Hodges. Code now lost to the mists of time.

(Incidentally, when I first added this feature to my site a couple of years ago I think it had a positive effect on my Google rating. Certainly Google seemed to come by more often. My theory is that this was caused the frequent changes to my recent listening made the content of my homepage look frequently updated, meaning that Google checked me out more often. Just a theory.)

One thought on “Recent Listening on WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.