Created
January 24, 2012 07:57
-
-
Save slant/1668755 to your computer and use it in GitHub Desktop.
Growl notifications for Pianobar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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:in
open'
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
Inspired by the work of Lucas McCoy found here:
http://blog.superuser.com/2011/04/26/listen-to-pandora-in-your-terminal-via-pianobar/#comment-2421