dacpclient 0.3.1 → 0.3.2

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: 66c56df86793fd1624160851a47545719c55b087
4
- data.tar.gz: a62913732101151597a1f8d3d3243e545c7c375a
3
+ metadata.gz: 75fdfc2a63bf7ff3c54194931d3a8475ad297f44
4
+ data.tar.gz: b3a5fe9f909c13a9ef96d7e8b6dd97d40db0d682
5
5
  SHA512:
6
- metadata.gz: 0ec5d69af7e39d2ed18dd4ba99c8104c5943aa79e5dc5e4210242a049719b8c2c60cf5c1503437d161426fa238f664f96c05de37996198d129e1655733f61239
7
- data.tar.gz: 87c00eeb87f5e09919fe4a4c3bd3e964e2e916cf34c4320ec0f145dfe18a274a401dc2632523aec05ca2d4a45ceffd43c614e5111b6756e85b965f708e3f834d
6
+ metadata.gz: ca6dee63a426109a45be94fa670ef322d2f7623576157727fba03fb056829f94f0bc731c9b216dc4480552743d76ef2dc13dec8259582f6196ef1fef328440d2
7
+ data.tar.gz: e1a8d069672cd29e0546cdfb8c3b766244ac0880fc8e627f857a89667936c6cdb18821ceb6b38560d89d26fdc43987bbd092f3740a7901d80bcadd00e147efd6
data/README.md CHANGED
@@ -29,7 +29,7 @@ Or install it yourself using:
29
29
 
30
30
  See [bin/dacpclient](https://github.com/jurriaan/ruby-dacpclient/blob/master/bin/dacpclient)
31
31
 
32
- DACPClient v0.3.0
32
+ DACPClient v0.3.1
33
33
  (c) 2014 Jurriaan Pruis <email@jurriaanpruis.nl>
34
34
 
35
35
  DACPClient commands:
@@ -37,11 +37,11 @@ See [bin/dacpclient](https://github.com/jurriaan/ruby-dacpclient/blob/master/bin
37
37
  dacpclient help [COMMAND] # Describe available commands or one specific command
38
38
  dacpclient hostname # Set the hostname
39
39
  dacpclient next # Go to next item
40
- dacpclient pause # Pause Playing
40
+ dacpclient pause # Pause playing
41
41
  dacpclient play # Start playing
42
42
  dacpclient play_playlist # Plays a playlist
43
43
  dacpclient playlists # Show the playlists
44
- dacpclient playpause # Toggle Playing
44
+ dacpclient playpause # Toggle playing
45
45
  dacpclient prev # Go to previous item
46
46
  dacpclient status # Shows the status of the DACP server
47
47
  dacpclient stop # Stop playing
@@ -59,6 +59,7 @@ See [bin/dacpclient](https://github.com/jurriaan/ruby-dacpclient/blob/master/bin
59
59
 
60
60
  ## Contributors
61
61
 
62
+ - [Daisuke Shimamoto](https://github.com/diskshima)
62
63
  - [Jurriaan Pruis](https://github.com/jurriaan)
63
64
 
64
65
  ## Thanks
data/bin/dacpclient CHANGED
@@ -18,8 +18,7 @@ class CLIClient < Thor
18
18
  @config = {}
19
19
  @config['client_name'] ||= "DACPClient (#{Socket.gethostname})"
20
20
  @config['host'] ||= 'localhost'
21
- @config['known_databases'] ||= []
22
-
21
+ @config['known_services'] ||= []
23
22
  load_config
24
23
 
25
24
  if @config['guid'].nil? || @config['guid'] !~ /^[A-F0-9]{16}$/
@@ -34,24 +33,27 @@ class CLIClient < Thor
34
33
 
35
34
  3.times do
36
35
  browser.browse
37
- database = browser.devices.find do |device|
38
- @config['known_databases'].include? device.database_id
36
+ database = browser.services.find do |service|
37
+ @config['known_services'].include? service.name
39
38
  end
40
39
  break if database
41
40
  sleep 0.5
42
41
  end
43
42
 
43
+ pin = @config['pin'].to_s.chars.map { |num| num.to_i }
44
+
44
45
  unless database
45
- pin = 4.times.map { Random.rand(10) } if pin.nil?
46
+ pin = 4.times.map { Random.rand(10) } if pin.empty?
46
47
  puts 'Cannot find paired Libraries, waiting for a pair request..'
47
48
  puts "Pincode: #{pin}"
48
49
  pairserver = DACPClient::PairingServer.new(@config['client_name'],
49
50
  @config['guid'])
50
51
  pairserver.pin = pin
51
52
  database = pairserver.start
52
- @config['known_databases'] << database.database_id
53
+ @config['known_services'] << database.name
53
54
  save_config
54
55
  end
56
+
55
57
  @client = DACPClient::Client.new(@config['client_name'], database.host,
56
58
  database.port)
57
59
  @client.guid = @config['guid']
@@ -237,6 +239,7 @@ class CLIClient < Thor
237
239
  end
238
240
  end
239
241
  end
242
+
240
243
  loop do
241
244
  status = @client.status true
242
245
  start_time = Time.now.to_f * 1000.0
@@ -252,10 +255,11 @@ class CLIClient < Thor
252
255
  @client.login
253
256
  end
254
257
  @login = true
255
- if @client.host != @config['host']
256
- @config['host'] = @client.host
257
- save_config
258
- end
258
+
259
+ return if @client.host == @config['host']
260
+
261
+ @config['host'] = @client.host
262
+ save_config
259
263
  end
260
264
 
261
265
  def format_time(millis)
@@ -299,8 +303,8 @@ class CLIClient < Thor
299
303
  end
300
304
 
301
305
  def clean_config
302
- @config['known_databases'].delete('')
303
- @config['known_databases'].uniq!
306
+ @config['known_services'].delete('')
307
+ @config['known_services'].uniq!
304
308
  end
305
309
 
306
310
  def save_config
@@ -4,34 +4,34 @@ require 'ostruct'
4
4
  module DACPClient
5
5
  # The Client class handles communication with the server
6
6
  class Browser
7
- class Device < Struct.new(:host, :port, :text_records)
8
- def name
9
- text_records['Machine Name'] || text_records['CtlN']
7
+ class Service < Struct.new(:name, :host, :port, :text_records)
8
+ def library_name
9
+ text_records['CtlN'] || text_records['Machine Name']
10
10
  end
11
11
 
12
12
  def database_id
13
- text_records['Database ID'] || text_records['DbId']
13
+ text_records['DbId'] || text_records['Database ID']
14
14
  end
15
15
  end
16
16
 
17
17
  DAAP_SERVICE = '_daap._tcp'.freeze
18
18
  TOUCHABLE_SERVICE = '_touch-able._tcp'.freeze
19
19
 
20
- attr_reader :devices
20
+ attr_reader :services
21
21
 
22
22
  def initialize
23
- @devices = []
23
+ @services = []
24
24
  end
25
25
 
26
26
  def browse
27
- @devices = []
27
+ @services = []
28
28
  timeout(5) do
29
29
  DNSSD.browse!(TOUCHABLE_SERVICE) do |node|
30
30
  resolve(node)
31
31
  break unless node.flags.more_coming?
32
32
  end
33
33
  end
34
- devices
34
+ services
35
35
  rescue Timeout::Error # => e
36
36
  []
37
37
  end
@@ -39,8 +39,8 @@ module DACPClient
39
39
  private
40
40
 
41
41
  def node_resolver(_node, resolved)
42
- devices << Device.new(get_device_host(resolved), resolved.port,
43
- resolved.text_record)
42
+ services << Service.new(resolved.name, get_device_host(resolved),
43
+ resolved.port, resolved.text_record)
44
44
 
45
45
  resolved.flags.more_coming?
46
46
  end
@@ -29,7 +29,6 @@ module DACPClient
29
29
  @browser = DACPClient::Browser.new
30
30
  @browser.browse
31
31
 
32
- PairInfo.new(DMAPParser::Parser.parse(@pairing_string))
33
32
  super
34
33
  join
35
34
 
@@ -46,10 +45,11 @@ module DACPClient
46
45
 
47
46
  def serve(client)
48
47
  data = client.gets
49
- peer_addr = client.peeraddr[2]
50
- @peer = @browser.devices.find do |device|
51
- device.host == peer_addr
48
+
49
+ @peer = @browser.services.find do |service|
50
+ data =~ /servicename=#{service.name}/i
52
51
  end
52
+
53
53
  if data =~ /pairingcode=#{@expected}/i && @peer
54
54
  client.print "HTTP/1.1 200 OK\n" \
55
55
  "Content-Length: #{@pairing_string.length}\n\n"
@@ -1,4 +1,4 @@
1
1
  # The DACPClient module
2
2
  module DACPClient
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dacpclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Pruis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-06 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday