ruby-mpd-client 0.1.1 → 0.2.0

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: 3c219fde56c4ab0036953aa05ace720270ca119a
4
- data.tar.gz: 408ded419edd17ce2774425f53a01cf427ca2892
3
+ metadata.gz: 5d038318cf899183f6ed52cc1f3c13294b87d899
4
+ data.tar.gz: 1c19d632d7c424d08ba14a5df9be67ca64217213
5
5
  SHA512:
6
- metadata.gz: 3686f11d2f2e8992f3eda5854a60edbf1f6b82847adb1ad12509430ee89f1c77e65e8f6586fb1b1227b0b212a00ffb32b1336016510bb4bdac2848faefeb5794
7
- data.tar.gz: d9437d5abdc6ecf9a6a6f9ceeb1e8086617f63f39c5caf6269cd9347c737601ba47679d043179625ad7bca43f4bb66375cab622de11d6c7231711f0e41bc5bfa
6
+ metadata.gz: 8ebe86c126933033f19be9e25b1c1e1a7e1c2b76856f1e65b60e16e0b685781d6c9f554688e3799a34221072b10b88495a3be94eb296d51f14d97b1092ba2e6b
7
+ data.tar.gz: 93ae6e1f0904011acf8976c26bfc8616d64d7a3336bb382fd076b6e80747e464fbadab11af69a608a0822f84108ca0ba6922645298aacdf51890d820ddd5e95d
data/lib/mpd/client.rb CHANGED
@@ -40,6 +40,10 @@ module MPD
40
40
  raise(ConnectionError) unless connection.gets =~ /^OK/
41
41
  end
42
42
 
43
+ def disconnect
44
+ connection.disconnect
45
+ end
46
+
43
47
  private
44
48
 
45
49
  attr_reader :connection
@@ -0,0 +1,17 @@
1
+ require 'mpd/playlist'
2
+
3
+ module MPD
4
+ class Client
5
+ module Commands
6
+ # https://www.musicpd.org/doc/protocol/queue.html
7
+ module CurrentPlaylist
8
+ # songs - integer or range
9
+ def playlist_info(songs = nil)
10
+ argument = songs.is_a?(Range) ? "#{songs.begin}:#{songs.end}" : songs
11
+ response = execute "playlistinfo #{argument}"
12
+ Playlist.from_response(response)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -12,9 +12,15 @@ module MPD
12
12
  end
13
13
 
14
14
  def connect
15
+ disconnect if socket
15
16
  @socket = TCPSocket.open(host, port)
16
17
  end
17
18
 
19
+ def disconnect
20
+ socket && socket.close
21
+ @socket = nil
22
+ end
23
+
18
24
  def puts(text)
19
25
  raise ConnectionError unless socket
20
26
  socket.puts(text)
@@ -0,0 +1,27 @@
1
+ require 'mpd/song'
2
+
3
+ module MPD
4
+ # Array<SongInfo> with some useful methods
5
+ class Playlist < Array
6
+ def self.from_response(response)
7
+ data = []
8
+ info = {}
9
+ response.key_value_pairs.each do |key, value|
10
+ if info.key?(key) # next song info
11
+ data << info
12
+ info = {}
13
+ end
14
+
15
+ info[key] = value
16
+ end
17
+
18
+ data << info
19
+ new(data)
20
+ end
21
+
22
+ # data - array of hashes from MPD
23
+ def initialize(data)
24
+ super(data.map { |info| Song.new(info) })
25
+ end
26
+ end
27
+ end
data/lib/mpd/song.rb ADDED
@@ -0,0 +1,28 @@
1
+ module MPD
2
+ # Hash with predefined structure (see MAPPINGS) created from
3
+ # basic MPD song info
4
+ # Additionaly it stores base data via #data
5
+ class Song < Hash
6
+ MAPPINGS = { file: 'file',
7
+ artist: 'Artist',
8
+ album: 'Album',
9
+ title: 'Title',
10
+ year: 'Date',
11
+ genre: 'Genre',
12
+ id: 'Id',
13
+ position: 'Pos',
14
+ time: 'Time' }.freeze
15
+
16
+ attr_reader :data
17
+
18
+ def initialize(data)
19
+ super()
20
+ @data = data
21
+ MAPPINGS.each { |key, data_key| self[key] = data[data_key] }
22
+ end
23
+
24
+ MAPPINGS.each do |method_name, data_key|
25
+ define_method(method_name) { data[data_key] }
26
+ end
27
+ end
28
+ end
data/lib/mpd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MPD
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpd-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Non
@@ -54,11 +54,14 @@ files:
54
54
  - bin/setup
55
55
  - lib/mpd/client.rb
56
56
  - lib/mpd/client/commands.rb
57
+ - lib/mpd/client/commands/current_playlist.rb
57
58
  - lib/mpd/client/commands/playback_control.rb
58
59
  - lib/mpd/client/commands/playback_options.rb
59
60
  - lib/mpd/client/connection.rb
60
61
  - lib/mpd/client/server_response.rb
61
62
  - lib/mpd/errors.rb
63
+ - lib/mpd/playlist.rb
64
+ - lib/mpd/song.rb
62
65
  - lib/mpd/version.rb
63
66
  - lib/ruby-mpd-client.rb
64
67
  - ruby-mpd-client.gemspec