-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwav_head.rb
executable file
·44 lines (42 loc) · 1.31 KB
/
wav_head.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
#!/usr/bin/env ruby
require 'optparse'
require 'sinatra/base'
require_relative './lib/db'
require_relative './lib/wav_head_player'
require_relative './lib/wav_head_info'
require_relative './lib/wav_head_server'
require_relative './lib/wav_head_vote_manager'
opts = {}
OptionParser.new do |o|
o.banner = "Usage: wav_head.rb [options]"
o.on("-s", "--server", "Run a server") do |v|
opts[:server] = true
end
o.on("-p", "--port PORT", Integer, "Run on a specific port") do |p|
opts[:port] = p
end
o.on("-i", "--index [DIR]", "Index a directory") do |i|
opts[:index] = i
end
o.on("-l", "--list", "List all songs") do |l|
opts[:list] = true
end
o.on("-d", "--delete", "Delete the database") do |d|
opts[:delete] = true
end
end.parse!
WavHead::Info.setup(opts[:index]) if opts[:index]
puts WavHead::Info.pretty_print if opts[:list]
WavHead::Info.delete! if opts[:delete]
if opts[:server]
puts "Starting a server..."
require 'yaml'
WavHead::Server.set :p, WavHead::Player.new
config = YAML.load_file "config.yml"
WavHead::Server.set :votemanager, WavHead::VoteManager.new(config)
puts WavHead::Server.settings.votemanager.inspect
WavHead::Server.settings.p.start!
WavHead::Server.set :port, opts[:port] if opts[:port]
WavHead::Server.set :bind, "0.0.0.0"
WavHead::Server.run!
end