Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 235 lines (193 sloc) 5.62 KB
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
Bundler.setup
disable_dbus = ARGV.delete '--no-dbus'
disable_drb = ARGV.delete '--no-drb'
require 'drb' unless disable_drb
unless disable_dbus
begin
require File.join(File.dirname(__FILE__), 'dbus-interface')
rescue LoadError
disable_dbus = true
end
end
if ARGV.any?
if ARGV.delete 'nowplaying'
DRb.start_service
begin
client = DRbObject.new nil, 'druby://localhost:68739'
info = client.now_playing
if info
puts info.to_s
else
puts "No song is playing"
end
rescue DRb::DRbConnError
puts "Remora is not running"
end
exit
end
end
require 'rubygems'
require 'luck'
require File.join(File.dirname(__FILE__), 'grooveshark', 'client')
require File.join(File.dirname(__FILE__), 'grooveshark', 'user')
require File.join(File.dirname(__FILE__), 'grooveshark', 'playlist')
require File.join(File.dirname(__FILE__), 'grooveshark', 'song')
require File.join(File.dirname(__FILE__), 'mplayer')
require File.join(File.dirname(__FILE__), 'panes', 'login')
require File.join(File.dirname(__FILE__), 'panes', 'songinfo')
client = GrooveShark::Client.new
$session = client.session
client.use_aoss = true if ARGV.delete '--use-aoss'
run_dbus client unless disable_dbus
DRb.start_service 'druby://localhost:68739', client unless disable_drb
load File.join(File.dirname(__FILE__), 'mpd.rb')
Thread.new {
EventMachine.run {
EventMachine::start_server "0.0.0.0", 8000, Remora::MPDConnection, client
}
}
$display = display = client.display = Luck::Display.new(client)
trap 'INT' do
display.close
exit
end
begin
def show_login display
display.focus :login, :user
display[:login].show!
display.dirty! :login
end
display.pane :queue, 1, 1, 27, -15, 'Queue' do
control :songs, Luck::ListBox, 1, 1, -1, -1 do
number!
on_submit do |list, title| # TODO: Song is a String here, of just the title
index = list.data.index(title)
song = client.queue[index]
if client.now_playing
client.player.stop
end
Thread.new do
begin
client.queue.play_radio index
rescue => ex
display.close
puts ex.class, ex.message, ex.backtrace
exit
end
end
#~ next unless song.is_a? GrooveShark::Song
#~
#~ pane = Remora::SongInfoPane.new(display, song)
#~ display.pane :songinfo, pane
#~ display.modal = pane
#~ display[:songinfo, :close].focus!
end
end
end
display.pane :threads, 1, -15, 27, -1, 'Threads' do
control :list, Luck::ListBox, 1, 1, -1, -1 do
number!
end
end
Thread.new {
loop {
display[:threads, :list].data = Thread.list.map {|t| t.object_id }
display.dirty! :threads
sleep 1
}
}
display.pane :main, 27, 1, -1, -15, 'Search results' do
control :search, Luck::CommandBox, 2, 1, -2, 1 do
self.label = 'Search'
self.text = ''
focus!
end
control :results, Luck::ListBox, 1, 2, -1, -1 do
number!
end
end
display.pane :log, 27, -15, -1, -5, 'MPlayer Output' do
control :output, Luck::ListBox, 2, 1, -2, -1
end
display.pane :np, 27, -5, -1, -1, 'Now playing' do
control :song_name, Luck::Label, 1, 1, -1, 1 do
align :center
end
control :cue, Luck::DoubleProgressBar, 2, 2, -2, 3 do
template '==>-> '
end
control :position, Luck::Label, 1, 3, -1, 3
end
display[:main, :results].on_submit do |list, song|
next unless song.is_a? GrooveShark::Song
client.queue << song
unless client.now_playing
Thread.new do
begin
client.queue.play_radio
rescue => ex
display.close
puts ex.class, ex.message, ex.backtrace
exit
end
end
end
end
$results = nil
display[:main, :search].on_submit do |box, query|
next if query.empty?
if query.to_i.to_s == query && $results
index = query.to_i - 1
next if index < 0 || index > $results.size
song = $results[index]
client.queue << song
unless client.now_playing
Thread.new do
begin
client.queue.play_radio
rescue => ex
display.close
puts ex.class, ex.message, ex.backtrace
exit
end
end
end
elsif query =~ /^\/info ([0-9]+)$/ && $results
index = $1.to_i - 1
next if index < 0 || index > $results.size
song = $results[index]
pane = Remora::SongInfoPane.new(display, song)
display.pane :songinfo, pane
display.modal = pane
display[:songinfo, :close].focus!
elsif query == '/pause'
client.player && client.player.pause
elsif query == '/stop'
client.player && client.player.stop
elsif query == '/login'
show_login display
elsif query =~ /^\/player (.+)$/
client.player && client.player.process.puts($1)
elsif query =~ /^\/raw ([^ ]+) ([^ ]+) (.*)$/
$results = nil
display[:main, :results].data = client.request($1, $2, eval($3)).inspect.lines.to_a.map{|l| l.chomp}
display[:main].title = "Results for #{$2} to #{$1}"
display.dirty! :main
else
$results = client.search_songs(query)
display[:main, :results].data = $results
display[:main].title = "Search Results for #{query}"
display.dirty! :main
end
end
display.pane :login, Remora::LoginPane.new(display)
#display.pane :songinfo, Remora::SongInfoPane.new(display)
display.handle while sleep 0.01
rescue => ex
display.close
puts ex.class, ex.message, ex.backtrace
exit
end