Skip to content

Instantly share code, notes, and snippets.

@shenqi
Created February 22, 2012 01:22
Show Gist options
  • Save shenqi/1880424 to your computer and use it in GitHub Desktop.
Save shenqi/1880424 to your computer and use it in GitHub Desktop.
Notify Classic.fm #NowPlaying
#!/usr/bin/env ruby -Ku
require 'net/http'
require 'rubygems'
require 'nokogiri'
require 'meow'
$appname = 'Classic.fm'
$image = '/Applications/Play.app/Contents/Resources/Play.icns'
def growl(title, message)
growl = Meow.new($appname)
opt = { :icon => Meow.import_image($image), :sticky => 'true' }
growl.notify(title, message.chomp, opt) do
system("open 'http://www.classicfm.co.uk/on-air/playlist/#current_track'")
end
end
while 1 < 2
d = Nokogiri::HTML(Net::HTTP.get(URI("http://www.classicfm.co.uk/on-air/playlist/"))).xpath('id("current_track")')
pt ||= ''
title = d.xpath('.//span[@class="title"]').text
if pt == title then
sleep 180
else
dt, dd = [], []
d.xpath('.//div[@class="extra_info"]/dl/dt').each{|node| dt << node.children.text.strip}
d.xpath('.//div[@class="extra_info"]/dl/dd').each{|node| dd << node.children.text}
n = []
dt.slice(0..-3).each{|str| n << str.length}
n.map!{|num| n.sort.last - num + 1}
i = 0
info = ''
while i < dt.slice(0..-3).length
p n[i]
info << dt[i] + ' '*n[i] + dd[i] + "\n"
i += 1
end
growl(title, info)
pt = title
sleep(180)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment