New JSON Feed for Recent Tracks

We just added a JSON formatted feed for recent tracks to make manipulation with JavaScript easier. The JSON feeds work lust like the recent tracks feeds:

Full feed: http://zenradar.roblogic.net/service/1.0/user/[username]/recenttracks.json
Specify number of results (1-10): http://zenradar.roblogic.net/service/1.0/user/[username]/recenttracks_[1-10].json

Here's the easy way to cache the feed on your site. Run this script from cron on a regular basis, then pull the cached file in your JavaScript to keep things snappy.
<?php
//from marc2003's script on last.fm forum
$user 'roblogic'//last.fm username

$remotefile "http://zenradar.roblogic.net/service/1.0/user/$user/
recenttracks.json"
;
$localfile $user.'.json';

try
{    
    
$ch curl_init($remotefile);
    
$fp fopen($localfile"w");
    
    
curl_setopt($chCURLOPT_FILE$fp);
    
curl_setopt($chCURLOPT_HEADER0);
    
    
curl_exec($ch);
    
curl_close($ch);
    
fclose($fp);

}
catch (
Exception $e)
{
    echo 
$e->getMessage();
    echo 
'<pre>';
    echo 
$e->getTraceAsString();
    echo 
'</pre>';
}

Displaying Recent Tracks with PHP4

We've been using a modified version of marc2003's recent tracks script as an example of how to display your recent tracks feed. It's simple, elegant and just works. However, it requires PHP5 due to it's dependance on SimpleXML.

If you are limited to PHP4, click here to download a version that does not rely on SimpleXML. Be sure to change the file extension from .txt to .php.

Artist images in recent tracks feed

Someone on the last.fm forums was asking about artist images for recently scrobbled tracks, so I though I'd look into adding them to our recent tracks feed.

Unfortunately, that artist info is really hard to get to on-demand. There's no info feed for artists, so even though you can get Similar Artists, Top Fans, Top Tracks, Top Albums, Top Tags, and Current Events, you can't get a simple artist detail. However, if you pull the similar artists feed, pick the first artist in the list, then pull that artist's similar artists feed, you can spin through those artists and find the target artist. This method does work, but does not seem to generate matches for all artists, so there are some blanks here and there. I've got a cron job running to update all of the artists that are already cached in our DB (around 1100) with the image data, it should be done by this time tomorrow. Any artists not already in our DB will have their image data saved as they come in on the last.fm recent tracks feeds.

ZenRadar recent tracks feeds now have small and large artist images in the artist nodes, like this:

<artist mbid="">
    Sound Tribe Sector 9
    <url>http://www.last.fm/music/Sound+Tribe+Sector+9</url>
    <image_small>http://userserve-ak.last.fm/serve/50/86460.jpg</image_small>
    <image_large>http://userserve-ak.last.fm/serve/160/86460.jpg</image_large>
</artist>

Which will give you:




Artists that we haven't found images for will have the last.fm default "no artist" images:


http://cdn.last.fm/depth/catalogue/noimage/noartist_50px.jpg


http://cdn.last.fm/depth/catalogue/noimage/noartist_140px.jpg

I hope this is useful, let me know if you have any questions, or if you'd like artist images added to any of the other feeds.

Timeout Errors Fixed

Since moving to our new server a couple of weeks ago, we've been experiencing some timeout problems on operations that pull a lot of feeds from last.fm. This was causing ugly 500 errors while pulling feeds or loading the dashboard. This afternoon I tracked the problem to mod_fcgid's ridiculously low default timeout params and fixed it.

Sorry for the inconvenience!

Zen Radar on build.last.fm

Zen Radar on build.last.fm

"Last.fm feeds on crack. All the enhancements you ever wanted."

ZR has been added to build.last.fm. We're proud to be a part of the growing last.fm developer community.

If you're new here, take a moment to read about what this thing is and find out how to use it. If you have questions, check the FAQ, or feel free to contact us. If you're ready to get a closer look, create an account and dive right in.




Thirdparty Labs
tpl skunkworks

last scrobbled track


user login

username


password


newest users



RSS