Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Growl notifications for Pianobar
#!/usr/bin/ruby
require 'open-uri'
require 'tempfile'
def cover_art url
extname = File.extname(url)
basename = File.basename(url, extname)
file = Tempfile.new([basename, extname])
file.binmode
open(URI.parse(url)) { |data| file.write data.read }
file
end
trigger = ARGV.shift
if trigger == 'songstart'
# Get current song information
songinfo = {}
STDIN.each_line { |line| songinfo.store(*line.chomp.split('=', 2)) }
# Grab cover art and send growl notification
image = cover_art(songinfo['coverArt'])
`growlnotify -t "Pianobar: Now Playing" -m "#{songinfo['title']}\nby #{songinfo['artist']}" --image "#{image.path}"`
# Clean up cover art temp file
image.unlink
image.close
end
@slant
Copy link
Author

slant commented Jan 24, 2012

@smartwatermelon
Copy link

smartwatermelon commented Jan 3, 2013

If there's no album art:

|> "Undo The Silence" by "Pulser" on "Miami Trance Anthems" <3
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:32:in open_uri_original_open': can't convert URI::Generic into String (TypeError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:32:inopen'
from /Users/andrewrich/.config/pianobar/eventcmd.d/pianobar-notify.rb:11:in `cover_art'
from /Users/andrewrich/.config/pianobar/eventcmd.d/pianobar-notify.rb:22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment