=begin AUTHOR: Kesiev WHAT IT DOES: Thanks to the LyricWiki APIs, you can sing along your songs. The lyrics changes while the music is playing. =end # The menu entry and LyricWiki homepage on help $menus<<{ :menu=>:song, :label=>"Lyricwiki window", :action=>Proc.new { lyricwiki_lookup } } << { :menu=>:help, :label=>"Lyricwiki homepage", :action=>Proc.new { surf("http://lyricwiki.org/Main_Page")} } # Lyricwiki window pointer and last lyric $lyricwiki_window=nil $lyricwiki_lp=nil # Show the lyricwiki window def lyricwiki_lookup if !$lyricwiki_window then $lyricwiki_window = Gtk::Window.new $lyricwiki_window.title="Lyricwiki" $lyricwiki_window.set_default_size(300,400) $lyricwiki_window.add(box=Gtk::VBox.new(false,5)) box.pack_start($lyricwiki_text=Gtk::Label.new,false,true) box.pack_start(boxit(Gtk::TextView.new($lyricwiki_lyric=Gtk::TextBuffer.new).set_editable(false)),true,true) $lyricwiki_window.signal_connect("destroy") { $lyricwiki_window=nil } $lyricwiki_window.show_all $lyricwiki_window.show # Since is recreated, the lyric have to be downloaded again $lyricwiki_lp="" end # Updates the lyric window lyricwiki_update end # When the song is notified, new lyrics are downloaded. alias lyricwiki_notify notify def notify(me) if $player.state[0]==:play then lyricwiki_update end lyricwiki_notify(me) end # Make a unique key used for download the lyrics only once, if the last song # is played multiple times (or when paused and replayed) def lyricwiki_makelp "#{$player.meta[:title]}#{$player.meta[:artist]}#{$player.meta[:album]}" end # Call lyricwiki and updates the window def lyricwiki_update if $lyricwiki_window && $player.meta[:title]!= $opt[:unknown] && $player.meta[:artist]!= $opt[:unknown] && $lyricwiki_lp!=lyricwiki_makelp then $lyricwiki_lp=lyricwiki_makelp $lyricwiki_text.markup="\n#{$player.meta[:title]}\n#{$player.meta[:artist]} - #{$player.meta[:album]}\n" $lyricwiki_lyric.text="" open("http://lyricwiki.org/api.php?func=getSong&artist=%s&song=%s&fmt=text" % [URI.escape($player.meta[:artist]),URI.escape($player.meta[:title])],"r") { |f| f.each { |line| $lyricwiki_lyric.text+=line.strip+"\n" } } end end