Audioscrobbler sidebar, fixed?
Posted by Jerry Mon, 19 Mar 2007 01:38:00 GMT
Tried making changes to the Audioscrobbler (aka Last.fm) sidebar plugin that never seemed to show up. Changed it in the sidebars admin to use the new API 1.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 hard, 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.
Posting code changes for TYPO_HOME/vendor/plugins/audioscrobbler_sidebar/audioscrobbler.rb:// we're replacing this procedure here
def parse(body)
xml = Document.new(body)
self.items = []
self.link = "http://last.fm" // not really used
self.title = "Recent Music" // title of sidebar box
XPath.each(xml, "//track/") do |elem|
item = AudioscrobblerItem.new
item.title = XPath.match(elem, "name/text()").to_s
item.artist = XPath.match(elem, "artist/text()").to_s
item.link = XPath.match(elem, "url/text()").to_s
item.date = Time.mktime(*ParseDate.parsedate(XPath.match(elem, "date/text()").to_s))
items << item
end
self.items = items.sort_by { |item| item.date }.reverse
end



