forked from sunny/so-nice
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.rb
53 lines (45 loc) · 1.14 KB
/
app.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
49
50
51
52
53
#!/usr/bin/env ruby
require 'sinatra'
require 'haml'
require 'lib/musicplayer'
require 'lib/videoplayer'
Dir[File.dirname(__FILE__) + '/lib/players/*'].each { |f| require f }
configure do
$musicplayer = MusicPlayer.launched or abort "Error: no music player launched!"
$videoplayer = VideoPlayer.launched or abort "Error: no video player launched!"
end
get '/' do
haml :index
end
get '/music' do
@title = $musicplayer.current_track
@artist = $musicplayer.current_artist
@album = $musicplayer.current_album
haml :music
end
get '/videos' do
@videos = Dir.glob('*').select { |file| File.directory?(file) }
Dir.glob('*.avi').each { |file| @videos << file }
@videos << ".."
@videos.sort!
haml :videos
end
post '/musicplayer' do
params.each { |k, v| $musicplayer.send(k) if $musicplayer.respond_to?(k) }
redirect '/music'
end
post '/videoplayer' do
params.each do |k, v|
if k == "play_file"
if File.directory?(v)
Dir.chdir(v)
redirect '/videos'
else
$videoplayer.send(k, v)
end
else
$videoplayer.send(k) if $videoplayer.respond_to?(k)
end
end
redirect '/videos'
end