Trampoline Systems

* Trampoline Description Here

Trampoline Systems

* Trampoline Description Here


Content

Machines

Ideas, thoughts and observations from Trampoline's technical brains

jan

growl-lastfm

By Jan Berkel on July 10th, 2007

We use last.fm a lot in the office - but one thing I always found annoying was that there’s no easy way to find out what’s currently playing (you need to go to the web page and hit refresh, very distracting) so I knocked up a little ruby script which uses growl to display the currently playing song.


#!/usr/bin/env ruby
require ‘rubygems’
require ‘ruby-growl’
require ‘hpricot’
require ‘cgi’
require ‘open-uri’

raise “#{$0} <user>” if ARGV.empty?
user = ARGV[0]
already_notified = []

while true do
now_listening = Hpricot(open(“http://www.last.fm/user/#{user}”))/“.nowListening td.subject”
unless now_listening.empty?
currently_played = now_listening.last.inner_text.strip
unless already_notified.include?(currently_played)
already_notified << currently_played
g = Growl.new(“localhost”, “ruby-growl”, ["ruby-growl Notification"])
g.notify(“ruby-growl Notification”, “#{user} is listening to”,
CGI::unescapeHTML(currently_played))
end
end
sleep 60
end

Make sure that you have hpricot and ruby-growl installed (gem install hpricot ruby-growl -y), then copy and paste the script (or download it) and start it with a last.fm username as parameter. You also need to have “Listen for incoming notifications” and “Allow remote registration” checked in growl’s preferences (System Preferences | Growl | Network).

5 Responses to “growl-lastfm”

  1. caroline Says:

    i just downloaded the newest version of last.fm and looked in the preferences, and have no idea what Growl is?? help?

  2. martind Says:

    Or you could go to Last.fm preferences -> growl -> send notification to growl when a new track starts :)

  3. jan Says:

    right, but i want to get notification for songs someone else is playing :)

  4. martind Says:

    ah, right. office with shared music setup. didn’t think of that — great idea!

  5. bryan Says:

    To get this to work with the new layout of last.fm, change the following line:

    now_listening = Hpricot(open(“http://www.last.fm/user/#{user}”))/“.nowListening td.subject”

    to:

    now_listening = Hpricot(open(“http://www.last.fm/user/#{user}”))/“td.featuredTrack”

Leave a comment