upnp_content_explorer 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab6a03172ad6faf495e4a04e7759640aea563d1f
|
4
|
+
data.tar.gz: c3511a497b1dcb9c1eb1d595fc27acd6c77f5336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ea6df8eabc42005accde92cfd74bf276784bdbb374d2b14cd159b69cb7304403d2b0d0710ce6c585f40446c826aa235fd6a53bd6e90f21c84a0a1ee4becb9d
|
7
|
+
data.tar.gz: fb640564b9274545fe4497d942d8e7280345df1dd3d798b39296d4ae187f8f8722c7380a160b78fd1b147d80d3df000cb71452c89ae7861bed408e494cfc93f9
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
1
3
|
require 'nokogiri'
|
2
4
|
require 'nori'
|
3
5
|
|
@@ -8,21 +10,32 @@ module UpnpContentExplorer
|
|
8
10
|
class PathNotFoundError < StandardError; end
|
9
11
|
|
10
12
|
class Explorer
|
11
|
-
|
13
|
+
attr_accessor :root
|
14
|
+
|
15
|
+
DEFAULT_OPTIONS = {
|
16
|
+
root_id: 0
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(service, options = {})
|
20
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
12
21
|
@service = service
|
13
|
-
@root =
|
22
|
+
@root = load_root_node(@options[:root_id])
|
14
23
|
end
|
15
24
|
|
16
|
-
def
|
25
|
+
def get(path)
|
17
26
|
find_terminal_node(prepare_path(path))
|
18
27
|
end
|
19
28
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
29
|
+
def root_path
|
30
|
+
path = []
|
31
|
+
current = @root
|
23
32
|
|
24
|
-
|
25
|
-
|
33
|
+
while !current.nil? && current.id != Node::ROOT_ID
|
34
|
+
path << current.title
|
35
|
+
current = load_root_node(current.parent_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
'/' << path.reverse.join('/')
|
26
39
|
end
|
27
40
|
|
28
41
|
def scrape(path)
|
@@ -57,6 +70,24 @@ module UpnpContentExplorer
|
|
57
70
|
find_terminal_node(path, child, next_traversed_path)
|
58
71
|
end
|
59
72
|
|
73
|
+
def load_root_node(id)
|
74
|
+
node = Node.new(id: id)
|
75
|
+
response = @service.Browse(
|
76
|
+
ObjectID: id,
|
77
|
+
BrowseFlag: 'BrowseMetadata',
|
78
|
+
Filter: '*',
|
79
|
+
StartingIndex: '0',
|
80
|
+
RequestedCount: '0'
|
81
|
+
)
|
82
|
+
|
83
|
+
node_xml = Nokogiri::XML(response[:Result])
|
84
|
+
node_xml.remove_namespaces!
|
85
|
+
node_data = parse_nori_node(node_xml.xpath('//DIDL-Lite/container'))
|
86
|
+
|
87
|
+
node.load!(node_data, false)
|
88
|
+
node
|
89
|
+
end
|
90
|
+
|
60
91
|
def get_node(node_id)
|
61
92
|
response = @service.Browse(
|
62
93
|
ObjectID: node_id,
|
@@ -66,7 +97,6 @@ module UpnpContentExplorer
|
|
66
97
|
RequestedCount: '0'
|
67
98
|
)
|
68
99
|
|
69
|
-
# Some UPnP servers (i.e., MediaTomb) screw up the namespacing
|
70
100
|
node_data = response[:Result].gsub('xmlns=', 'xmlns:didl=')
|
71
101
|
content = Nokogiri::XML(node_data)
|
72
102
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module UpnpContentExplorer
|
2
2
|
class Node
|
3
|
+
ROOT_ID = '0'
|
4
|
+
|
3
5
|
def initialize(data)
|
4
6
|
@data = data
|
5
7
|
end
|
@@ -14,13 +16,17 @@ module UpnpContentExplorer
|
|
14
16
|
super
|
15
17
|
end
|
16
18
|
|
17
|
-
def load!(data)
|
19
|
+
def load!(data, mark_loaded = true)
|
18
20
|
merged_data = @data.merge(data)
|
19
|
-
merged_data[:loaded?]
|
21
|
+
merged_data[:loaded?] ||= mark_loaded
|
20
22
|
|
21
23
|
@data = merged_data
|
22
24
|
end
|
23
25
|
|
26
|
+
def parent_id
|
27
|
+
@data[:parentID] || nil
|
28
|
+
end
|
29
|
+
|
24
30
|
def children
|
25
31
|
@data[:children].values || []
|
26
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upnp_content_explorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Mullins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nori
|