forked from pipt/viera_play
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
require "viera_play/tv" | ||
require "viera_play/soapy" | ||
require "viera_play/player" | ||
require "viera_play/scanner" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |