<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Code Train &#187; last.fm</title>
	<atom:link href="http://thecodetrain.co.uk/tag/lastfm/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecodetrain.co.uk</link>
	<description>Where Neil Crosby talks about coding on the train...</description>
	<lastBuildDate>Wed, 18 Aug 2010 18:22:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using last.fm tags to make awesome playlists in your local iTunes library</title>
		<link>http://thecodetrain.co.uk/2010/08/using-last-fm-tags-to-make-awesome-playlists-in-your-local-itunes-library/</link>
		<comments>http://thecodetrain.co.uk/2010/08/using-last-fm-tags-to-make-awesome-playlists-in-your-local-itunes-library/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 18:00:15 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=484</guid>
		<description><![CDATA[<p>As I&#8217;ve mentioned previously, I have a large music collection that I manage using iTunes.  One of the problems with any large collection is the curation and management that goes with it.  I carry my iPhone around with me and I listen to music on it, but even the biggest iPhone available would hold only  fifth of my collection.  So, I need techniques for pulling interesting music from my iTunes library into my iPhone.</p>

<p>Up until now I&#8217;ve used a collection of Smart Playlists which take into account my ratings, when I last listened to songs and a whole bunch of other information.  At the last count, I had over 70 Smart Playlists feeding into each other to generate the playlists which finally get Synced over to my iPhone.</p>

<p>But there was something missing.  Whilst I could generate playlists based on the mid-90s simplicity of the &#8220;Genre&#8221; tag, that tag is by design only able to identify one piece of information.  So I wouldn&#8217;t be able to find, for example, all tracks in my collection that are &#8220;rock&#8221;, &#8220;funny&#8221; and performed by a &#8220;female&#8221;.  And even if I could, I wouldn&#8217;t want to go and tag 40,000 tracks by hand. That way madness lies.</p>

<p>It turns out there&#8217;s a fairly simple solution to this &#8211; last.fm allows users to tag any and all tracks it knows about, and it keeps track of how many times each track has been tagged with each tag.  So, it&#8217;s entirely possible to grab the top 15 tags for each track in my collection, add that data to my tracks somehow, and then query that.</p>

<p>The somehow turns out to be pretty simple too &#8211; the ID3 &#8220;comment&#8221; field is there for the taking, and by design is expected to be larger than any other field.  Excellent.  So that&#8217;s the &#8220;where to store&#8221; sorted, now how about &#8220;how to store so that the data is queryable&#8221;?</p>

<p>For this I took <a href="http://www.xml.com/pub/a/2007/09/04/parsing-microformats.html?page=2">a trick out of Brian Suda&#8217;s book</a>.  A couple of years back I took a look at how he&#8217;d written his microformats parser using XSLT to be able to check for classes an element may or may not have &#8211; the trick being to wrap strings of classes with a space at the beginning and end so that every class <em>always</em> had spaces surrounding it.  I used the same trick for storing my tag data, also wrapping it in a &#8216;lfm&#8217; square bracketed enclosure to separate it from any other data in the comment.</p>

<p>So, the data I saved in the comment looked a little something like this:</p>

<pre><code>[lfm: tag1 tag2 tag23 tag3 ]
</code></pre>

<p>You&#8217;re probably starting to see why wrapping in spaces is important now.  Because iTunes&#8217; Smart Playlist system can only perform simple string matching (Apple doesn&#8217;t seem to like regexes &#8211; AppleScript can&#8217;t do them natively either), you need some way of targetting the beginning and end of tags. Without those spaces, a query of &#8220;<code>Comments contains 'tag2'</code>&#8221; would return you both <code>tag2</code> and <code>tag23</code>, which no-one wants.  By requesting &#8220;<code>Comments contains ' tag2 '</code>&#8221; instead (note the extra spaces) you end up just being given <code>tag2</code>.</p>

<p>All this thinking is packaged up into a <a href="http://github.com/NeilCrosby/itunes-helpers/commit/b94cf1f2c28bdc2b83129b458e0e6bc42573afdb">couple of scripts</a> (though obviously take <a href="http://github.com/NeilCrosby/itunes-helpers/tree/master/playlist/lastfm/">the latest code</a> if you want to actually use it yourself) I wrote a couple of days ago that takes a given playlist from your iTunes library, asks last.fm for tags for each of the songs in that playlist, and then adds that data to the library using AppleScript.</p>

<h2>Problems?</h2>

<p>There are, unfortunately, a couple of issues with the script at the moment.  First off, because last.fm allows anything and everything to be given as a tag, they can contain characters that need to be normalised out.  Right now I&#8217;m doing that very simply (spaces to dashes mostly), but I should revisit the code and harden that normalisation &#8211; I&#8217;ve seen tagging bail out a couple of times because of unexpected data.</p>

<p>Next up, the fact that last.fm allows tags to be incredibly long coupled with the fact that under ID3 v2.x the comments field can only be 256 characters long means that it&#8217;s possible to run into issues with tagsets being too long to fit into the comments field.  Add that to the fact that some songs in my collection legitimately contain comments already and that I want to add tags non-destructively, and we&#8217;re ending up with not much space for tags.  So, an improvement that I&#8217;m planning on making to the script is to make sure that tags try to take up no more than the space that&#8217;s legitimately available to them.</p>

<p>The final issue that I&#8217;ve been having lives with last.fm&#8217;s track.getTopTags API method.  Unfortunately at present the track.getTopTags API method does not perform any auto-correction of track names, which means that if you try to get the tags for something that does get auto-corrected by the system then you end up with the tags for the uncorrected track name. A subtle distinction, but it probably means that we end up with unmaintained tags that haven&#8217;t been touched for the year or so since auto-correction was turned on. A possible solution here if last.fm choose not to &#8220;fix&#8221; this behaviour (it could be argued that this is correct behaviour) would be to make a request out to Musicbrainz to get an ID for the track and then pass that into track.getTopTags instead.  But that seems like a whole bunch of extra work for a not massive gain.</p>

<h2>The final Smart Playlist</h2>

<p>So, what about that Smart Playlist? After all, that&#8217;s the thing that all this work was done for.</p>

<p>In iTunes, select <code>File</code>, <code>New Smart Playlist</code>, and then enter the following:</p>

<pre><code>Match all of the following rules:
    Comments contains ' female '
    Comments contains ' rock ' ...
    any of the following rules:
        Comments contains ' comedy '
        Comments contains ' funny '
</code></pre>

<p>This cunning playlist uses a Smart Playlist feature I wasn&#8217;t aware of until yesterday &#8211; rule groups.  Up until now, I&#8217;d been pulling in other Smart Playlists as sources to perform the same job.</p>

<p>To create a new rule group in a Smart Playlist, simply click an ellipsis button in the Smart Playlist interface, rather than clicking on the plus button.</p>

<p>Essentially what these rule groups give you is the ability to nest rulesets, and generate very complex playlists that don&#8217;t have half their rules hidden in external playlists.  In the playlist above we&#8217;re simply asking for all tracks tagged with &#8220;female&#8221;, &#8220;rock&#8221; and either &#8220;funny&#8221; or &#8220;comedy&#8221;. So essentially &#8220;female comedy rock&#8221;.  At present this playlist returns me no items from my collection, but not everything&#8217;s been tagged yet.  I&#8217;m hopeful.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve mentioned previously, I have a large music collection that I manage using iTunes.  One of the problems with any large collection is the curation and management that goes with it.  I carry my iPhone around with me and I listen to music on it, but even the biggest iPhone available would hold only  fifth of my collection.  So, I need techniques for pulling interesting music from my iTunes library into my iPhone.</p>

<p>Up until now I&#8217;ve used a collection of Smart Playlists which take into account my ratings, when I last listened to songs and a whole bunch of other information.  At the last count, I had over 70 Smart Playlists feeding into each other to generate the playlists which finally get Synced over to my iPhone.</p>

<p>But there was something missing.  Whilst I could generate playlists based on the mid-90s simplicity of the &#8220;Genre&#8221; tag, that tag is by design only able to identify one piece of information.  So I wouldn&#8217;t be able to find, for example, all tracks in my collection that are &#8220;rock&#8221;, &#8220;funny&#8221; and performed by a &#8220;female&#8221;.  And even if I could, I wouldn&#8217;t want to go and tag 40,000 tracks by hand. That way madness lies.</p>

<p>It turns out there&#8217;s a fairly simple solution to this &#8211; last.fm allows users to tag any and all tracks it knows about, and it keeps track of how many times each track has been tagged with each tag.  So, it&#8217;s entirely possible to grab the top 15 tags for each track in my collection, add that data to my tracks somehow, and then query that.</p>

<p>The somehow turns out to be pretty simple too &#8211; the ID3 &#8220;comment&#8221; field is there for the taking, and by design is expected to be larger than any other field.  Excellent.  So that&#8217;s the &#8220;where to store&#8221; sorted, now how about &#8220;how to store so that the data is queryable&#8221;?</p>

<p>For this I took <a href="http://www.xml.com/pub/a/2007/09/04/parsing-microformats.html?page=2">a trick out of Brian Suda&#8217;s book</a>.  A couple of years back I took a look at how he&#8217;d written his microformats parser using XSLT to be able to check for classes an element may or may not have &#8211; the trick being to wrap strings of classes with a space at the beginning and end so that every class <em>always</em> had spaces surrounding it.  I used the same trick for storing my tag data, also wrapping it in a &#8216;lfm&#8217; square bracketed enclosure to separate it from any other data in the comment.</p>

<p>So, the data I saved in the comment looked a little something like this:</p>

<pre><code>[lfm: tag1 tag2 tag23 tag3 ]
</code></pre>

<p>You&#8217;re probably starting to see why wrapping in spaces is important now.  Because iTunes&#8217; Smart Playlist system can only perform simple string matching (Apple doesn&#8217;t seem to like regexes &#8211; AppleScript can&#8217;t do them natively either), you need some way of targetting the beginning and end of tags. Without those spaces, a query of &#8220;<code>Comments contains 'tag2'</code>&#8221; would return you both <code>tag2</code> and <code>tag23</code>, which no-one wants.  By requesting &#8220;<code>Comments contains ' tag2 '</code>&#8221; instead (note the extra spaces) you end up just being given <code>tag2</code>.</p>

<p>All this thinking is packaged up into a <a href="http://github.com/NeilCrosby/itunes-helpers/commit/b94cf1f2c28bdc2b83129b458e0e6bc42573afdb">couple of scripts</a> (though obviously take <a href="http://github.com/NeilCrosby/itunes-helpers/tree/master/playlist/lastfm/">the latest code</a> if you want to actually use it yourself) I wrote a couple of days ago that takes a given playlist from your iTunes library, asks last.fm for tags for each of the songs in that playlist, and then adds that data to the library using AppleScript.</p>

<h2>Problems?</h2>

<p>There are, unfortunately, a couple of issues with the script at the moment.  First off, because last.fm allows anything and everything to be given as a tag, they can contain characters that need to be normalised out.  Right now I&#8217;m doing that very simply (spaces to dashes mostly), but I should revisit the code and harden that normalisation &#8211; I&#8217;ve seen tagging bail out a couple of times because of unexpected data.</p>

<p>Next up, the fact that last.fm allows tags to be incredibly long coupled with the fact that under ID3 v2.x the comments field can only be 256 characters long means that it&#8217;s possible to run into issues with tagsets being too long to fit into the comments field.  Add that to the fact that some songs in my collection legitimately contain comments already and that I want to add tags non-destructively, and we&#8217;re ending up with not much space for tags.  So, an improvement that I&#8217;m planning on making to the script is to make sure that tags try to take up no more than the space that&#8217;s legitimately available to them.</p>

<p>The final issue that I&#8217;ve been having lives with last.fm&#8217;s track.getTopTags API method.  Unfortunately at present the track.getTopTags API method does not perform any auto-correction of track names, which means that if you try to get the tags for something that does get auto-corrected by the system then you end up with the tags for the uncorrected track name. A subtle distinction, but it probably means that we end up with unmaintained tags that haven&#8217;t been touched for the year or so since auto-correction was turned on. A possible solution here if last.fm choose not to &#8220;fix&#8221; this behaviour (it could be argued that this is correct behaviour) would be to make a request out to Musicbrainz to get an ID for the track and then pass that into track.getTopTags instead.  But that seems like a whole bunch of extra work for a not massive gain.</p>

<h2>The final Smart Playlist</h2>

<p>So, what about that Smart Playlist? After all, that&#8217;s the thing that all this work was done for.</p>

<p>In iTunes, select <code>File</code>, <code>New Smart Playlist</code>, and then enter the following:</p>

<pre><code>Match all of the following rules:
    Comments contains ' female '
    Comments contains ' rock ' ...
    any of the following rules:
        Comments contains ' comedy '
        Comments contains ' funny '
</code></pre>

<p>This cunning playlist uses a Smart Playlist feature I wasn&#8217;t aware of until yesterday &#8211; rule groups.  Up until now, I&#8217;d been pulling in other Smart Playlists as sources to perform the same job.</p>

<p>To create a new rule group in a Smart Playlist, simply click an ellipsis button in the Smart Playlist interface, rather than clicking on the plus button.</p>

<p>Essentially what these rule groups give you is the ability to nest rulesets, and generate very complex playlists that don&#8217;t have half their rules hidden in external playlists.  In the playlist above we&#8217;re simply asking for all tracks tagged with &#8220;female&#8221;, &#8220;rock&#8221; and either &#8220;funny&#8221; or &#8220;comedy&#8221;. So essentially &#8220;female comedy rock&#8221;.  At present this playlist returns me no items from my collection, but not everything&#8217;s been tagged yet.  I&#8217;m hopeful.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2010/08/using-last-fm-tags-to-make-awesome-playlists-in-your-local-itunes-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Letting everyone control my music</title>
		<link>http://thecodetrain.co.uk/2009/02/letting-everyone-control-my-music/</link>
		<comments>http://thecodetrain.co.uk/2009/02/letting-everyone-control-my-music/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 19:25:00 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[collaboration]]></category>
		<category><![CDATA[enya]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[lastify]]></category>
		<category><![CDATA[playlists]]></category>
		<category><![CDATA[radio]]></category>
		<category><![CDATA[spotify]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=211</guid>
		<description><![CDATA[<p>Today, I tried an experiment.  This morning, I&#8217;d been reading <a href="http://musicmachinery.com/">Paul Lamere</a>&#8217;s blog entry about <a href="http://musicmachinery.com/2009/02/23/collaborative-playlists/">Collaborative Playlists</a> in which he mentioned that it was possible to create them in <a href="http://spotify.com">Spotify</a>.</p>

<p>Well, colour me surprised.  </p>

<p>I&#8217;ve been using Spotify for a little while now, but only ever to listen to particular songs that I wanted to hear whilst away from my full media library or to listen to artist radio.  I&#8217;d never been enticed by playlists in Spotify in general, mainly because I only ever used it for little bits and pieces here and there.  Finding out that I could use it to get people to suggest music to me was a revelation.</p>

<p>So, I tried a little experiment.  This morning <a href="http://twitter.com/NeilCrosby/status/1252951853">I tweeted</a> a link to <a href="http://open.spotify.com/user/neilcrosby/playlist/2CGjeaQQ8WomtSoJqpAU5Y">my collaborative playlist</a>, asking people to add to it.  My aim was to press play at that point and just keep listening to the playlist all day, with no self intervention.  I trusted people to add music that they thought was good, with a little bit of adding amusingly bad songs for the hell of it.  Sure enough, Aqua made it in there with &#8220;Barbie Girl&#8221;, as did Celine Dion with &#8220;My Heart Will Go On&#8221;.  But, I listened to them all.  Well, all of them except for Enya, but you have to draw the line somewhere, don&#8217;t you?</p>

<p>During the course of the day I listened to many artists I&#8217;d forgotten about, as well as plenty I didn&#8217;t know at all.  One of the nice things that came out of this experiment was finding a load of new songs that I liked, and thanks to <a href="http://georgebrock.com/">George Brocklehurst&#8217;s</a> <a href="http://github.com/georgebrock/lastify/tree/master">Lastify</a> add-on for Spotify I was able to easily mark them as &#8220;loved&#8221; on Last.fm so that I could come back and listen to them again later.</p>

<p>By the time I finished working I&#8217;d only managed to make it halfway down the playlist that had been created.  So, tomorrow I&#8217;ll be carrying on where I left of and listening to some more new to me music.</p>

<p>There are a couple of things that I wish were possible with Spotify&#8217;s Collaborative Playlists though.  First off, I wish I could see who it was who added certain songs, so I could gently mock them for their choices.  Following on from that it would be nice if you could lock down a playlist so that only certain users could add to it, or block certain user entirely.  Not that I had any problems today, but it&#8217;s still a worry that someone might go crazy and just add fifteen hours of Rick Astley to a playlist.</p>

<p>Why not give it a go yourself?  Just create a playlist in Spotify, right click on its name and set it as collaborative, and then give people the URL.  You&#8217;ll probably be pleasantly surprised by what you get added.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Today, I tried an experiment.  This morning, I&#8217;d been reading <a href="http://musicmachinery.com/">Paul Lamere</a>&#8217;s blog entry about <a href="http://musicmachinery.com/2009/02/23/collaborative-playlists/">Collaborative Playlists</a> in which he mentioned that it was possible to create them in <a href="http://spotify.com">Spotify</a>.</p>

<p>Well, colour me surprised.  </p>

<p>I&#8217;ve been using Spotify for a little while now, but only ever to listen to particular songs that I wanted to hear whilst away from my full media library or to listen to artist radio.  I&#8217;d never been enticed by playlists in Spotify in general, mainly because I only ever used it for little bits and pieces here and there.  Finding out that I could use it to get people to suggest music to me was a revelation.</p>

<p>So, I tried a little experiment.  This morning <a href="http://twitter.com/NeilCrosby/status/1252951853">I tweeted</a> a link to <a href="http://open.spotify.com/user/neilcrosby/playlist/2CGjeaQQ8WomtSoJqpAU5Y">my collaborative playlist</a>, asking people to add to it.  My aim was to press play at that point and just keep listening to the playlist all day, with no self intervention.  I trusted people to add music that they thought was good, with a little bit of adding amusingly bad songs for the hell of it.  Sure enough, Aqua made it in there with &#8220;Barbie Girl&#8221;, as did Celine Dion with &#8220;My Heart Will Go On&#8221;.  But, I listened to them all.  Well, all of them except for Enya, but you have to draw the line somewhere, don&#8217;t you?</p>

<p>During the course of the day I listened to many artists I&#8217;d forgotten about, as well as plenty I didn&#8217;t know at all.  One of the nice things that came out of this experiment was finding a load of new songs that I liked, and thanks to <a href="http://georgebrock.com/">George Brocklehurst&#8217;s</a> <a href="http://github.com/georgebrock/lastify/tree/master">Lastify</a> add-on for Spotify I was able to easily mark them as &#8220;loved&#8221; on Last.fm so that I could come back and listen to them again later.</p>

<p>By the time I finished working I&#8217;d only managed to make it halfway down the playlist that had been created.  So, tomorrow I&#8217;ll be carrying on where I left of and listening to some more new to me music.</p>

<p>There are a couple of things that I wish were possible with Spotify&#8217;s Collaborative Playlists though.  First off, I wish I could see who it was who added certain songs, so I could gently mock them for their choices.  Following on from that it would be nice if you could lock down a playlist so that only certain users could add to it, or block certain user entirely.  Not that I had any problems today, but it&#8217;s still a worry that someone might go crazy and just add fifteen hours of Rick Astley to a playlist.</p>

<p>Why not give it a go yourself?  Just create a playlist in Spotify, right click on its name and set it as collaborative, and then give people the URL.  You&#8217;ll probably be pleasantly surprised by what you get added.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2009/02/letting-everyone-control-my-music/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last Genius &#8211; A last.fm hack day project</title>
		<link>http://thecodetrain.co.uk/2008/12/last-genius-a-lastfm-hack-day-project/</link>
		<comments>http://thecodetrain.co.uk/2008/12/last-genius-a-lastfm-hack-day-project/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 11:02:13 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[genius]]></category>
		<category><![CDATA[genius playlists]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[hack day]]></category>
		<category><![CDATA[last.fm]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=182</guid>
		<description><![CDATA[<p>Gosh, it&#8217;s thursday already?  Last Sunday I attended <a href="http://last.fm">last.fm</a>&#8217;s first open <a href="http://www.last.fm/group/Hack+Day">Hack Day</a> near Brick Lane in London with the intention of building a system to allow creation of Genius Playlists using last.fm&#8217;s data.</p>

<p>For those of you who aren&#8217;t sure, a Genius Playlist is a playlist of music that all &#8220;works together&#8221; that&#8217;s created from one seed track of the user&#8217;s choice.  Essentially, it&#8217;s a shortcut to creating playlists of stuff that suits how you&#8217;re feeling at that moment, rather than you having to go to the trouble of creating the playlist yourself.</p>

<p>Whilst I was initially sceptical of how well this would work (I&#8217;ve worked in this problem space before, so I know it isn&#8217;t awesomely easy), since iTunes gained this feature in v8 I&#8217;ve become more and more reliant on it.  My reliance has been so great that I&#8217;ve expected the feature in all the other music based services I use.  For example, when I started using <a href="http://spotify.com">Spotify</a>, one of the first things I did without thinking was to start playing  a track that I wanted to listen to and then look for the &#8220;genius&#8221; button to see what else Spotify would try and play for me.  It upset me that this feature wasn&#8217;t there.  Sure, Spotify and last.fm allow you to play radio stations based on a certain genre, artist or tag, but that misses a piece of perceived control that starting with a chosen song implies.</p>

<p>So, for last.fm&#8217;s hack day I decided to hack together a genius playlist creator.  After all, <a href="http://last.fm/api">last.fm&#8217;s API</a> supplies the <a href="http://www.last.fm/api/show?service=319">track.getSimilar</a> method, which pretty much gives all the data you need for a genius playlist.  </p>

<p>There were a few hurdles to get through though.  First up was playlist creation and playback itself.  It turns out that in last.fm-world you can only create actual playlists if you&#8217;re a paid subscriber to the service.  That&#8217;s not a dealbreaker for me, so I paid my £1.50 for a month&#8217;s subscription to see how it went.  Unfortunately, at that point I realised that whilst I could now create playlists, I could only play them back if they had at least 45 songs in them by at least 15 different artists.  Oh, and I could only play them back in shuffle mode.  On the website.  Not in the desktop app or on the iPhone.  Somewhat sub-optimal.</p>

<p>So, I went back to the drawing board.  If I couldn&#8217;t do playlists how I wanted in last.fm, how about if I found the data I wanted in last.fm and then used Spotify to play it?  Unfortunately, Spotify doesn&#8217;t yet have an API, so this also proved impossible.</p>

<p>Scratch Plan B then.  Thankfully, I did have a Plan 9 available to me &#8211; last.fm&#8217;s ability to autostart tracks on the website by adding <code>?autostart</code> to the end of any song page URL.  Using this ability, I reckoned, I would be able to create a page containing a list of songs that could then be played in a browser window by loading up the individual song pages in a hidden iframe.  Simplicity itsef, and as if by magic it actually worked!</p>

<p>There was, of course, more magic that went into creating Last Genius.  Not all songs on the site are available to stream, and of those that are not all of them are full length tracks.  Because I was playing the songs in iframes I had no way of knowing when a song had actually ended.  I had to make sure that you didn&#8217;t end up hearing the same song twice in a playlist.  All these things and more were hacked around during the hack day, and in the end I had something that actually worked.</p>

<p>The end result was a bookmarklet that you can stick into your browser toolbar and click to create a genius playlist any time you want.  Just make sure you&#8217;re on a Last.fm song page and a playlist will be created for you.  If you&#8217;re not on a song page, lets just say that the system will try and find you some music that it reckons you&#8217;ll like.</p>

<p><a href="javascript:void(window.open('http://projects.thecodetrain.co.uk/last-genius/playlist.php?url='+location.href,'mywin','left=20,top=20,width=700,height=300,toolbar=0,resizable=1'));">Last Genius</a> bookmarklet &#8211; drag onto your toolbar.</p>

<p>All I ask is that you remember that this is a hack.  It&#8217;s only tested in Firefox 3 on the Mac, because during a hack day you don&#8217;t have time to make everything work everywhere (it&#8217;ll probably work elsewhere, I just haven&#8217;t tested yet).  Because Last Genius has to make quite a few calls back to the mothership to set itself up, it might also take a little while to start up.  Just be patient.  For what it&#8217;s worth, I have plans to improve this over Christmas.</p>

<p>Because this is a toy I want for myself I plan to spend a bit more time making it nicer.  With that in mind, if you have any ideas for things that will make it better, please let me know.  Likewise, <a href="https://github.com/NeilCrosby/last-genius/tree">the source code</a> is up on GitHub, so please go fork it and make improvements.  Anything awesome I&#8217;ll very happily merge back into the trunk.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Gosh, it&#8217;s thursday already?  Last Sunday I attended <a href="http://last.fm">last.fm</a>&#8217;s first open <a href="http://www.last.fm/group/Hack+Day">Hack Day</a> near Brick Lane in London with the intention of building a system to allow creation of Genius Playlists using last.fm&#8217;s data.</p>

<p>For those of you who aren&#8217;t sure, a Genius Playlist is a playlist of music that all &#8220;works together&#8221; that&#8217;s created from one seed track of the user&#8217;s choice.  Essentially, it&#8217;s a shortcut to creating playlists of stuff that suits how you&#8217;re feeling at that moment, rather than you having to go to the trouble of creating the playlist yourself.</p>

<p>Whilst I was initially sceptical of how well this would work (I&#8217;ve worked in this problem space before, so I know it isn&#8217;t awesomely easy), since iTunes gained this feature in v8 I&#8217;ve become more and more reliant on it.  My reliance has been so great that I&#8217;ve expected the feature in all the other music based services I use.  For example, when I started using <a href="http://spotify.com">Spotify</a>, one of the first things I did without thinking was to start playing  a track that I wanted to listen to and then look for the &#8220;genius&#8221; button to see what else Spotify would try and play for me.  It upset me that this feature wasn&#8217;t there.  Sure, Spotify and last.fm allow you to play radio stations based on a certain genre, artist or tag, but that misses a piece of perceived control that starting with a chosen song implies.</p>

<p>So, for last.fm&#8217;s hack day I decided to hack together a genius playlist creator.  After all, <a href="http://last.fm/api">last.fm&#8217;s API</a> supplies the <a href="http://www.last.fm/api/show?service=319">track.getSimilar</a> method, which pretty much gives all the data you need for a genius playlist.  </p>

<p>There were a few hurdles to get through though.  First up was playlist creation and playback itself.  It turns out that in last.fm-world you can only create actual playlists if you&#8217;re a paid subscriber to the service.  That&#8217;s not a dealbreaker for me, so I paid my £1.50 for a month&#8217;s subscription to see how it went.  Unfortunately, at that point I realised that whilst I could now create playlists, I could only play them back if they had at least 45 songs in them by at least 15 different artists.  Oh, and I could only play them back in shuffle mode.  On the website.  Not in the desktop app or on the iPhone.  Somewhat sub-optimal.</p>

<p>So, I went back to the drawing board.  If I couldn&#8217;t do playlists how I wanted in last.fm, how about if I found the data I wanted in last.fm and then used Spotify to play it?  Unfortunately, Spotify doesn&#8217;t yet have an API, so this also proved impossible.</p>

<p>Scratch Plan B then.  Thankfully, I did have a Plan 9 available to me &#8211; last.fm&#8217;s ability to autostart tracks on the website by adding <code>?autostart</code> to the end of any song page URL.  Using this ability, I reckoned, I would be able to create a page containing a list of songs that could then be played in a browser window by loading up the individual song pages in a hidden iframe.  Simplicity itsef, and as if by magic it actually worked!</p>

<p>There was, of course, more magic that went into creating Last Genius.  Not all songs on the site are available to stream, and of those that are not all of them are full length tracks.  Because I was playing the songs in iframes I had no way of knowing when a song had actually ended.  I had to make sure that you didn&#8217;t end up hearing the same song twice in a playlist.  All these things and more were hacked around during the hack day, and in the end I had something that actually worked.</p>

<p>The end result was a bookmarklet that you can stick into your browser toolbar and click to create a genius playlist any time you want.  Just make sure you&#8217;re on a Last.fm song page and a playlist will be created for you.  If you&#8217;re not on a song page, lets just say that the system will try and find you some music that it reckons you&#8217;ll like.</p>

<p><a href="javascript:void(window.open('http://projects.thecodetrain.co.uk/last-genius/playlist.php?url='+location.href,'mywin','left=20,top=20,width=700,height=300,toolbar=0,resizable=1'));">Last Genius</a> bookmarklet &#8211; drag onto your toolbar.</p>

<p>All I ask is that you remember that this is a hack.  It&#8217;s only tested in Firefox 3 on the Mac, because during a hack day you don&#8217;t have time to make everything work everywhere (it&#8217;ll probably work elsewhere, I just haven&#8217;t tested yet).  Because Last Genius has to make quite a few calls back to the mothership to set itself up, it might also take a little while to start up.  Just be patient.  For what it&#8217;s worth, I have plans to improve this over Christmas.</p>

<p>Because this is a toy I want for myself I plan to spend a bit more time making it nicer.  With that in mind, if you have any ideas for things that will make it better, please let me know.  Likewise, <a href="https://github.com/NeilCrosby/last-genius/tree">the source code</a> is up on GitHub, so please go fork it and make improvements.  Anything awesome I&#8217;ll very happily merge back into the trunk.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2008/12/last-genius-a-lastfm-hack-day-project/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to get more than the last 10 Recently Played Tracks from last.fm</title>
		<link>http://thecodetrain.co.uk/2008/12/how-to-get-more-than-the-last-10-recently-played-tracks-from-lastfm/</link>
		<comments>http://thecodetrain.co.uk/2008/12/how-to-get-more-than-the-last-10-recently-played-tracks-from-lastfm/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 12:07:58 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scratching an itch]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=168</guid>
		<description><![CDATA[<p>I don&#8217;t have time for a full entry today, so here&#8217;s a quick tip for <a href="http://last.fm">last.fm</a> users who are making use of their &#8220;Recently Played Tracks&#8221; RSS to do cool things.</p>

<p>It turns out that you can increase the number of tracks returned by the feed simply by adding a <code>limit=somenumber</code> parameter to the URL.  So, for me to grab the last 20 songs that I&#8217;ve scrobbled, I would ask for:</p>

<pre><code>http://ws.audioscrobbler.com/1.0/user/NeilCrosby/recenttracks.rss?limit=20
</code></pre>

<p>I use this as a way of getting a decent sampling of my recent tracks to use on <a href="http://NeilCrosby.com">NeilCrosby.com</a>, as I found the default 10 was too limiting since my &#8220;Stream of Consciousness&#8221; stream normally covers a few days worth of information, whereas my last 10 tracks would only cover an hour or so of data.</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t have time for a full entry today, so here&#8217;s a quick tip for <a href="http://last.fm">last.fm</a> users who are making use of their &#8220;Recently Played Tracks&#8221; RSS to do cool things.</p>

<p>It turns out that you can increase the number of tracks returned by the feed simply by adding a <code>limit=somenumber</code> parameter to the URL.  So, for me to grab the last 20 songs that I&#8217;ve scrobbled, I would ask for:</p>

<pre><code>http://ws.audioscrobbler.com/1.0/user/NeilCrosby/recenttracks.rss?limit=20
</code></pre>

<p>I use this as a way of getting a decent sampling of my recent tracks to use on <a href="http://NeilCrosby.com">NeilCrosby.com</a>, as I found the default 10 was too limiting since my &#8220;Stream of Consciousness&#8221; stream normally covers a few days worth of information, whereas my last 10 tracks would only cover an hour or so of data.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2008/12/how-to-get-more-than-the-last-10-recently-played-tracks-from-lastfm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
