dacpclient 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cff4d4d1619ceb0c95d8b580555e2e52654a5d0
4
- data.tar.gz: 9386ed35980f41b0c13d4a7984cc8e8380bc8dff
3
+ metadata.gz: ff09ad7307bbe342d0806c38c576a60b281845fe
4
+ data.tar.gz: 2672d25061e9704982a95969c3b91a4f22af53f2
5
5
  SHA512:
6
- metadata.gz: 9c3b18e11267e973a749e6914cdc49d208272320b9f3894e00a2a2ec47d681ecd740a34ef01d690f9dd30034142d680232f37865afa230d81415fdfb8fedbcba
7
- data.tar.gz: 89f07f9edb793880e2c04da6aafa0dd780457499abfa2251cb95cb33df644982e0bc5f91f5cd284119ce97e8e980cc6dee220aaa46db7091725103be7967e9eb
6
+ metadata.gz: 6e82b67093b1adc96ad84c80b8187e0f21a2906835553ee926c7eb49e3badb8f49c1b6432aeb88f91fba1a68af035b8a4d357a3bd4280ea42c336543381ab804
7
+ data.tar.gz: 190209f628221d59e98d534b1937bd4cb8381034ef941d00e6098fbac91943c69e953061fd7c7c7a745fd37e563ef264e5c0de395d713f10fd8b8da36663bcf7
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2013, Jurriaan Pruis <email@jurriaanpruis.nl>
1
+ Copyright (c) 2011-2014, Jurriaan Pruis <email@jurriaanpruis.nl>
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -11,6 +11,8 @@ Look at the [bin/dacpclient](https://github.com/jurriaan/ruby-dacpclient/blob/ma
11
11
 
12
12
  ## Installation
13
13
 
14
+ On Linux you need the avahi-dnssd-compat package (`libavahi-compat-libdnssd-dev` on Debian/Ubuntu).
15
+
14
16
  Add this line to your application's Gemfile:
15
17
 
16
18
  gem 'dacpclient'
@@ -28,7 +30,7 @@ Or install it yourself using:
28
30
  See [bin/dacpclient](https://github.com/jurriaan/ruby-dacpclient/blob/master/bin/dacpclient)
29
31
 
30
32
  Usage: dacpclient [command]
31
- (c) 2013 Jurriaan Pruis <email@jurriaanpruis.nl>
33
+ (c) 2014 Jurriaan Pruis <email@jurriaanpruis.nl>
32
34
 
33
35
  Where command is one of the following:
34
36
  status
data/bin/dacpclient CHANGED
@@ -11,10 +11,11 @@ class CLIClient
11
11
  def initialize
12
12
  @config = {}
13
13
  @config['client_name'] ||= "DACPClient (#{Socket.gethostname})"
14
+ @config['host'] ||= 'localhost'
14
15
  load_config
15
16
 
16
- @client = DACPClient::Client.new(@config['client_name'], 'localhost', 3689)
17
- if @config['guid'].nil? || @config['guid'] !~ /^[a-f0-9]{16}$/
17
+ @client = DACPClient::Client.new(@config['client_name'], @config['host'], 3689)
18
+ if @config['guid'].nil? || @config['guid'] !~ /^[A-F0-9]{16}$/
18
19
  @config['guid'] = @client.guid
19
20
  save_config
20
21
  end
@@ -42,9 +43,13 @@ class CLIClient
42
43
  artist = status.cana
43
44
  album = status.canl
44
45
  playstatus = status.caps != 4 ? '❙❙' : '▶ '
45
- remaining = status.cant
46
- total = status.cast
47
- current = total - remaining
46
+ current = 0
47
+ total = 0
48
+ if status.cast? && status.cant?
49
+ remaining = status.cant
50
+ total = status.cast
51
+ current = total - remaining
52
+ end
48
53
  puts "[#{format_time(current)}/#{format_time(total)}] #{playstatus} #{name} - #{artist} (#{album})"
49
54
  end
50
55
  end
@@ -62,9 +67,13 @@ class CLIClient
62
67
  artist = status.cana
63
68
  album = status.canl
64
69
  playstatus = status.caps != 4 ? '❙❙' : '▶ '
65
- total = status.cast
66
- remaining = status.cant
67
- current = total - remaining + [((Time.now.to_f * 1000.0) - status_time), 0].max
70
+ current = 0
71
+ total = 0
72
+ if status.cast? && status.cant?
73
+ remaining = status.cant
74
+ total = status.cast
75
+ current = total - remaining + [((Time.now.to_f * 1000.0) - status_time), 0].max
76
+ end
68
77
  print "\r\033[K[#{format_time(current)}/#{format_time(total)}] #{playstatus} #{name} - #{artist} (#{album})"
69
78
  end
70
79
  end
@@ -91,6 +100,14 @@ class CLIClient
91
100
  puts "Got your Home Sharing GUID (#{guid}). Logging in.."
92
101
  login
93
102
  end
103
+
104
+ def hostname
105
+ puts "Please enter a new hostname to connect to:"
106
+ @config['host'] = $stdin.gets.strip
107
+ save_config
108
+ @client = DACPClient::Client.new(@config['client_name'], @config['host'], 3689)
109
+ status
110
+ end
94
111
 
95
112
  def play
96
113
  login
@@ -22,7 +22,7 @@ module DACPClient
22
22
  'Viewer-Only-Client' => '1',
23
23
  # 'Accept-Encoding' => 'gzip',
24
24
  'Connection' => 'keep-alive',
25
- 'User-Agent' => 'Remote/2.0'
25
+ 'User-Agent' => 'RubyDACPClient/' + VERSION
26
26
  }.freeze
27
27
 
28
28
  def initialize(name, host = 'localhost', port = 3689)
@@ -38,6 +38,18 @@ module DACPClient
38
38
  @client = Faraday.new(url: @uri.to_s)
39
39
  end
40
40
 
41
+ [:play, :playpause, :stop, :pause,
42
+ :nextitem, :previtem, :getspeakers].each do |action_name|
43
+ define_method action_name do
44
+ do_action action_name
45
+ end
46
+ end
47
+
48
+ alias_method :previous, :previtem
49
+ alias_method :prev, :previtem
50
+ alias_method :next, :nextitem
51
+ alias_method :speakers, :getspeakers
52
+
41
53
  def setup_home_sharing(user, password)
42
54
  hs_client = Faraday.new(url: HOME_SHARING_HOST)
43
55
  result = hs_client.post do |request|
@@ -54,7 +66,7 @@ module DACPClient
54
66
  def guid
55
67
  return @guid unless @guid.nil?
56
68
  d = Digest::SHA2.hexdigest(@name)
57
- d[0..15]
69
+ d[0..15].upcase
58
70
  end
59
71
 
60
72
  def pair(pin)
@@ -93,25 +105,9 @@ module DACPClient
93
105
  do_action('content-codes', {}, true)
94
106
  end
95
107
 
96
- def play
97
- do_action(:play)
98
- end
99
-
100
- def playpause
101
- do_action(:playpause)
102
- end
103
-
104
- def stop
105
- do_action(:stop)
106
- end
107
-
108
- def pause
109
- do_action(:pause)
110
- end
111
-
112
108
  def track_length
113
109
  response = do_action(:getproperty, properties: 'dacp.playingtime')
114
- response['cast']
110
+ response.cast? ? response['cast'] : 0
115
111
  end
116
112
 
117
113
  def seek(ms)
@@ -120,7 +116,7 @@ module DACPClient
120
116
 
121
117
  def position
122
118
  response = do_action(:getproperty, properties: 'dacp.playingtime')
123
- response['cast'] - response['cant']
119
+ response.cast? ? (response['cast'] - response['cant']) : 0
124
120
  end
125
121
 
126
122
  alias_method :position=, :seek
@@ -138,16 +134,6 @@ module DACPClient
138
134
  end
139
135
  end
140
136
 
141
- def next
142
- do_action(:nextitem)
143
- end
144
-
145
- def prev
146
- do_action(:previtem)
147
- end
148
-
149
- alias_method :previous, :prev
150
-
151
137
  def volume
152
138
  response = do_action(:getproperty, properties: 'dmcp.volume')
153
139
  response[:cmvo]
@@ -175,10 +161,6 @@ module DACPClient
175
161
  do_action(:setproperty, 'dmcp.shufflestate' => shufflestate)
176
162
  end
177
163
 
178
- def speakers
179
- do_action(:getspeakers)
180
- end
181
-
182
164
  def ctrl_int
183
165
  do_action('ctrl-int', {}, true)
184
166
  end
@@ -271,7 +253,7 @@ module DACPClient
271
253
 
272
254
  parse_result result
273
255
  end
274
-
256
+
275
257
  def parse_result(result)
276
258
  if !result.success?
277
259
  fail DACPForbiddenError, result
@@ -34,7 +34,7 @@ module DACPClient
34
34
 
35
35
  def self.generate_pin_challenge(pair, pin)
36
36
  pin_string = pin.map { |i| "#{i}\x00" }.join
37
- Digest::MD5.hexdigest(pair + pin_string)
37
+ Digest::MD5.hexdigest(pair.upcase + pin_string)
38
38
  end
39
39
 
40
40
  def serve(client)
@@ -59,7 +59,7 @@ module DACPClient
59
59
  'DvTy' => @device_type,
60
60
  'RemN' => 'Remote',
61
61
  'txtvers' => '1',
62
- 'Pair' => @pair
62
+ 'Pair' => @pair.upcase
63
63
  )
64
64
  end
65
65
 
@@ -35,7 +35,9 @@ module DACPClient
35
35
  end
36
36
 
37
37
  def method_missing(method, *arguments, &block)
38
- if has?(method)
38
+ if method =~ /(.*)\?$/
39
+ has?($1)
40
+ elsif has?(method)
39
41
  get_value(method)
40
42
  else
41
43
  super
@@ -1,4 +1,4 @@
1
1
  # The DACPClient module
2
2
  module DACPClient
3
- VERSION = '0.2.4'
3
+ VERSION = '0.2.5'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dacpclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Pruis