Skip to content

Commit

Permalink
Let me scan for servers.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlea committed May 12, 2013
1 parent 9da284d commit 36ea845
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
20 changes: 16 additions & 4 deletions bin/viera_play
Expand Up @@ -2,7 +2,19 @@

require "viera_play"

VieraPlay::Player.new(
:tv_control_url => ENV["TV_CONTROL_URL"],
:file_path => ARGV.first
).call
case ARGV.first
when nil
STDERR.puts "Usage:"
STDERR.puts "# Play a file:\n\t#{$0} [FILENAME]"
STDERR.puts "# List available servers:\n\t#{$0} -l"
exit 1
when '-l'
VieraPlay::Scanner.services.each do |name, url|
puts "#{name}\t#{url}"
end
else
VieraPlay::Player.new(
:tv_control_url => ENV["TV_CONTROL_URL"],
:file_path => ARGV.first
).call
end
1 change: 1 addition & 0 deletions lib/viera_play.rb
Expand Up @@ -2,3 +2,4 @@
require "viera_play/tv"
require "viera_play/soapy"
require "viera_play/player"
require "viera_play/scanner"
40 changes: 40 additions & 0 deletions lib/viera_play/scanner.rb
@@ -0,0 +1,40 @@
require 'upnp/ssdp'
require 'nokogiri'
require 'open-uri'
require 'uri'

UPnP.log=false

class VieraPlay::Scanner
def self.services
@instance ||= new
@instance.services
end

def services
services = UPnP::SSDP.search(service_type)
locations = services.map{|v| v[:location] }.uniq
locations.inject(Hash.new){ |acc, location|
acc.merge(fetch_and_parse_service_description(location))
}
end

protected

def service_type
'urn:schemas-upnp-org:service:AVTransport:1'
end

def fetch_and_parse_service_description(service_description_url)
Nokogiri::XML(open(service_description_url))
services = doc.css('service')
rendering_controller_services = services.select{|service|
service.css('serviceType').text == service_type
}
rendering_controller_services.map{|service|
control_path = service.css('controlURL').text
control_url = URI.join(service_description_url, control_path)
{ doc.css('friendlyName').text => control_url }
}
end
end

0 comments on commit 36ea845

Please sign in to comment.