druzy-protocol-plugin-upnp 0.0.1 → 0.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: b263bad510f87505c2172efee315409fe7a817e9
4
- data.tar.gz: a55c0eabf5780e2f1e0fc780c7ffb16c1609fa67
3
+ metadata.gz: 751e1986eae403b671a3c1f26f3eb897e2defd90
4
+ data.tar.gz: fe4b7c3d1b39aac7c85589ab8f21a935bfcd1850
5
5
  SHA512:
6
- metadata.gz: 41f95e6c2f3cc204d7c8fe738fd199480d5801ba8b7b83ed90b5e9991e09d113482d8ba7766a75f5441070abae6bfcca70321f39ce9d5623714e68a81ae51fc1
7
- data.tar.gz: 0e15091291663fab7d733fd476ad1f435cdab0e3273dc9b3dbbc54bda93805b85036272e35b942d6ca1b50c07f755d99e4f30d92c6775b30e55c795330cb68c2
6
+ metadata.gz: 4f850c0059b9efb9c1367deb93dfb9ba3fd7f043d27d603b1839d30639dc2de39ed4f0c63e01a4dd999eabea135584106e51cc40606b8f6304cd5b4b27f632b8
7
+ data.tar.gz: b47b0283e4253da3dd1cde8b1fe7f3320acf95a723f3b45d2362750d28607b09bb405aee16c296492f623e5ced9d6756ccec181b0b20893cf41269496a1fd35a
@@ -1,25 +1,30 @@
1
1
  require 'druzy/protocol/plugin/upnp/version'
2
-
3
- require 'druzy/protocol'
2
+ require 'druzy/server'
4
3
  require 'easy_upnp/ssdp_searcher'
4
+ require 'filemagic'
5
+ require 'nokogiri'
5
6
 
6
7
  module Druzy
7
8
  module Protocol
8
9
  module Plugin
9
10
  module Upnp
10
11
 
12
+ PORT=15322
13
+
11
14
  class UpnpDiscoverer < Druzy::Protocol::Discoverer
12
15
 
13
16
  @@urn_connection_manager='urn:schemas-upnp-org:service:ConnectionManager:1'
14
17
  @@urn_rendering_control='urn:schemas-upnp-org:service:RenderingControl:1'
15
18
 
16
- def start_discoverer(delay=10, identifier=nil, &discovery_listener)
19
+ def start_discoverer(delay=10, identifier=nil)
17
20
  searcher = EasyUpnp::SsdpSearcher.new
18
21
  devices = searcher.search('upnp:rootdevice')
19
22
  for device in devices
20
23
  begin
21
24
  if device.all_services.include?(@@urn_connection_manager) && device.all_services.include?(@@urn_rendering_control)
22
- puts device.device_name
25
+ if block_given?
26
+ yield(UpnpRenderer.new(device))
27
+ end
23
28
  end
24
29
  rescue
25
30
 
@@ -34,7 +39,97 @@ module Druzy
34
39
  end
35
40
  end
36
41
 
42
+ class UpnpRenderer < Druzy::Protocol::Renderer
43
+
44
+ def initialize(easy_upnp)
45
+ @av_transport = easy_upnp.service('urn:schemas-upnp-org:service:AVTransport:1')
46
+ @rendering_control = easy_upnp.service('urn:schemas-upnp-org:service:RenderingControl:1')
47
+ @connection_manager = easy_upnp.service('urn:schemas-upnp-org:service:ConnectionManager:1')
48
+ @av_transport_id=nil
49
+ @connection_id=nil
50
+ @rcs_id=nil
51
+
52
+ document = open(easy_upnp.service_definition(easy_upnp.all_services.first)[:location]) { |f| f.read }
53
+ xml = Nokogiri::XML(document)
54
+ xml.remove_namespaces!
55
+ url_base=xml.xpath("//URLBase").text
56
+ url_icon=url_base+xml.xpath("//device/iconList/icon/url").first.text
57
+
58
+ super(easy_upnp.uuid,"upnp",easy_upnp.device_name,url_icon)
59
+
60
+ end
61
+
62
+ def play
63
+ @av_transport.Play({:InstanceID => @av_transport_id, :Speed => "1"})
64
+ end
65
+
66
+ def pause
67
+ @av_transport.Pause({:InstanceID => @av_transport_id})
68
+ end
69
+
70
+ def stop
71
+ puts "dans stop"
72
+ puts @av_transport.Stop({:InstanceID => @av_transport_id})
73
+ puts "apres"
74
+ end
75
+
76
+ def send(file)
77
+ #vérification du protocol
78
+ protocols = @connection_manager.GetProtocolInfo[:Sink]
79
+ mimetype=FileMagic.new(FileMagic::MAGIC_MIME_TYPE).file(file)
80
+ ask_protocol="http-get:*:"+mimetype+":*"
81
+ if protocols[ask_protocol] != nil
82
+ if @connection_id == nil || @av_transport_id == nil || rcs_id == nil
83
+ ids=@connection_manager.PrepareForConnection({:RemoteProtocolInfo => ask_protocol, :PeerConnectionManager => "/", :PeerConnectionID => -1, :Direction => "Output"})
84
+ @connection_id = ids[:ConnectionID]
85
+ @av_transport_id = ids[:AVTransportID]
86
+ @rcs_id = ids[:RcsID]
87
+ end
88
+
89
+ #ajout du fichier au serveur
90
+ r=Druzy::Server::RestrictedFileServer.instance(PORT)
91
+ r.add_file(file)
92
+
93
+ #preparation de currentUriMetadata
94
+ xml = %Q(<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
95
+ <item id="#{r.get_address(file)}" parentID="0" restricted="false">
96
+ <dc:title>#{File.basename(file,".*")}</dc:title>
97
+ <dc:creator></dc:creator>
98
+ <upnp:class>
99
+ object.item
100
+ </upnp:class>
101
+ <res protocolInfo="#{ask_protocol}">
102
+ #{r.get_address(file)}
103
+ </res>
104
+ </item>
105
+ </DIDL-Lite>)
106
+ #envoie de l'url au renderer
107
+ @av_transport.SetAVTransportURI({:InstanceID => @av_transport_id, :CurrentURI => r.get_address(file), :CurrentURIMetaData => xml})
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+
37
114
  end
38
115
  end
39
116
  end
117
+ end
118
+
119
+ if __FILE__ == $0
120
+
121
+
122
+ up=Druzy::Protocol::Plugin::Upnp::UpnpDiscoverer.new
123
+ up.start_discoverer{ |device|
124
+ device.send("/home/druzy/elliot.mp4")
125
+ device.play
126
+ sleep(10)
127
+ device.pause
128
+ sleep(5)
129
+ device.play
130
+ sleep(5)
131
+ device.stop
132
+ }
133
+
134
+ Thread.list.each{|t| t.join if t!=Thread.main}
40
135
  end
@@ -2,7 +2,7 @@ module Druzy
2
2
  module Protocol
3
3
  module Plugin
4
4
  module Upnp
5
- VERSION = "0.0.1"
5
+ VERSION = "0.1.0"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,29 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: druzy-protocol-plugin-upnp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Le Greneur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: druzy-protocol
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: druzy-server
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: easy_upnp
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-filemagic
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.6.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
25
81
  - !ruby/object:Gem::Version
26
- version: '0'
82
+ version: 1.6.6.2
27
83
  - !ruby/object:Gem::Dependency
28
84
  name: bundler
29
85
  requirement: !ruby/object:Gem::Requirement