<p>This plugin is a useful way of showing what you're listening to on your website. It's what runs the links on my front page and helps with the Amazon integration. To help, I've posted the code I use to parse the XML output. I've tried to comment it where appropriate. This was a quick 10 minute job, so anyone wanting to improve it is welcome, but it does the job for me ;)<br/>
<br/>
The plugin can be downloaded <a href="
http://brandon.fuller.name/archives/hacks/nowplaying/wmp/index.html"><font color="#ff0000">here</font></a> for either iTunes or Windows Media Player....<br/>
<br/>
<% <br/>
'--------------------------------------------------------<br/>
' Open music.xml....extract the artist/song etc information<br/>
'--------------------------------------------------------</p>
<p>file = server.mappath("music.xml")<br/>
Set fs = CreateObject("Scripting.FileSystemObject")<br/>
Set openfile = fs.OpenTextFile(file, 1, False)</p>
<p>'-------------------------------------------------------------------<br/>
'Code to get the last time a track was played by using the file timestamp<br/>
'-------------------------------------------------------------------<br/>
dim fs1, f11<br/>
set fs1=Server.CreateObject("Scripting.FileSystemObject")<br/>
set f11=fs1.GetFile(Server.MapPath("music.xml"))<br/>
Response.Write("The last track was played @ <b>" & f11.DateLastModified) & "</b><p><hr>"</p>
<p>'-------------------------------------------------------------------</p>
<p>'-------------------------------------------------------------------<br/>
'Set te variable to 0<br/>
'-------------------------------------------------------------------</p>
<p>SWplaycount=0<br/>
counter=0<br/>
SWimage = ""<br/>
SWtitle = ""<br/>
SWartist = ""<br/>
SWtrack = ""<br/>
SWalbum = ""<br/>
SWrating = ""</p>
<p> </p>
<p>'-------------------------------------------------------------------</p>
<p><br/>
do while not openfile.AtEndOfStream </p>
<p> counter=counter+1<br/>
thisline=openfile.readline<br/>
<br/>
'-------------------------------------------------------------------<br/>
' Read the data in from music.xml - each line is a new loop until file is fully read.<br/>
'-------------------------------------------------------------------</p>
<p><br/>
'response.write thisline & "<br>"</p>
<p> if instr(thisline,"<artist>") <> 0 and SWartist = "" then<br/>
SWartist = mid(thisline, instr(thisline,"<artist>") + 8, len(thisline))<br/>
'response.write "<BR>" & SWartist & "<BR>"<br/>
end if<br/>
<br/>
if instr(thisline,"<title>") <> 0 and SWtitle = "" then<br/>
SWtitle = mid(thisline, instr(thisline,"<title>") + 7, len(thisline))<br/>
'response.write "<BR>" & SWtitle & "<BR>"<br/>
end if</p>
<p> if instr(thisline,"<album>") <> 0 and SWalbum = "" then<br/>
'This small IF statement removes any Album details in square brackets (ie [UK Limited edition] as this is unlikely to be found on </p>
<p>amazon.<br/>
if instr(thisline,"[") <> 0 then<br/>
length = (instr(thisline,"[") - 17)<br/>
else<br/>
length = len(thisline)<br/>
end if<br/>
<br/>
SWalbum = mid(thisline, instr(thisline,"<album>") + 7, length)<br/>
'response.write "<BR>" & SWalbum & "<BR>"<br/>
end if </p>
<p> if instr(thisline,"<playcount>") <> 0 and SWplaycount = "" then<br/>
SWplaycount = replace(thisline, "</playcount>", "")<br/>
SWplaycount = Mid(SWplaycount,14,2)<br/>
'SWplaycount = replace(SWplaycount, char(9), "")<br/>
'response.write "<BR>sss" & SWplaycount & "<BR>"<br/>
end if </p>
<p> if instr(thisline,"<rating>") <> 0 and SWrating = "" then <br/>
SWrating = replace(thisline, "<rating>", "")<br/>
SWrating = replace(SWrating, "</rating>", "")<br/>
SWrating = replace(SWrating, chr(9), "")<br/>
'response.write "<BR>" & SWrating & "<BR>"<br/>
end if <br/>
<br/>
if instr(thisline,"<track>") <> 0 and SWtrack = "" then<br/>
SWtrack = mid(thisline, instr(thisline,"<track>"), len(thisline))<br/>
'response.write "<BR>" & SWtrack & "<BR>"<br/>
end if <br/>
<br/>
if instr(thisline,"<genre>") <> 0 and SWgenre = "" then<br/>
SWgenre = mid(thisline, instr(thisline,"<genre>"), len(thisline))<br/>
'response.write "<BR>" & SWgenre & "<BR>"<br/>
end if <br/>
<br/>
if instr(thisline,"<urlAmazon>") <> 0 and SWurlAmazon = "" then<br/>
SWurlAmazon = replace(thisline, "<urlAmazon>", "")<br/>
SWurlAmazon = replace(SWurlAmazon, "</urlAmazon>", "")<br/>
'response.write "<BR>" & SWurlAmazon & "<BR>"<br/>
end if <br/>
<br/>
if instr(thisline,"<imageLarge>") <> 0 and SWimage = "" then<br/>
SWimage = Replace(thisline, "<imageLarge>", "")<br/>
SWimage = Replace(SWimage, "</imageLarge>", "")<br/>
'response.write "<BR>" & SWimage & "<BR>"<br/>
SWimage = "<a href=""" & SWurlAmazon & """><img src=""" & SWimage & """</img><br>(Click to buy this from Amazon)</a>"</p>
<p> end if </p>
<p> '-------------------------------------------------------------------<br/>
' Does this line represent the end of info about a song - If so then write up and reset vars.<br/>
'-------------------------------------------------------------------</p>
<p> if instr(thisline,"</song>") <> 0 then <br/>
'A quick 2 line piece of code to number the songs...<br/>
songcount = songcount + 1<br/>
response.write "The last songs I've played...<b>#" & songcount & " </b><br>" </p>
<p> if SWimage <> "" then<br/>
response.write "<br>" & SWimage & ""<br/>
end if </p>
<p> response.write("<p><b>")<br/>
response.write SWtitle & "</b> by " <br/>
response.write (SWartist) <br/>
response.write("<p>This is track <b>" & SWtrack)<br/>
response.write("</b> from the album <b>" & SWalbum & "</b>.")<br/>
<br/>
response.write("<p>")</p>
<p> response.write "</b> <p>I have given this track a rating of <b>" <br/>
<br/>
if SWrating = "" then <br/>
response.write "Unrated" <br/>
else<br/>
response.write SWrating <br/>
end if<br/>
<br/>
response.write " out of 5 </b>and played the track <b>"<br/>
response.write cint(SWplaycount) + 1<br/>
response.write " </b> since 03/06. <p><hr>"</p>
<p> SWimage = ""<br/>
SWtitle = ""<br/>
SWartist = ""<br/>
SWtrack = ""<br/>
SWalbum = ""<br/>
SWrating = ""<br/>
SWurlAmazon = ""<br/>
SWplaycount = "0"</p>
<p> end if<br/>
loop<br/>
openfile.Close<br/>
set fs=nothing</p>
<p>' Tidy up, close of old objects.<br/>
set f11=nothing<br/>
set fs1=nothing <br/>
set xmlDoc = nothing<br/>
%><br/>
<hr><br/>
<iframe src="<a href="
http://rcm-uk.amazon.co.uk/e/cm?t=orangesteelor-21&o=2&p=27&l=qs1&f=ifr">
http://rcm-uk.amazon.co.uk/e/cm?t=orangesteelor-21&o=2&p=27&l=qs1&f=ifr</a>" width="165" height="150" frameborder="0" scrolling="no"></iframe></p>
<p> </p>