>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Last.fm tag update

StephenM sent me a few changes to the last.fm tag. He made thses changes:

* Added check for top tracks
* Added a variable for audioscrobbler account
* Added some XML checks

For those of you that don't know what this tags does it basically grabs you audioscrobbler information (used by last.fm) and diplays it on your page. It then links the music name into your amazon account. It shows your top albums, latest played tracks, top artist.

The new code is:

<!--- n.tong@talkwebsolutions.co.uk |
/**
* Get xml datafeeds for last.fm and links the artists from the page to you amazon account
*
* @param AmazonTagID Your amazonID, you can get this from vreating a link in the amazon affiliate area.(Required)
* @author Nick Tong (n.tong@talkwebsolutions.co.uk)
* @version 0.1, April 3, 2006
* @ update StephenM - Added check for top tracks and added a variable for audioscrobbler account
*/
--->
<cfsetting enablecfoutputonly=true>
<cfoutput>
<cfsavecontent variable="request.JSHeader">
<script type="text/javascript" src="includes/javascript/tipster.js"></script>
<style type="text/css">
      h2 {
         font-family:Helvetica, Arial, sans-serif;
         font-size: 1.2em;
      }
.musictable{
width:100%;
       font-family:Helvetica, Arial, sans-serif;
       font-size:0.9em;
}
th{
text-align:left;
    font-size: 1em;
}
tr.even{
padding-top: 2px;
padding-bottom: 2px;
border-right: 1px solid ##000000;
padding-left: 3px;
padding-right: 3px;
background-color: ##E0DFCB;
       font-size:1em;
}
tr.odd{
padding-top: 2px;
padding-bottom: 2px;
border-right: 1px solid ##000000;
padding-left: 3px;
padding-right: 3px;
background-color: ##FFFFF;
       font-size:1em;
}
</style>
</cfsavecontent>
<cfhtmlhead text="#request.JSHeader#">
</cfoutput>
<cfif structKEyExists(url,"clearList")>
<cfset tmp = structdelete(application,"recent")>
<cfset tmp = structdelete(application,"lastfetch")>
</cfif>
<cfmodule template="tags/layout.cfm" title="My Last.FM Listing">
<!--- lets not run the page on every request - lets load the page into the application scope and reload it every 10 mins (this can be changed) --->
<cftry>
<!---Make sure we have data in the cache for the key--->
<cfparam name="application.recent" default="">
<cfparam name="application.lastFetch" default="#now()#">
<!--- n.tong@talkwebsolutions.co.uk | set the amazonTagID --->
<cfset request.scrobblerID="YourScrobblerID" />
<cfset request.amazonTagID = "yourAmazonID" />

<!---Get the expiration date for the data, in mins--->
<cfset maxDate = DateAdd("n",10,application.lastFetch)>
<!---Does the key contain content and is the expiration date greater than the current date, if not lets get the data again--->
<cfif len(application.recent) AND DateCompare(maxDate,Now()) EQ 1>
<cfoutput>#application.recent# </cfoutput>
<cfelse>
<!--- n.tong@talkwebsolutions.co.uk | get the feeds --->
<cfhttp url="http://ws.audioscrobbler.com/1.0/user/#request.scrobblerID#/recenttracks.xml" method="get"></cfhttp>
<cfset recenttracks = XmlParse(cfhttp.FileContent) />
<cfset recenttracksDetail = XmlSearch(recenttracks, "/recenttracks/track") />
<cfset recenttracksShowCount = ArrayLen(recenttracksDetail)>
<cfhttp url="http://ws.audioscrobbler.com/1.0/user/#request.scrobblerID#/topartists.xml" method="get"></cfhttp>
<cfif IsXML(cfhttp.FileContent)>
<cfset topartists = XmlParse(cfhttp.FileContent) />
<cfset topArtistNames = XmlSearch(topartists, "/topartists/artist") />
<cfset topArtistShowCount = 20>
<!--- ArrayLen(topArtistNames) --->
</cfif>
<cfhttp url="http://ws.audioscrobbler.com/1.0/user/#request.scrobblerID#/topalbums.xml" method="get"></cfhttp>
<cfif IsXML(cfhttp.FileContent)>
<cfset topAlbums = XmlParse(cfhttp.FileContent) />
<cfset topAlbumsNames = XmlSearch(topalbums, "/topalbums/album") />
<cfset topAlbumsShowCount = ArrayLen(topAlbumsNames)>
</cfif>
<cfhttp url="http://ws.audioscrobbler.com/1.0/user/#request.scrobblerID#/toptracks.xml" method="get"></cfhttp>
<cfif IsXML(cfhttp.FileContent)>
<cfset toptracks = XmlParse(cfhttp.FileContent) />
<cfset toptracksNames = XmlSearch(toptracks, "/toptracks/track") />
<cfset toptracksShowCount = ArrayLen(toptracksNames)>
</cfif>

<cfoutput>
<cfsavecontent variable="application.Recent">
<cfif StructKeyExists(variables,"topAlbumsShowCount")>
<script type="text/javascript"><!--

// First, create a new tip object, and pass it its own name so it can reference itself.        var docTips = new TipObj('docTips');
with (docTips)
{
template = '%3%';

<cfloop index="z" from="1" to="#topAlbumsShowCount#">
<cfif len(topalbumsNames[z].mbid.XmlText)>
tips.#rereplace(topalbumsNames[z].mbid.XmlText,"[^a-z]","","all")# = new Array(5, 5, 150, '<img src=#topalbumsNames[z].image.small.XmlText#>');
</cfif>
</cfloop>
}

//--></script> <div id="docTipsLayer" style="position: absolute; z-index: 10000; visibility: hidden;
left: 0px; top: 0px; width: 10px"
>
</div>
</cfif>
<h2>Recent Tracks</h2>
<table title="My Recent Tracks" summary="Check out my most recent songs and artists." class="musictable">
<tr>
<th>Played</th>
<th>Track</th>
<th>Artist</th>
</tr>
<cfloop index="z" from="1" to="#recenttracksShowCount#">
<tr class="<cfif z mod 2>even<cfelse>odd</cfif>">
<td>#recenttracksDetail[z].date.XmlText# </td>
<td>#recenttracksDetail[z].name.XmlText# </td>
<td><a href="http://www.amazon.co.uk/exec/obidos/redirect?link_code=ur2&tag=#request.amazonTagID#&camp=1634&creative=6738&path=external-search%3Fsearch-type=ss%26index=blended%26keyword=#recenttracksDetail[z].artist.XmlText#" target="_blank">#recenttracksDetail[z].artist.XmlText#</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=#request.amazonTagID#&l=ur2&o=2" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> </td>
</tr>
</cfloop>
</table>
<cfif StructKeyExists(variables,"topArtistShowCount")>
<h2>Top Artists</h2>
<table title="My Top Artists" summary="Check out my most recent songs and artists." class="musictable">
<tr>
<th>Rank</th>
<th>Artists</th>
<th>PlayCount</th>
</tr>
<cfloop index="z" from="1" to="#topArtistShowCount#">
<tr class="<cfif z mod 2>even<cfelse>odd</cfif>">
<td valign="top">#topArtistNames[z].rank.XmlText# </td>
<td valign="top"><a href="http://www.amazon.co.uk/exec/obidos/redirect?link_code=ur2&tag=#request.amazonTagID#&camp=1634&creative=6738&path=external-search%3Fsearch-type=ss%26index=blended%26keyword=#topArtistNames[z].name.XmlText#" target="_blank">#topArtistNames[z].name.XmlText#</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=#request.amazonTagID#&l=ur2&o=2" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> </td>
<td valign="top">#topArtistNames[z].playcount.XmlText# </td>
</tr>
</cfloop>
</table>
</cfif>
<cfif StructKeyExists(variables,"topAlbumsShowCount")>
<h2>Top Albums</h2>
<table title="My Tops Albums" summary="Check out my most recent songs and artists." class="musictable">
<tr>
<th>Rank</th>
<th>Album</th>
<th>Artist</th>
<th>PlayCount</th>
</tr>
<cfloop index="z" from="1" to="#topAlbumsShowCount#">
<tr class="<cfif z mod 2>even<cfelse>odd</cfif>">
<td valign="top">#topalbumsNames[z].rank.XmlText# </td>
<td valign="top" onmouseover="docTips.show('#rereplace(topalbumsNames[z].mbid.XmlText,"[^a-z]","","all")#')"
onmouseout="docTips.hide()" >
#topalbumsNames[z].name.XmlText# </td>
<td valign="top"><a href="http://www.amazon.co.uk/exec/obidos/redirect?link_code=ur2&tag=#request.amazonTagID#&camp=1634&creative=6738&path=external-search%3Fsearch-type=ss%26index=blended%26keyword=#topalbumsNames[z].artist.XmlText#" target="_blank">#topalbumsNames[z].artist.XmlText#</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=#request.amazonTagID#&l=ur2&o=2" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> </td>
<td valign="top">#topalbumsNames[z].playcount.XmlText# </td>
</tr>
</cfloop>
</table>
</cfif>
<cfif StructKeyExists(variables,"toptracksShowCount")>
<h2>Top Tracks</h2>
<table title="Top Tracks" summary="Check out my most recent songs and artists." class="musictable">
<tr>
<th>Rank</th>
<th>Track</th>
<th>Artist</th>
<th>PlayCount</th>
</tr>
<cfloop index="z" from="1" to="#toptracksShowCount#">
<tr class="<cfif z mod 2>even<cfelse>odd</cfif>">
<td valign="top">#toptracksNames[z].rank.XmlText# </td>
<td valign="top">#toptracksNames[z].name.XmlText# </td>
<td valign="top"><a href="http://www.amazon.co.uk/exec/obidos/redirect?link_code=ur2&tag=#request.amazonTagID#&camp=1634&creative=6738&path=external-search%3Fsearch-type=ss%26index=blended%26keyword=#toptracksNames[z].artist.XmlText#" target="_blank">#toptracksNames[z].artist.XmlText#</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=#request.amazonTagID#&l=ur2&o=2" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> </td>
<td valign="top">#toptracksNames[z].playcount.XmlText# </td>
</tr>
</cfloop>
</table>
</cfif>
<br /><img src="http://www.succor.co.uk/media/images/audioscrobbler.png" alt="audioScrobbler" name="audioscrobbler" width="144" height="27" /><br />&nbsp;

      Displayed using Nick Tongs <a href="http://www.succor.co.uk/index.cfm/2006/10/20/Lastfm-tag-update">Last.fm tag.</a>
       
</cfsavecontent>
<!--- output the content --->
#application.recent# </cfoutput>
</cfif>
<cfcatch>
<cfoutput>Service Unavailable</cfoutput>
<Cfdump var="#variables#">
</cfcatch>
</cftry>
</cfmodule>
<cfsetting enablecfoutputonly=false>

Thanks Stephen.

Remember if you're using this tage outside of blogCFC then remove the cfmodule template="tags/layout.cfm" tag.

View the results here


 
Comments
Stephen Moretti's Gravatar Heh heh - no worries.... Can you tell its Friday afternoon?
# Posted By Stephen Moretti | 20/10/06 14:48 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.