upnp_content_explorer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/upnp_content_explorer/explorer.rb +5 -4
- data/lib/upnp_content_explorer/item.rb +23 -9
- data/lib/upnp_content_explorer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dad4e9e6f0e15f60e68da4211f9a4fafa6f2664
|
4
|
+
data.tar.gz: 7d6f4bebfc9121071f0ffd016e841dc7f7b6dde3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba264790a78cda569421a5619cdb7cd49f840357da1345908b3f4aa3c1be889f45bd37f7274fdc6c8de6d5b48be972beea3e872caf84021c16dab95976288339
|
7
|
+
data.tar.gz: c20dfd6806f82f75cf1f621b88061a7d02c644a599405443de8b6fae1f5b5e68c9b556e62ef826bf1c400bb03a778d128817c04c40105336a17a4768892d2c55
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ You can then do the following:
|
|
34
34
|
### Get the contents of a directory
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
node = explorer.
|
37
|
+
node = explorer.get('/Movies')
|
38
38
|
|
39
39
|
node.children.map(&:title)
|
40
40
|
# => ["Comedy", "Horror", "Suspense"]
|
@@ -45,7 +45,7 @@ node.items.map(&:title)
|
|
45
45
|
|
46
46
|
### List the children of a directory
|
47
47
|
```ruby
|
48
|
-
children = explorer.
|
48
|
+
children = explorer.get('/Movies').children
|
49
49
|
|
50
50
|
children.map(&:title)
|
51
51
|
# => ["Comedy", "Horror", "Suspense"]
|
@@ -53,7 +53,7 @@ children.map(&:title)
|
|
53
53
|
|
54
54
|
### List the files inside of a directory
|
55
55
|
```ruby
|
56
|
-
items = explorer.
|
56
|
+
items = explorer.get('/Movies').items
|
57
57
|
|
58
58
|
items.map(&:title)
|
59
59
|
# => ["Inside Out (2015).mkv"]
|
@@ -63,10 +63,21 @@ items.map(&:title)
|
|
63
63
|
```ruby
|
64
64
|
movies = explorer.scrape('/Movies')
|
65
65
|
|
66
|
-
|
66
|
+
movies.map(&:title)
|
67
67
|
# => ["Inside Out (2015).mkv", "Exorcist, The (1973).mkv", "Seven (1995).mkv", "Airplane (1980).mkv"]
|
68
68
|
```
|
69
69
|
|
70
|
+
### Mounting at non-root directory
|
71
|
+
```ruby
|
72
|
+
explorer.root_path
|
73
|
+
#=> "/"
|
74
|
+
|
75
|
+
movies = explorer.get('/Movies')
|
76
|
+
explorer = UpnpContentExplorer::Explorer.new(service, root_id: movies.id)
|
77
|
+
explorer.root_path
|
78
|
+
#=> "/Movies"
|
79
|
+
```
|
80
|
+
|
70
81
|
## Extracting metadata
|
71
82
|
|
72
83
|
To extract DIDL Lite metadata for an item, you should generally call `Browse` with the `BrowseFlag` parameter equal to `'BrowseMetadata'`, passing the `ObjectID` of the item in question. For example:
|
@@ -97,8 +97,10 @@ module UpnpContentExplorer
|
|
97
97
|
RequestedCount: '0'
|
98
98
|
)
|
99
99
|
|
100
|
-
node_data = response[:Result]
|
101
|
-
|
100
|
+
node_data = response[:Result]
|
101
|
+
.gsub('xmlns=', 'xmlns:didl=')
|
102
|
+
content = Nokogiri::XML(node_data)
|
103
|
+
content.remove_namespaces!
|
102
104
|
|
103
105
|
children = content.xpath('/DIDL-Lite/container').map do |child|
|
104
106
|
node_data = parse_nori_node(child)
|
@@ -106,8 +108,7 @@ module UpnpContentExplorer
|
|
106
108
|
end
|
107
109
|
|
108
110
|
items = content.xpath('/DIDL-Lite/item').map do |item|
|
109
|
-
|
110
|
-
Item.new(item_data)
|
111
|
+
Item.new(item)
|
111
112
|
end
|
112
113
|
|
113
114
|
children = Hash[ children.map { |x| [x.title, x] } ]
|
@@ -1,16 +1,30 @@
|
|
1
1
|
module UpnpContentExplorer
|
2
2
|
class Item
|
3
|
-
def initialize(
|
4
|
-
@
|
5
|
-
|
3
|
+
def initialize(xml_node)
|
4
|
+
@xml_node = xml_node
|
5
|
+
@props = {}
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
%w{id parentID restricted}.each do |m|
|
8
|
+
define_singleton_method(m) { extract_xpath("@#{m}") }
|
9
|
+
end
|
10
|
+
|
11
|
+
%w{title class date}.each do |m|
|
12
|
+
define_singleton_method(m) { extract_xpath("#{m}") }
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
%w{
|
16
|
+
size duration bitrate sampleFrequency nrAudioChannels resolution
|
17
|
+
protocolInfo
|
18
|
+
}.each do |m|
|
19
|
+
define_singleton_method(m) { extract_xpath("res/@#{m}") }
|
20
|
+
end
|
21
|
+
|
22
|
+
define_singleton_method('url') { extract_xpath("res") }
|
14
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def extract_xpath(xpath)
|
27
|
+
@xml_node.xpath(xpath).text
|
28
|
+
end
|
15
29
|
end
|
16
30
|
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: 1.
|
4
|
+
version: 1.1.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-
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nori
|