Can be used as a tag or implemented directly in page. Uses independant scope cache of your choice. Default is application. Modify for your own look. Currently uses html markup for display but could easily be switched to an external style sheet. Use cfschedule for best site performance. You must schedule it for a time less than the cache time. Script is currently in use and available for download at http://illequipped.com/blog. Enjoy.

Updated 6/10/2005 error trapping added for empty or unavailable rss feed.

  • Emmet Mcgovern (illequipped.com/blog)
<cfsetting enablecfoutputonly=true>

<!---
CF_AudioScrobbler 6/6/2005 5:27PM
Grabs last 10 tracks from the member RSS feed at www.audioscrobbler.com

written by: Emmet McGovern
http://illequiped.com/blog
emmet@illequipped.com
--->

<cftry>
<cfset scrobbler = StructGet("application")>

<!--- create caches --->
<cfif not StructKeyExists(scrobbler,"Recent")>
        <cfset scrobbler["Recent"] = StructNew()>
</cfif>
<cfif not StructKeyExists(scrobbler,"LastFetch")>
        <cfset scrobbler["LastFetch"] = StructNew()>
</cfif>

<!---Make sure we have data in the cache for the key--->
<cfparam name="scrobbler.Recent['Playlist']" default="">
<cfparam name="scrobbler.LastFetch['Playlist']" default="#now()#">

<!---Get the expiration date for the data--->
<cfset dateCreated = scrobbler.LastFetch["Playlist"]>
<cfset maxDate = DateAdd("n",5,dateCreated)>

<!---Does the key contain content and is the expiration date greater than the current date, if not lets get the data again--->
<cfif len(scrobbler.Recent["Playlist"]) AND  DateCompare(maxDate,Now()) EQ 1>
        <cfoutput>
        #scrobbler.Recent["Playlist"]#
        <span class="small">Updated #Dateformat(scrobbler.LastFetch["Playlist"],"M/DD")# #Timeformat(scrobbler.LastFetch["Playlist"],"h:MMtt")#</span>
        </cfoutput>
<cfelse>
        <cfhttp url="http://ws.audioscrobbler.com/rdf/history/username" method="get"></cfhttp>
        <CFSet xml=CFHTTP.FileContent>
        <CFSet xmlDoc = XMLParse(xml)>
        <cfif isdefined("xmlDoc.rdf.item")>
        <cfset song=xmlDoc.rdf.item>
        <CFSET song_list = "">
        <cfloop from="1" to="#ArrayLen(song)#" index="i">
        <CFSET song_list = song_list & "<strong>" & ListFirst(song[i].description.XmlText, "-") & "</strong>" & " - " & ListLast(song[i].description.XmlText, "-") & "
"> </cfloop> <cfset scrobbler.Recent["Playlist"] = song_list> <cfset scrobbler.LastFetch["Playlist"] = Now()> <cfoutput> #scrobbler.Recent["Playlist"]# Updated #Dateformat(scrobbler.LastFetch["Playlist"],"M/DD")# #Timeformat(scrobbler.LastFetch["Playlist"],"h:MMtt")# </cfoutput> <cfelse> <cfset scrobbler.Recent["Playlist"] = "No recent tracks played"> <cfset scrobbler.LastFetch["Playlist"] = Now()> </cfif> </cfif> <cfcatch> <cfoutput>Service Unavailable</cfoutput> </cfcatch> </cftry> <cfsetting enablecfoutputonly=false>