forked from seattlerb/upnp-mediaserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_server.rb
76 lines (55 loc) · 2 KB
/
media_server.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'rubygems'
require 'UPnP/device'
require 'UPnP/service/content_directory'
require 'UPnP/service/connection_manager'
##
# A UPnP MediaServer. See upnp.org for specifications.
class UPnP::Device::MediaServer < UPnP::Device
VERSION = '1.0.0'
add_service_id UPnP::Service::ContentDirectory, 'ContentDirectory'
add_service_id UPnP::Service::ConnectionManager, 'ConnectorManager'
##
# Adds directory and name options.
def self.option_parser
super do |option_parser, options|
options[:directories] = []
options[:name] = Socket.gethostname.split('.', 2).first
option_parser.banner = <<-EOF
Usage: #{option_parser.program_name} [options]
Starts a UPnP media server. If no directories are given, serves content in
the current directory.
EOF
option_parser.separator ''
option_parser.on('-d', '--directory=DIRECTORY',
'Expose a directory to the media server') do |value|
options[:directories] << value
end
option_parser.on('-n', '--name=NAME',
'Set the MediaServer\'s name') do |value|
options[:name] = value
end
end
end
##
# Runs a MediaServer. Automatically adds the current directory if no
# directories were specified.
def self.run(argv = ARGV)
super
@options[:directories] << Dir.pwd if @options[:directories].empty?
device = create 'MediaServer', @options[:name] do |ms|
ms.manufacturer = 'Seattle Ruby Brigade'
ms.manufacturer_url = 'http://seattlerb.org'
ms.model_description = "Ruby Media Server version #{ms.class::VERSION}"
ms.model_name = 'Ruby Media Server'
ms.model_url = 'http://seattlerb.org/UPnP-MediaServer'
ms.model_number = UPnP::Device::MediaServer::VERSION
ms.add_service 'ContentDirectory' do |cd|
@options[:directories].each do |directory|
cd.add_directory directory
end
end
ms.add_service 'ConnectionManager'
end
device.run
end
end