Created
April 3, 2009 18:50
-
-
Save kuzux/89894 to your computer and use it in GitHub Desktop.
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 'rubygems' | |
require 'open-uri' | |
require 'cgi' | |
require 'hpricot' | |
require 'id3lib' | |
require 'dbus' | |
def lyrics(title,artist) | |
url = "http://lyricwiki.org/#{artist}:#{title}" | |
file = Hpricot(open(url)) | |
div = (file/".lyricbox")[0] | |
begin | |
[div.innerHTML.gsub(/\<br \/\>/,"\n").gsub(/<(.|\n)*?>/,""), url] | |
rescue | |
puts "No lyrics found" | |
[nil,nil] | |
end | |
end | |
def escape x | |
CGI.escape(x).gsub(/\+(\w)/){|m| "_" + m[1].chr.upcase}.sub(/(\w)/){|m| m.upcase} | |
end | |
def main | |
bus = DBus::SessionBus.instance | |
proxy = bus.introspect("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")["org.gnome.Rhythmbox.Player"] | |
paths = proxy.getPlayingUri | |
paths.each do |path| | |
path = CGI.unescape(path).gsub(/file:\/\//,"") | |
tag = ID3Lib::Tag.new(path) | |
artist,title = escape(tag.artist), escape(tag.title) | |
ly, url = lyrics title, artist | |
puts "\033[1m\e[01;33m#{tag.artist}-#{tag.title}\e[00m\033[0m" | |
puts ly | |
puts "\e[01;36mLyrics fetched from #{url}\e[00m" | |
end | |
end | |
main if __FILE__ == $0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment