Displaying Recently Played Tracks on Blogs

January 8th, 2005   (303 views )

(I think this will work for any PHP blog like wordpress or b2evolution.)

So danah (via various posts) has got me really into Last.FM (and the associated Audioscrobbler plugin for iTunes). Last.Fm stores what people are actually listening to and allows you, like the original Napster did, to look at what other people are listening to.

Avast! The Audioscrobbler page for each user even publishes a feed (for example, my profile publishes this feed)!

So much am I enjoying Last.fm that I've even wrote a quick hack using magpieRSS and EdB's _magpierss.php to display the most recent tracks I've listened to on NQB's sidebar. Take a look over there to see what I'm listening to!

(I'll post my hack here tomorrow.)

UPDATE [2005-01-08 20:10]: Well, the side panel for my music wasn't updating. It turns out that you need to have a directory in the same folder as MagpieRSS for its cache (that is, it needs a place it can put stuff until the target feed has been updated). In short, you'll need to make a directory in this folder called cache with the proper permissions. The following (from the command-line) should do the trick:

mkdir cache
chmod 755 cache

UPDATE [2005-01-09 09:50]: Alright, so here are the details of this sidebar audioscrobbler plugin hack based on [EdB]'s magpieRSS hack for b2evolution.

  1. First, I listen to a lot of music... which means that I need the sidepanel to update itself more often than once an hour (the magpieRSS default). However, I also don't want to contribute to slamming the Audioscrobbler servers. MagpieRSS has a built-in cache feature which will check the time on the remote RDF/RSS/ATOM file and update the feed information only if this file is new and only after a minimum amount of time has passed (default is one hour).

    You'll have to change EdB's hack to _main.php (or your main PHP file) to redefine how often magpieRSS should check for updates to the field. Find this part of EdB's hack:

    < ?php   
    require_once( dirname(__FILE__).'/rss_fetch.inc' );
    ?>
    

    and include a line that redefines the update time. Here, I use ten minutes (600 seconds):

    < ?php   
    // define a time to check for RSS updates (in seconds)
    define('MAGPIE_CACHE_AGE', 600);
    require_once( dirname(__FILE__).'/rss_fetch.inc' );
    ?>
    
  2. Next, I did some not-so-complicated but easy-to-fuck-up modification of EdB's _magpierss.php file. So I've created a patch file _magpierss.php.patch that you can apply to EdB's original file via the following command (make sure that the patch file is in the same directory as _magpierss.php):

    patch < _magpierss.php.patch
    

    (Here are the two files (save as .php): _magpierss.php.orig.txt and _magpierss.php.new.txt) What changes did I make? Well, a few things:

    • I added a switch to not display item descriptions. For Audioscrobbler, the descriptions are the same as the titles, so this was redundant.

    • I added a switch that toggles shortening of titles. EdB had titles being shortened to 20 characters. I set this as a switch, the "unshortened" case shortens titles to 80 characters and the shortened case acts just like EdB's original. UPDATE: I actually had to increase this to two-hundred characters to accommodate long metadata for some classical music... like so:

      a screenshot of a really long classical music title

    • I moved the site title to the end. I also hard-coded in "Joe's Audioscrobbler profile" as I can't change the dumb title that Audioscrobbler defaults to ("Audioscrobbler Music Profile: Joebeone"). You'll have to change this on your own. (Now that I think about it, it would be easy to pass in a site title from _main.php. Screw it.)

Comments, Pingbacks:

Comment from: Ryan Shaw [Visitor] · http://aeshin.org/
I've been using the Now Playing plugin for iTunes to do something similar--as an added bonus, it pulls album art from Amazon, and clicking on titles takes you either to Amazon or a Google "I'm feeling lucky" search for the artist. Check it out: http://sindikk.aeshin.org/ (in the sidebar).
PermalinkPermalink 01/26/05 @ 15:27
Comment from: EdB [Visitor] · http://wonderwinds.com
Hey cool! Not the music feed - the way to make magpieRSS do the cache thing. It bugged me and I had no clue how to do that. Now if/when I need to use that hack again I'll be sure to make myself a cache folder.
PermalinkPermalink 02/14/05 @ 17:17
Comment from: Tom [Visitor] · http://www.a-rush.co.uk/8/blogs
Just found Audioscrobbler myself, and thought "wouldn't it be cool to take the RDF feed and put it in the sidebar" - searching b2evo forums for a feed-processor brought me here - where you've already done all the work for me :-)

It's on my sidebar, showing three recently played tracks now...

Thanks!
PermalinkPermalink 04/17/05 @ 13:23

Comments are closed for this post.

Previous post: Trade Secrets and the "Cherokee Nation Open Source License"? Yeah, right...Next post: EFF: EFF's Review of Elgato's EyeTV 500