dacpclient 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +3 -1
- data/bin/dacpclient +25 -8
- data/lib/dacpclient/client.rb +17 -35
- data/lib/dacpclient/pairingserver.rb +2 -2
- data/lib/dacpclient/tag_container.rb +3 -1
- data/lib/dacpclient/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff09ad7307bbe342d0806c38c576a60b281845fe
|
4
|
+
data.tar.gz: 2672d25061e9704982a95969c3b91a4f22af53f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e82b67093b1adc96ad84c80b8187e0f21a2906835553ee926c7eb49e3badb8f49c1b6432aeb88f91fba1a68af035b8a4d357a3bd4280ea42c336543381ab804
|
7
|
+
data.tar.gz: 190209f628221d59e98d534b1937bd4cb8381034ef941d00e6098fbac91943c69e953061fd7c7c7a745fd37e563ef264e5c0de395d713f10fd8b8da36663bcf7
|
data/LICENSE
CHANGED
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)
|
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'], '
|
17
|
-
if @config['guid'].nil? || @config['guid'] !~ /^[
|
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
|
-
|
46
|
-
total =
|
47
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
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
|
data/lib/dacpclient/client.rb
CHANGED
@@ -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' => '
|
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
|
|
data/lib/dacpclient/version.rb
CHANGED