Skip to content

Instantly share code, notes, and snippets.

@agarrharr
Created December 11, 2014 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agarrharr/c53143b1541c6d54ce0b to your computer and use it in GitHub Desktop.
Save agarrharr/c53143b1541c6d54ce0b to your computer and use it in GitHub Desktop.
Save Pianobar songs to firebase and file

Here are some scripts that can be used with pianobar

brew install pianobar

You'll also need the firebase gem if you want to save to firebase

gem install firebase

You'll need to modify the firebase url and the paths

#!/usr/bin/ruby
require 'cgi'
trigger = ARGV.shift
if trigger == 'songstart'
songinfo = {}
STDIN.each_line { |line| songinfo.store(*line.chomp.split('=', 2))}
File.open('/Users/adamharris/.config/pianobar/nowplaying', 'w') do |f2|
f2.puts "#{songinfo['artist']}\n#{songinfo['album']}\n#{songinfo['title']}"
end
system("ruby pianobarFirebase.rb")
end
#!/usr/bin/ruby
require 'cgi'
trigger = ARGV.shift
if trigger == 'songstart'
songinfo = {}
STDIN.each_line { |line| songinfo.store(*line.chomp.split('=', 2))}
File.open('/Users/adamharris/.config/pianobar/nowplaying', 'w') do |f2|
f2.puts "#{songinfo['artist']}\n#{songinfo['album']}\n#{songinfo['title']}"
end
system("ruby pianobarFirebase.rb")
end
#!/usr/bin/ruby
require 'cgi'
require 'firebase'
title = ""
artist = ""
album = ""
flag = ARGV[0]
counter = 1
file = File.new('/Users/adamharris/.config/pianobar/nowplaying', 'r')
while (line = file.gets)
if counter == 1
artist = line
end
if counter == 2
album = line
end
if counter == 3
title = line
end
counter = counter + 1
end
base_uri = 'https://blazing-fire-5020.firebaseio.com/'
firebase = Firebase::Client.new(base_uri)
firebase.push("songs", { :artist => artist, :title => title, :album => album})
#!/usr/bin/ruby
title = ""
artist = ""
album = ""
flag = ARGV[0]
counter = 1
file = File.new('/Users/adamharris/.config/pianobar/nowplaying', 'r')
while (line = file.gets)
if counter == 1
artist = line
end
if counter == 2
album = line
end
if counter == 3
title = line
end
counter = counter + 1
end
if flag == "--notification" || flag == "-n"
`terminal-notifier -message "Artist: #{artist}\rAlbum: #{album}" -title "#{title}"`
else
puts "Song: #{title}\rArtist: #{artist}\rAlbum: #{album}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment