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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab6a03172ad6faf495e4a04e7759640aea563d1f
4
- data.tar.gz: c3511a497b1dcb9c1eb1d595fc27acd6c77f5336
3
+ metadata.gz: 8dad4e9e6f0e15f60e68da4211f9a4fafa6f2664
4
+ data.tar.gz: 7d6f4bebfc9121071f0ffd016e841dc7f7b6dde3
5
5
  SHA512:
6
- metadata.gz: 06ea6df8eabc42005accde92cfd74bf276784bdbb374d2b14cd159b69cb7304403d2b0d0710ce6c585f40446c826aa235fd6a53bd6e90f21c84a0a1ee4becb9d
7
- data.tar.gz: fb640564b9274545fe4497d942d8e7280345df1dd3d798b39296d4ae187f8f8722c7380a160b78fd1b147d80d3df000cb71452c89ae7861bed408e494cfc93f9
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.node_at('/Movies')
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.children_of('/Movies')
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.items_of('/Movies')
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
- items.map(&:title)
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].gsub('xmlns=', 'xmlns:didl=')
101
- content = Nokogiri::XML(node_data)
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
- item_data = parse_nori_node(item)
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(data)
4
- @data = data
5
- end
3
+ def initialize(xml_node)
4
+ @xml_node = xml_node
5
+ @props = {}
6
6
 
7
- def item_class
8
- @data[:class]
9
- end
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
- def method_missing(key)
12
- return @data[key] if @data.has_key?(key)
13
- super
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
@@ -1,3 +1,3 @@
1
1
  module UpnpContentExplorer
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  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.0.0
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-04-27 00:00:00.000000000 Z
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nori