-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrasdio-alarm.rb
47 lines (34 loc) · 857 Bytes
/
rasdio-alarm.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
require 'sinatra'
require 'erb'
set :bind, '0.0.0.0'
get '/' do
" Hello "
# "hello from #{`uname -a`} <br> #{`mpc`}"
end
get '/index' do
# stations = [{:name => 'Lohro 90,2', :active => true},
# { :name => 'FluxFM', :active => false },
# { :name => 'NPR Berlin', :active => false },
# { :name => 'Fritz', :active => false }]
stations = []
`mpc playlist`.split('\n').each do |name|
playlist.push({:name => name, :active => false})
end
erb :index, :locals => {:stations => stations}
end
get '/stop' do
`mpc stop`
end
get '/play' do
`mpc play`
end
# the mpd playlist directory is /var/lib/mpd/playlists
# you need sudo powers to write there though - weird
post '/add' do
url = params[:url]
end
post '/controls' do
action = params[:action]
# this is bad and needs to be filtered!
`mpc #{action}`
end