sonycam 1.2.1 → 1.3.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: 517e4d28a7d968b7c3211a8607ec8120e25d8221
4
- data.tar.gz: 195ecb3e7bbf72add185dbd2c584ad7f722f86bb
3
+ metadata.gz: 267685466ea2942f1aaeb2de7a06390c6755a25a
4
+ data.tar.gz: 6324ddf7763fe498cf7a574a243fb7dffa8eab20
5
5
  SHA512:
6
- metadata.gz: bebebc883f013e9477e2a3848aae5b0c5141f4197eedfa15ee3140b1e13caf5f4723edb46653d64390896a3c1a4ea429a44c466df7467e459817c86c3b674055
7
- data.tar.gz: c1d7afd13daaabde61354ddc06fef294defd0d7deb08f3aaa9a9cae002ba7130a08c7c2de712ed51877b202b405bd871439199a6c7e965923225bcfed69031de
6
+ metadata.gz: db15ae7fe31a6432daf7ecdfe2369903ac0a26233fead4e5cc8abdda1a892553c6e55802e4c2ca6f396e22d50464d9d2eed64d1d738581b3b65e8744c7fdaae4
7
+ data.tar.gz: 9b2e817e2e67beea7f2691ecf773f295214077e398156cba48aac6ab47e0142e31c86f937bbba0661bdf3db7464fd4c94c133eaf20aac57104106e620d8a9b41
@@ -1,32 +1,34 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
3
 
4
- class DeviceDescription
5
- attr_reader :doc
4
+ module Sonycam
5
+ class DeviceDescription
6
+ attr_reader :doc
6
7
 
7
- # document: String or Nokogiri::XML::Node
8
- def initialize document
9
- @doc = Nokogiri::XML(open(document))
10
- @camera_name = @doc.at_xpath('//xmlns:friendlyName').content
11
- @api_url_hash = {}
12
- @doc.xpath('//av:X_ScalarWebAPI_Service', av: 'urn:schemas-sony-com:av').each do |node|
13
- type = node.at_xpath('av:X_ScalarWebAPI_ServiceType', av: 'urn:schemas-sony-com:av').content
14
- url = node.at_xpath('av:X_ScalarWebAPI_ActionList_URL', av: 'urn:schemas-sony-com:av').content
15
- @api_url_hash[type.to_sym] = url
8
+ # document: String or Nokogiri::XML::Node
9
+ def initialize document
10
+ @doc = Nokogiri::XML(open(document))
11
+ @camera_name = @doc.at_xpath('//xmlns:friendlyName').content
12
+ @api_url_hash = {}
13
+ @doc.xpath('//av:X_ScalarWebAPI_Service', av: 'urn:schemas-sony-com:av').each do |node|
14
+ type = node.at_xpath('av:X_ScalarWebAPI_ServiceType', av: 'urn:schemas-sony-com:av').content
15
+ url = node.at_xpath('av:X_ScalarWebAPI_ActionList_URL', av: 'urn:schemas-sony-com:av').content
16
+ @api_url_hash[type.to_sym] = url
17
+ end
16
18
  end
17
- end
18
19
 
19
- # type: :camera, :system, :guide
20
- def api_url type = :camera
21
- # Hush, it's a secret, don't tell anyone.
22
- if @camera_name == 'DSC-RX100M2'
23
- url = @api_url_hash[type].sub('sony', 'camera')
24
- puts "DSC-RX100M2 detected, API URL \"#{url}\" was used insteadly."
25
- return url
26
- end
20
+ # type: :camera, :system, :guide
21
+ def api_url type = :camera
22
+ # Hush, it's a secret, don't tell anyone.
23
+ if @camera_name == 'DSC-RX100M2'
24
+ url = @api_url_hash[type].sub('sony', 'camera')
25
+ puts "DSC-RX100M2 detected, API URL \"#{url}\" was used insteadly."
26
+ return url
27
+ end
27
28
 
28
- if action_list_url = @api_url_hash[type] then "#{action_list_url}/#{type}"
29
- else raise "Can't not find service type \"#{type}\"."
29
+ if action_list_url = @api_url_hash[type] then "#{action_list_url}/#{type}"
30
+ else raise "Can't not find service type \"#{type}\"."
31
+ end
30
32
  end
31
33
  end
32
34
  end
@@ -1,42 +1,44 @@
1
1
  require 'net/http'
2
2
  require 'sonycam/packet'
3
3
 
4
- module Liveview
5
- extend self
6
- def stream liveview_url
7
- uri = URI(liveview_url)
8
- Net::HTTP.start(uri.host, uri.port) do |http|
9
- request = Net::HTTP::Get.new uri
10
- http.request request do |response|
11
- state = :commen_header
12
- buf = ''.force_encoding('BINARY')
13
- commen_header = nil
14
- payload_header = nil
15
- response.read_body do |chunk|
16
- buf += chunk
17
- until buf.empty?
18
- case state
19
- when :commen_header # 8 bytes
20
- break if buf.size < 8
21
- commen_header = buf.slice!(0, 8).unpack('H2CnN')
22
- state = :payload_header
23
- when :payload_header # 128 bytes
24
- break if buf.size < 128
25
- payload_header = buf.slice!(0, 128).unpack('H8H6CH8CH*')
26
- state = :payload_data
27
- when :payload_data
28
- jpeg_data_size = payload_header[1].to_i(16)
29
- padding_size = payload_header[2]
30
- break if buf.size < jpeg_data_size + padding_size
31
- jpeg_data = buf.slice!(0, jpeg_data_size)
32
- padding_data = buf.slice!(0, padding_size)
33
- state = :commen_header
34
- yield Packet.new(commen_header, payload_header, jpeg_data, padding_data)
35
- end # case state
36
- # gets
37
- end # until buf.empty?
38
- end # response.read_body do |chunk|
39
- end # http.request request do |response|
40
- end rescue retry # Net::HTTP.start(uri.host, uri.port) do |http|
41
- end # def stream
42
- end # class Liveview
4
+ module Sonycam
5
+ module Liveview
6
+ extend self
7
+ def stream liveview_url
8
+ uri = URI(liveview_url)
9
+ Net::HTTP.start(uri.host, uri.port) do |http|
10
+ request = Net::HTTP::Get.new uri
11
+ http.request request do |response|
12
+ state = :commen_header
13
+ buf = ''.force_encoding('BINARY')
14
+ commen_header = nil
15
+ payload_header = nil
16
+ response.read_body do |chunk|
17
+ buf += chunk
18
+ until buf.empty?
19
+ case state
20
+ when :commen_header # 8 bytes
21
+ break if buf.size < 8
22
+ commen_header = buf.slice!(0, 8).unpack('H2CnN')
23
+ state = :payload_header
24
+ when :payload_header # 128 bytes
25
+ break if buf.size < 128
26
+ payload_header = buf.slice!(0, 128).unpack('H8H6CH8CH*')
27
+ state = :payload_data
28
+ when :payload_data
29
+ jpeg_data_size = payload_header[1].to_i(16)
30
+ padding_size = payload_header[2]
31
+ break if buf.size < jpeg_data_size + padding_size
32
+ jpeg_data = buf.slice!(0, jpeg_data_size)
33
+ padding_data = buf.slice!(0, padding_size)
34
+ state = :commen_header
35
+ yield Packet.new(commen_header, payload_header, jpeg_data, padding_data)
36
+ end # case state
37
+ # gets
38
+ end # until buf.empty?
39
+ end # response.read_body do |chunk|
40
+ end # http.request request do |response|
41
+ end rescue retry # Net::HTTP.start(uri.host, uri.port) do |http|
42
+ end # def stream
43
+ end # class Liveview
44
+ end
@@ -1,28 +1,30 @@
1
- class Packet
2
- def initialize commen_header, payload_header, jpeg_data, padding_data
3
- @packet = {
4
- commen_header: {
5
- start_byte: commen_header[0], # hex, fixed "FF"
6
- payload_type: commen_header[1], # int
7
- sequence_number: commen_header[2], # int
8
- time_stamp: commen_header[3] # int
9
- },
10
- payload_header: {
11
- star_code: payload_header[0], # hex, fixed "24356879"
12
- jpeg_data_size: payload_header[1].to_i(16), # int
13
- padding_size: payload_header[2], # int
14
- reserved: payload_header[3], # hex
15
- flag: payload_header[4], # int, fixed "00"
16
- reserved_2: payload_header[5]
1
+ module Sonycam
2
+ class Packet
3
+ def initialize commen_header, payload_header, jpeg_data, padding_data
4
+ @packet = {
5
+ commen_header: {
6
+ start_byte: commen_header[0], # hex, fixed "FF"
7
+ payload_type: commen_header[1], # int
8
+ sequence_number: commen_header[2], # int
9
+ time_stamp: commen_header[3] # int
10
+ },
11
+ payload_header: {
12
+ star_code: payload_header[0], # hex, fixed "24356879"
13
+ jpeg_data_size: payload_header[1].to_i(16), # int
14
+ padding_size: payload_header[2], # int
15
+ reserved: payload_header[3], # hex
16
+ flag: payload_header[4], # int, fixed "00"
17
+ reserved_2: payload_header[5]
17
18
 
18
- },
19
- payload_data: {
20
- jpeg_data: jpeg_data,
21
- padding_data: padding_data
22
- },
23
- }
24
- end
25
- def [] key
26
- @packet[key]
19
+ },
20
+ payload_data: {
21
+ jpeg_data: jpeg_data,
22
+ padding_data: padding_data
23
+ },
24
+ }
25
+ end
26
+ def [] key
27
+ @packet[key]
28
+ end
27
29
  end
28
30
  end
@@ -1,3 +1,3 @@
1
1
  module Sonycam
2
- VERSION = '1.2.1'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonycam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Jian