Skip Navigation Links
Skip navigation links
Blog
BadBrother
Fun Stuff
Learning
Webcams
Email
About
OSv3 Portal Topics: Brandon Fuller - Now playing plugin

T_SUBJECT

Brandon Fuller - Now playing plugin 

CAT_ID

FORUM_ID

TOPIC_ID

129 

T_STATUS

T_MAIL

T_MESSAGE

<p>This plugin is a useful way of showing what you're listening to on your website.&nbsp; It's what runs the links on my front page and helps with the Amazon integration.&nbsp; To help, I've posted the code I use to parse the XML output.&nbsp; I've tried to comment it where appropriate.&nbsp; 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/>
&lt;% <br/>
'--------------------------------------------------------<br/>
' Open music.xml....extract the artist/song etc information<br/>
'--------------------------------------------------------</p>
<p>file = server.mappath(&quot;music.xml&quot;)<br/>
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)<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(&quot;Scripting.FileSystemObject&quot;)<br/>
set f11=fs1.GetFile(Server.MapPath(&quot;music.xml&quot;))<br/>
Response.Write(&quot;The last track was played @ &lt;b&gt;&quot; &amp; f11.DateLastModified) &amp; &quot;&lt;/b&gt;&lt;p&gt;&lt;hr&gt;&quot;</p>
<p>'-------------------------------------------------------------------</p>
<p>'-------------------------------------------------------------------<br/>
'Set te variable to 0<br/>
'-------------------------------------------------------------------</p>
<p>SWplaycount=0<br/>
counter=0<br/>
&nbsp;&nbsp;&nbsp;SWimage = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWtitle = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWartist = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWtrack = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWalbum = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWrating = &quot;&quot;</p>
<p>&nbsp;</p>
<p>'-------------------------------------------------------------------</p>
<p><br/>
do&nbsp; while not openfile.AtEndOfStream </p>
<p>&nbsp;&nbsp; &nbsp;&nbsp;counter=counter+1<br/>
&nbsp; &nbsp;&nbsp;thisline=openfile.readline<br/>
&nbsp; &nbsp;&nbsp;<br/>
&nbsp;&nbsp;'-------------------------------------------------------------------<br/>
&nbsp;&nbsp;' Read the data in from music.xml - each line is a new loop until file is fully read.<br/>
&nbsp;&nbsp;'-------------------------------------------------------------------</p>
<p><br/>
&nbsp; &nbsp;&nbsp;'response.write thisline &amp; &quot;&lt;br&gt;&quot;</p>
<p>&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;artist&gt;&quot;) &lt;&gt; 0 and SWartist = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWartist = mid(thisline, instr(thisline,&quot;&lt;artist&gt;&quot;) + 8, len(thisline))<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWartist &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if<br/>
&nbsp;&nbsp; &nbsp;&nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;title&gt;&quot;) &lt;&gt; 0 and SWtitle = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWtitle = mid(thisline, instr(thisline,&quot;&lt;title&gt;&quot;) + 7, len(thisline))<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWtitle &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if</p>
<p>&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;album&gt;&quot;) &lt;&gt; 0 and SWalbum = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'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/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if instr(thisline,&quot;[&quot;) &lt;&gt; 0 then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;length = (instr(thisline,&quot;[&quot;) - 17)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;length = len(thisline)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end if<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWalbum = mid(thisline, instr(thisline,&quot;&lt;album&gt;&quot;) + 7, length)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWalbum &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp;</p>
<p>&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;playcount&gt;&quot;) &lt;&gt; 0 and SWplaycount = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWplaycount = replace(thisline, &quot;&lt;/playcount&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWplaycount = Mid(SWplaycount,14,2)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'SWplaycount = replace(SWplaycount, char(9), &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'response.write &quot;&lt;BR&gt;sss&quot; &amp; SWplaycount &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp;</p>
<p>&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;rating&gt;&quot;) &lt;&gt; 0 and SWrating = &quot;&quot; then&nbsp;&nbsp; &nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SWrating = replace(thisline, &quot;&lt;rating&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWrating = replace(SWrating, &quot;&lt;/rating&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWrating = replace(SWrating, chr(9), &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWrating &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp;<br/>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;track&gt;&quot;) &lt;&gt; 0 and SWtrack = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWtrack = mid(thisline, instr(thisline,&quot;&lt;track&gt;&quot;), len(thisline))<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWtrack &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp; <br/>
&nbsp;&nbsp; &nbsp;&nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;genre&gt;&quot;) &lt;&gt; 0 and SWgenre = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWgenre = mid(thisline, instr(thisline,&quot;&lt;genre&gt;&quot;), len(thisline))<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWgenre &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp; <br/>
&nbsp;&nbsp; &nbsp;&nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;urlAmazon&gt;&quot;) &lt;&gt; 0 and SWurlAmazon = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWurlAmazon = replace(thisline, &quot;&lt;urlAmazon&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWurlAmazon = replace(SWurlAmazon, &quot;&lt;/urlAmazon&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWurlAmazon &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp;&nbsp;&nbsp; &nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;if instr(thisline,&quot;&lt;imageLarge&gt;&quot;) &lt;&gt; 0 and SWimage = &quot;&quot; then<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;SWimage =&nbsp; Replace(thisline, &quot;&lt;imageLarge&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;SWimage =&nbsp; Replace(SWimage, &quot;&lt;/imageLarge&gt;&quot;, &quot;&quot;)<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;'response.write &quot;&lt;BR&gt;&quot; &amp; SWimage&nbsp; &amp; &quot;&lt;BR&gt;&quot;<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;SWimage = &quot;&lt;a href=&quot;&quot;&quot; &amp; SWurlAmazon &amp; &quot;&quot;&quot;&gt;&lt;img src=&quot;&quot;&quot; &amp; SWimage &amp; &quot;&quot;&quot;&lt;/img&gt;&lt;br&gt;(Click to buy this from Amazon)&lt;/a&gt;&quot;</p>
<p>&nbsp;&nbsp; &nbsp;&nbsp;end if&nbsp;</p>
<p>&nbsp;&nbsp;'-------------------------------------------------------------------<br/>
&nbsp;&nbsp;' Does this line represent the end of info about a song - If so then write up and reset vars.<br/>
&nbsp;&nbsp;'-------------------------------------------------------------------</p>
<p>&nbsp;&nbsp;if instr(thisline,&quot;&lt;/song&gt;&quot;) &lt;&gt; 0 then&nbsp;&nbsp; <br/>
&nbsp;&nbsp;&nbsp;'A quick 2 line piece of code to number the songs...<br/>
&nbsp;&nbsp;&nbsp;songcount = songcount + 1<br/>
&nbsp;&nbsp;&nbsp;response.write &quot;The last songs I've played...&lt;b&gt;#&quot; &amp; songcount &amp; &quot; &lt;/b&gt;&lt;br&gt;&quot;&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;if SWimage &lt;&gt; &quot;&quot; then<br/>
&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;&lt;br&gt;&quot; &amp; SWimage &amp; &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;end if&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;response.write(&quot;&lt;p&gt;&lt;b&gt;&quot;)<br/>
&nbsp;&nbsp;&nbsp;response.write SWtitle &amp; &quot;&lt;/b&gt; by &quot; <br/>
&nbsp;&nbsp;&nbsp;response.write (SWartist) <br/>
&nbsp;&nbsp;&nbsp;response.write(&quot;&lt;p&gt;This is track &lt;b&gt;&quot; &amp; SWtrack)<br/>
&nbsp;&nbsp;&nbsp;response.write(&quot;&lt;/b&gt; from the album &lt;b&gt;&quot; &amp; SWalbum &amp; &quot;&lt;/b&gt;.&quot;)<br/>
&nbsp;<br/>
&nbsp;&nbsp;&nbsp;response.write(&quot;&lt;p&gt;&quot;)</p>
<p>&nbsp;&nbsp;&nbsp;response.write &quot;&lt;/b&gt;&nbsp; &lt;p&gt;I have given this track a rating of &lt;b&gt;&quot; <br/>
&nbsp;<br/>
&nbsp;&nbsp;&nbsp;if SWrating = &quot;&quot; then <br/>
&nbsp;&nbsp;&nbsp;&nbsp;response.write &quot;Unrated&quot; <br/>
&nbsp;&nbsp;&nbsp;else<br/>
&nbsp;&nbsp;&nbsp;&nbsp;response.write SWrating <br/>
&nbsp;&nbsp;&nbsp;end if<br/>
&nbsp;<br/>
&nbsp;&nbsp;&nbsp;response.write &quot; out of 5 &lt;/b&gt;and played the track &lt;b&gt;&quot;<br/>
&nbsp;&nbsp;&nbsp;response.write cint(SWplaycount) + 1<br/>
&nbsp;&nbsp;&nbsp;response.write &quot; &lt;/b&gt; since 03/06.&nbsp; &lt;p&gt;&lt;hr&gt;&quot;</p>
<p>&nbsp;&nbsp;&nbsp;SWimage = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWtitle = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWartist = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWtrack = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWalbum = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWrating = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWurlAmazon = &quot;&quot;<br/>
&nbsp;&nbsp;&nbsp;SWplaycount = &quot;0&quot;</p>
<p>&nbsp; &nbsp;&nbsp;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/>
%&gt;<br/>
&lt;hr&gt;<br/>
&lt;iframe src=&quot;<a href="http://rcm-uk.amazon.co.uk/e/cm?t=orangesteelor-21&amp;o=2&amp;p=27&amp;l=qs1&amp;f=ifr">http://rcm-uk.amazon.co.uk/e/cm?t=orangesteelor-21&amp;o=2&amp;p=27&amp;l=qs1&amp;f=ifr</a>&quot; width=&quot;165&quot; height=&quot;150&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;</p>
<p>&nbsp;</p>

T_REPLIES

T_VIEW_COUNT

429 

T_LAST_POST

20061018232823 

T_DATE

20061018232823 

T_LAST_POSTER

T_IP

192.168.0.23 

T_LAST_POST_AUTHOR

T_MSGICON

T_INPLACE

T_POLL

T_NEWS

T_SIG

Attachments
Created at 3/26/2009 12:01 AM  by Simon Salmon 
Last modified at 3/26/2009 12:01 AM  by Simon Salmon