Just like starting over

Over the years, I have started a couple of last.fm projects. All have one thing in common: they provide a way to display covers on your site, and do it more elegantly than the standard last.fm widget. One of the things that really bugged me about my projects was the different pieces of code I maintain; and how difficult it becomes to support all these variants.

As we’re approaching the new year, here is my resolution: one codebase for all, starting today with a basic object that can be used as-is, or with some additional programming, for platforms as WordPress and Drupal. This also means that my WordPress plugins will be built on this code once it gets out of beta (hey, even Chrome did!).

In case you’re wondering: yes, the covers on the top right of this page are there thanks to this new code. And no, it’s not a WordPress plugin or widget yet, I wrote it directly in themes/sidebar.php

I’m releasing this code under GPL, so it is available to use in your own projects. If you do, I ask you to

  1. keep my info in the javascript file
  2. change the last.fm API key
  3. let me know where you are going with it

Once installed, the javascript hands you one object you can configure and run, like this:

jQuery(document).ready( function() {
 
  // last.fm username
  lastFmRecords.setUser('hondjevandirkie');
  // id of the div element where script can add covers
  lastFmRecords.setPlaceholder('lastfmrecords');
  // image to show while loading images or when image not found
  lastFmRecords.setDefaultThumb('./lastfm_logo.jpg');
  // TODO: value is ignored at the moment
  lastFmRecords.setPeriod('smart');
  // TODO: value is ignored at the moment
  lastFmRecords.setStyle('lightbox');
  // number of covers, at the moment max. 50
  lastFmRecords.setCount(20);
  // refresh interval (get fresh data from last.fm)
  lastFmRecords.setRefreshMinutes(1);
  // GMT offset
  lastFmRecords.setTimeOffset(1);
  // log to console
  lastFmRecords.debug();
 
  // run
  lastFmRecords.init();
});

Most options come from my earlier projects; the refresh is new. And best of all, I found out how to get JSON from last.fm. This means jQuery can make the requests, so all requests now go directly from the browser to last.fm, without a data provider in PHP on your own server.

So what do you need to get this running?

  • include jQuery
  • include last.fm.records.js
    (see download link below)
  • a last.fm username (you’re free to use mine when you like Randy Newman)
  • a div on the page where the script can put the HTML in
    (default: <div id=”lastfmrecords” />)

You can download the beta of Last.Fm Records 3.1 here.
UPDATE: see this page for the javascript file. It’s in the WordPress package, but can be used alone.

This entry was posted in coding. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted January 1, 2009 at 7:31 pm | Permalink

    Great jQuery tool! I’ve been slowly hacking pieces of it into my blog, and this is something that I’ve been looking for for a while.

    However, I cannot get it to play well with jQuery tweet and jQuery Flickr on the same page. This is the error I get from Firebug:

    Console is undefined:
    if (‘function’ != typeof console.log || !_debug) {

    Any ideas?

  2. Posted January 1, 2009 at 8:16 pm | Permalink

    Hi Dan — I have. You’re still on version 3.0.

  3. Kyle U
    Posted May 9, 2009 at 12:57 am | Permalink

    Great tool!
    I was wondering if you could have the album art for most recently listened to ALBUMS as opposed to tracks. Because if I listen to a whole CD with 10 tracks, the first 10 spots will all the be the same image. Any insight?
    Thanks!

  4. Kyle U
    Posted May 9, 2009 at 1:41 am | Permalink

    I see that Run for Cover does what I’m asking, but I’m not using WordPress, and I can’t get the PHP last.fm records to work…
    anyway to modify this jQuery version?

  5. Steve
    Posted May 27, 2009 at 1:27 am | Permalink

    Excellent work. Is there a way to display more than one category for the same user. For example display the recent tracks and loved tracks on the same page? I can get it to display either or but not both on the same page. Any ideas or suggestions would be greatly appreciated. Thanks. :-)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

  • recent beluisterd