David Singleton
Last.fm Now-Playing information radiator

This is a litte project I started a while back but only finished/cleaned up recently. It’s a simple information radiator that shows you what a Last.fm user is listening to right now.

Now playing screen

It was designed to let one (or many people) know what’s playing at a glance. I’ve been using it while listening to Last.fm radio while getting ready for work, shared office playback (it works really well here) and even on top of Spotify playlists at parties. You can stalk along to someone else’s listening too, for the curious.

Dev/ops have made heavy use of radiators/glanceables for a while (that’s a whole ‘nothing post), but it’s nice to see more social and experimental uses being applied. With “second screens” getting more popular I’m excited to see what else will get made soon.

Try the hosted demo version or fork the project on Github.

Responsiveness

DSCF0009

It’s not strictly a responsive-design (no media queries in sight) but it does work really well across multiple devices. Only needing some font size adjustments on larger screens. Matthew Sheret has been running this on an old iPod touch sat on his desk for a few weeks, quite happily.

How it works

There’s no server-side requirement, everything is HTML/CSS/JS, no PHP or Python dependency, which means it’s super easy to use locally. You can clone it from Github and use it immediately, no configuration. It includes a tiny Last.fm API client written in Javascript

Now-playing is part Last.fm scrobbling API, supported by most clients it’s sent at the begining of a track rather than at the end (like scrobbling). Becuase there’s no realtime API i’m polling on a with a tiny Javascript API client. By default it polls on a 5 second interval, which feels pretty snappy and sit well within the TOS (~1 req/sec max).

Checkout the source, on Github and have a play.

Giving XFN more visibility through CSS2.1 Attribute Selectors

As I was redesigning a bit lately and making use of FamFamFam’s very nice Silk icon set (used under the CC Attribution License) and it occurred to me I could use CSS2.1 Attribute Selectors to show the relationships the XFN defines.

If you’re not familiar with XFN this wikipedia article gives a good introduction.

In the WordPress blogroll you get the option to add XFN relationships to the people/links, as I’ve been on a bit of a microformats kick i’ve been thinking how I can make better use

The XHTML

<ul>
<li><a rel="friend met neighbor" xhref="http://www.simoncoltman.net/">Simon Coltman</a></li>
<li><a rel="friend met" xhref="http://fberriman.com/">Frances Berriman</a></li>
<li><a rel="acquaintance" xhref="http://moglenstar.net/">Max Glenister</a></li>
<li><a rel="friend met co-worker" xhref="http://www.ricardocabello.com">Ricardo Cabello</a></li>
<li><a rel="friend met" xhref="http://www.krisswatt.co.uk">Kriss Watt</a></li>
</ul>

The CSS

ul.xfn_example a {
background-image: url(/images/icons/user_gray.gif);
}

ul.xfn_example a[rel*="acquaintance“] {
background-image: url(/images/icons/user_blue.gif);
}

ul.xfn_example a[rel*="friend“] {
background-image: url(/images/icons/user_green.gif);
}

ul.xfn_example a[rel*="co-worker“] {
background-image: url(/images/icons/user_suit.gif);
}

Browser Difficulties

Attribute selectors are not supported in IE6 so the first rule sets the background all links, if the other more complicated rules aren’t understood then the icon stays a default grey. For the browser that do understand the more complex rules, assigning icons for some of the different relationship types.

They’re ordered so that, for example co-worker will override friend, should the XFN define both of these relationships. I’ve not done it here but if you wanted to you could chain the selectors and create a specific rule (and image) for someone who is a friend and a co-worker a[rel*="friend“][rel*="co-worker“]

With the announcement that IE7 will be supporting, amongst other things, attribute selectors I can imagine them being used a lot more as IE7 adoption increases and progressive enhancements like this becoming more common.

Design Flaws

The different icons don’t do a great job of communicating the different relationships, but maybe more specific icons would help, or on a larger list maybe a key might help?

Conclusions

This isn’t a particularly complicated idea but i’ve had a couple of people ask me about it, so I thought I’d give a brief explanation and maybe encourage people to take the idea further and make something cooler.

Fun with FAMFAMFAM Icons and jQuery

If you not familiar with the FAMFAMFAM Silk icons they’re a set of 1000 beautiful little 16×16px icons that you’re free to use under the CC-Attribution license.

I’ve been using them a little recently for a few things, including this blog and some coding projects. The problem is, with 1000 icons, finding the ones that are suitable for what you’re doing.

The Silk webpage used to have every icon on the page, with a little search box to only show ones matching your search. This was great, you could filter down to the more relevant ones, while still comparing them on the same page.

Unfortunately this seems to have gone now, so I thought I’d put together a version of it myself, mostly to make it easier to find icons, but also as an excuse to play around with jQuery.

jQuery is one of the huge variety of Javascript libraries around at the moment. It’s got very powerful selectors, cross browser events and animation and is built around the idea of chaining. I’ve used it a little recently at work and it has made Javascript fun.

The Icon Selector

In half an hour or so I knocked together a quick demo of (as i’ve now dubbed it) the Icon Selector. I’m pretty happy with how it turned out, it’s easy to search for and preview the icons you want.

I’ve made a few tweaks since to speed it up a little, you can take a peak at the Javascript source if you want to see the jQuery magic, it’s pretty cool.

Most impressively it works well on all modern browsers. jQuery handles a lot of the inherent differences in the DOM and event models. Conclusions? jQuery is very nice, definately something i’ll be using more in the future.

A last.fm tag-cloud generated from XSL

19/07/2009: The script in this post is currently broken, it’ll be fixed soon

If you use last.fm the you can get some pretty interesting statistical data about your musical habits.

Being a web and music geek I’ve put together a simple tag-cloud to show what i’ve listened to that week. Everyone loves a nice tag-cloud.

You can take a look at the finished version on my Music page.

How it was made

I’ve had a rough version of this for a while, but it had quite a few issues, was generally a little broken and not very semantic. So I took a few hours to re-write it and make then make it public.

First of it all it uses my last.fm Weekly Artists XML, which gets turned in to HTML through a simple XSL transformation then styled with CSS.

The glue that holds it together is the extremely useful inlineRSS plugin for Wordpress. this handled the fetching of the XML and the XSL transformation, with a little caching too.

XSL Transformation

Take a look at the full XSL file.

The XSL that converts the last.fm feed into the tag-cloud HMTL is fairly simple, grabbing a bunch of artists and looping through them to build an ordered list. The tricky bit is defining the differing sizes between artists based on the playcount. There are a couple of other bits might benefit from further explanation:

<xsl:variable name="max_artists" select="20"/>
<xsl:variable name="min_playcount" select="2" />

These specify a maximum number of artists and a minimum number of plays to be included in the cloud. This solves two problems, a large number of artists being played making the tag-cloud huge and playing just one or two tracks for an artist (Like with compilations) which just swamps the tag cloud with lots of low played artists.

<xsl:variable name="weight" select="playcount div $max_playcount" />
<xsl:variable name="size" select="($weight * $size_range) + $size_min" />

To calculate the weighting, how big the font-size should be, it takes the highest played artists playcount as a baseline and treats every other artist as a fraction of that. This fraction, the weight, is then used to the size using the min and max sizes as boundaries.

The rest of the XSL just builds the list, link and span tags/content.

<xsl:variable name="artists" select="/weeklyartistchart/artist[playcount >= $min_playcount and position() <= $max_artists]" />

This is the XPATH query used to get the set of valid artists than have the minimum playcount and caped at the maximum number of artists

Semantics

Tag-clouds have a reputation as being pretty unsemantic when it comes to HTML. Often just being an alphabetised list when viewed without styling. Norm had a go at marking up tag-clouds semantically, which i’ve followed with one exception.

Rather than using a set of class names I opted for inline styles declaring the font-size. Heresy! Well, yes and no. I want the cloud items to be properly scaled and the scale easy to modify, this just isn’t possible using a set combination of classes mapped to sizes.

This doesn’t really bother me much, especially with the extra semantic information added. So the final markup looks like so:

<li style="font-size: 4.000em;">     <span><span class="weighting">26</span> listens to</span>     <a xhref="http://www.last.fm/music/Stars" mce_href="http://www.last.fm/music/Stars" title="Stars (26 listens)">         Stars     </a> </li> <li style="font-size: 3.077em;">     <span><span class="weighting">18</span> listens to</span>     <a xhref="http://www.last.fm/music/The+Microphones" mce_href="http://www.last.fm/music/The+Microphones" title="The Microphones (18 listens)">         The Microphones     </a> </li>

If you’re paying attention you’ll have spotted another span in there, inside the one used to hide the non-artist-name information. Why add it? It gives a semantic hook to get the actual weighting value of the cloud, in this case listens.

With this you could create a very simple piece of javascript to turn the tag cloud back in to a chart, ordered by listens rather than alphabetically.

Styling

There’s only some very simple styling on the list itself. Mostly just visual formating, but importantly a rule to hide the span of contextual information leaving just the artist name.

ol {
width: 700px;
margin: 0 auto;

list-style: none;
text-align: center;

font-size: .6em;
}

li {
display: inline;
margin: 0 .2em;
padding: 0 .3em;

line-height: 1.5;
vertical-align: middle;
}

li span {
position: absolute;
left: -999px;
width: 990px;
}

Known Issues

There are still a few things I’m unhappy about with this, when using artist names rather than tags you’re far more likely to get spaces and end up with an artist name split across two lines. This can often end up looking like two separate artists if you’re not familiar with the name.

And, the obvious problem – it’s all reliant on data from another site, last.fm. I can’t be sure it’ll always be up, or that formats wont change. This is the price you pay for relying on external service, in this case it’s nothing critical or even important, but it’s something people seem to forget a lot of the time.

Demo

I built a little demo page where you can enter your last.fm username (or a friends) and see a tag cloud of your recently weekly artists. Check out a few examples;

Give it a try.