-
Notifications
You must be signed in to change notification settings - Fork 23
/
sonice.rb
executable file
·49 lines (41 loc) · 1.01 KB
/
sonice.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
require 'sinatra'
require 'haml'
$: << File.join(File.dirname(__FILE__), 'lib')
require './sonice/artist_image'
require './sonice/player'
require './sonice/players/itunes'
require './sonice/players/itunes_win'
require './sonice/players/mpd'
require './sonice/players/rhythmbox'
set :environment, ENV['RACK_ENV'] || :production
configure do
set :controls, ENV['SONICE_CONTROLS'] != '0'
$player = Sonice::Player.launched or abort "Error: no music player launched!"
puts "Connected to #{$player.name}"
end
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
post '/player' do
return if !settings.controls
params.each { |k, v| $player.send(k) if $player.respond_to?(k) }
if !request.xhr?
redirect '/'
end
end
get '/' do
@title = $player.track
@artist = $player.artist
@album = $player.album
@image_uri = Sonice::ArtistImage.new(@artist).uri
if request.xhr?
content_type :js
erb :indexjs
else
haml :index
end
end