<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>libcoffee.net: Audioscrobbler sidebar, fixed?</title>
    <link>http://www.libcoffee.net/articles/2007/03/19/audioscrobbler-sidebar-fixed</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>:: Just another Typo weblog ::</description>
    <item>
      <title>Audioscrobbler sidebar, fixed?</title>
      <description>&lt;p&gt;Tried making changes to the Audioscrobbler (aka &lt;a href="http://last.fm"&gt;Last.fm&lt;/a&gt;) sidebar plugin that never seemed to show up. Changed it in the sidebars admin to use the new &lt;span class="caps"&gt;API 1&lt;/span&gt;.0 xml feeds, and then the .rb file so it can parse the feed XPath correctly (As a side note, debugging Typo sidebar plugins is &lt;i&gt;hard&lt;/i&gt;, no output text, any exceptions thrown simply makes it not rendered. Blah, the world needs a better plugin architecture. :p). And then it worked! Woot.&lt;/p&gt;


Posting code changes for &lt;i&gt;&lt;span class="caps"&gt;TYPO&lt;/span&gt;_HOME/vendor/plugins/audioscrobbler_sidebar/audioscrobbler.rb&lt;/i&gt;:
&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;// we're replacing this procedure here
def parse(body)

    xml = Document.new(body)
    self.items        = []
    self.link = &amp;quot;http://last.fm&amp;quot; // not really used
    self.title = &amp;quot;Recent Music&amp;quot;  // title of sidebar box

    XPath.each(xml, &amp;quot;//track/&amp;quot;) do |elem|
    item = AudioscrobblerItem.new
      item.title       = XPath.match(elem, &amp;quot;name/text()&amp;quot;).to_s
      item.artist       = XPath.match(elem, &amp;quot;artist/text()&amp;quot;).to_s
      item.link        = XPath.match(elem, &amp;quot;url/text()&amp;quot;).to_s
      item.date        = Time.mktime(*ParseDate.parsedate(XPath.match(elem, &amp;quot;date/text()&amp;quot;).to_s))
      items &amp;amp;lt;&amp;amp;lt; item
    end

    self.items = items.sort_by { |item| item.date }.reverse
  end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
It still doesn&amp;#8217;t seem to refresh though. Hmm. :S</description>
      <pubDate>Mon, 19 Mar 2007 11:38:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:cc8d1e69-f22b-4d4a-bd95-c57b51fd8e07</guid>
      <author>zanglang@gmail.com (Jerry)</author>
      <link>http://www.libcoffee.net/articles/2007/03/19/audioscrobbler-sidebar-fixed</link>
      <category>Code</category>
      <trackback:ping>http://www.libcoffee.net/articles/trackback/245</trackback:ping>
    </item>
  </channel>
</rss>
