ruby-mpd 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +8 -12
- data/Rakefile +6 -0
- data/lib/ruby-mpd.rb +34 -20
- data/lib/ruby-mpd/parser.rb +0 -1
- data/lib/ruby-mpd/song.rb +1 -1
- data/lib/ruby-mpd/version.rb +1 -1
- data/test/test_parser.rb +52 -0
- metadata +5 -4
- data/test/libtests.rb +0 -1134
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abe8c832ca9a5b9254a92bfe8927b132c3bbe498
|
4
|
+
data.tar.gz: dbb36caae0622e63cc70149924911dec0d1abde1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 861e3e63f0a6faeff4794b226e38475ea404c20d1f9a3fcb2b9eb37b0394f090aa6a933c134f2e2d389b8134107a859df94e26f86ab56e93e352e30bd416b12c
|
7
|
+
data.tar.gz: 35d40fc9e2b6ee08d6b564c7ec1f7b301699bec390248fc0bc270a1a1b68d56b3906a2010c9734efeb31363c5b64b5f4b8ea566c6a08da0c594b6fd967c5b873
|
data/README.rdoc
CHANGED
@@ -39,9 +39,9 @@ When you are done, disconnect by calling disconnect.
|
|
39
39
|
|
40
40
|
mpd.disconnect
|
41
41
|
|
42
|
-
*Note*:
|
43
|
-
|
44
|
-
|
42
|
+
*Note*: In the past, one had to tackle the issue of the server possibly disconnecting
|
43
|
+
the client at any time due to inactivity. Since 0.3.0, this is handled automatically
|
44
|
+
via a reconnect mechanism.
|
45
45
|
|
46
46
|
Once connected, you can issue commands to talk to the server.
|
47
47
|
|
@@ -143,14 +143,12 @@ certain connection.
|
|
143
143
|
Callbacks are a simple way to make your client respond to events, rather that
|
144
144
|
have to continuously ask the server for updates. This allows you to focus on
|
145
145
|
displaying the data, rather that working overly hard to get it. This is done
|
146
|
-
by having a background thread continuously check the server for changes.
|
147
|
-
of this thead, enabling callbacks also means your client will stay connected to
|
148
|
-
the server without having to worry about timeouts.
|
146
|
+
by having a background thread continuously check the server for changes.
|
149
147
|
|
150
148
|
To make use of callbacks, we need to:
|
151
149
|
|
152
150
|
1. Setup a callback to be called when something happens.
|
153
|
-
2.
|
151
|
+
2. Create a MPD client instance with callbacks enabled.
|
154
152
|
|
155
153
|
Firstly, we need to create a callback block and subscribe it, so that will get
|
156
154
|
triggered whenever a specific event happens. When the callback is triggered,
|
@@ -217,16 +215,14 @@ in order to recieve those values:
|
|
217
215
|
puts args.join(',')
|
218
216
|
end
|
219
217
|
|
220
|
-
Finally, the easiest step. In order for callbacks to work,
|
218
|
+
Finally, the easiest step. In order for callbacks to work, create a MPD instance
|
221
219
|
with callbacks enabled:
|
222
220
|
|
223
|
-
|
221
|
+
MPD.new('localhost', 6600, {callbacks: true})
|
224
222
|
|
225
223
|
Easy as pie. The above will connect to the server like normal, but this time it will
|
226
224
|
create a new thread that loops until you issue a `disconnect`. This loop checks the
|
227
|
-
server, then sleeps for two tenths of a second, then loops.
|
228
|
-
polling the server, there's the added benefit of your client not being disconnected
|
229
|
-
due to inactivity.
|
225
|
+
server, then sleeps for two tenths of a second, then loops.
|
230
226
|
|
231
227
|
== Not yet implemented
|
232
228
|
|
data/Rakefile
ADDED
data/lib/ruby-mpd.rb
CHANGED
@@ -44,9 +44,17 @@ class MPD
|
|
44
44
|
|
45
45
|
# Initialize an MPD object with the specified hostname and port.
|
46
46
|
# When called without arguments, 'localhost' and 6600 are used.
|
47
|
-
|
47
|
+
#
|
48
|
+
# When called with +callbacks: true+ as an optional argument,
|
49
|
+
# callbacks will be enabled by starting a separate polling thread.
|
50
|
+
#
|
51
|
+
# @param [String] hostname Hostname of the daemon
|
52
|
+
# @param [Integer] port Port of the daemon
|
53
|
+
# @param [Hash] opts Optional parameters. Currently accepts +callbacks+
|
54
|
+
def initialize(hostname = 'localhost', port = 6600, opts = {})
|
48
55
|
@hostname = hostname
|
49
56
|
@port = port
|
57
|
+
@options = {callbacks: false}.merge(opts)
|
50
58
|
reset_vars
|
51
59
|
|
52
60
|
@mutex = Mutex.new
|
@@ -105,14 +113,12 @@ class MPD
|
|
105
113
|
status[:time] = [nil, nil] if !status[:time] # elapsed, total
|
106
114
|
status[:audio] = [nil, nil, nil] if !status[:audio] # samp, bits, chans
|
107
115
|
|
116
|
+
status[:song] = mpd.current_song
|
117
|
+
|
108
118
|
status.each do |key, val|
|
109
119
|
next if val == old_status[key] # skip unchanged keys
|
110
|
-
|
111
|
-
|
112
|
-
emit(:song, mpd.current_song)
|
113
|
-
else # convert arrays to splat arguments
|
114
|
-
val.is_a?(Array) ? emit(key, *val) : emit(key, val)
|
115
|
-
end
|
120
|
+
# convert arrays to splat arguments
|
121
|
+
val.is_a?(Array) ? emit(key, *val) : emit(key, val)
|
116
122
|
end
|
117
123
|
|
118
124
|
old_status = status
|
@@ -136,13 +142,9 @@ class MPD
|
|
136
142
|
# When called without any arguments, this will just connect to the server
|
137
143
|
# and wait for your commands.
|
138
144
|
#
|
139
|
-
# When called with +callbacks: true+ as an argument, this will enable callbacks by starting
|
140
|
-
# a seperate polling thread, which will also automatically reconnect if disconnected
|
141
|
-
# for whatever reason.
|
142
|
-
#
|
143
145
|
# @return [true] Successfully connected.
|
144
146
|
# @raise [MPDError] If connect is called on an already connected instance.
|
145
|
-
def connect(
|
147
|
+
def connect(callbacks = nil)
|
146
148
|
raise ConnectionError, 'Already connected!' if self.connected?
|
147
149
|
|
148
150
|
@socket = File.exists?(@hostname) ? UNIXSocket.new(@hostname) : TCPSocket.new(@hostname, @port)
|
@@ -156,12 +158,12 @@ class MPD
|
|
156
158
|
raise ConnectionError, 'Unable to connect (possibly too many connections open)'
|
157
159
|
end
|
158
160
|
|
159
|
-
if
|
160
|
-
warn "Using 'true' or 'false' as an argument to #connect has been deprecated, and will be removed in the future!"
|
161
|
-
|
161
|
+
if callbacks
|
162
|
+
warn "Using 'true' or 'false' as an argument to MPD#connect has been deprecated, and will be removed in the future!"
|
163
|
+
@options.merge!(callbacks: callbacks)
|
162
164
|
end
|
163
165
|
|
164
|
-
callback_thread if
|
166
|
+
callback_thread if @options[:callbacks]
|
165
167
|
return true
|
166
168
|
end
|
167
169
|
|
@@ -184,12 +186,24 @@ class MPD
|
|
184
186
|
|
185
187
|
return false if !@socket
|
186
188
|
|
187
|
-
|
188
|
-
|
189
|
+
begin
|
190
|
+
@socket.puts 'close'
|
191
|
+
@socket.close
|
192
|
+
rescue Errno::EPIPE
|
193
|
+
# socket was forcefully closed
|
194
|
+
end
|
195
|
+
|
189
196
|
reset_vars
|
190
197
|
return true
|
191
198
|
end
|
192
199
|
|
200
|
+
# Attempts to reconnect to the MPD daemon.
|
201
|
+
# @return [Boolean] True if successfully reconnected, false otherwise.
|
202
|
+
def reconnect
|
203
|
+
disconnect
|
204
|
+
connect
|
205
|
+
end
|
206
|
+
|
193
207
|
# Kills the MPD process.
|
194
208
|
# @macro returnraise
|
195
209
|
def kill
|
@@ -227,8 +241,8 @@ class MPD
|
|
227
241
|
response = handle_server_response
|
228
242
|
return parse_response(command, response)
|
229
243
|
rescue Errno::EPIPE
|
230
|
-
|
231
|
-
|
244
|
+
reconnect
|
245
|
+
retry
|
232
246
|
end
|
233
247
|
end
|
234
248
|
end
|
data/lib/ruby-mpd/parser.rb
CHANGED
@@ -44,7 +44,6 @@ class MPD
|
|
44
44
|
FLOAT_KEYS = [:mixrampdb, :elapsed]
|
45
45
|
BOOL_KEYS = [:repeat, :random, :single, :consume, :outputenabled]
|
46
46
|
|
47
|
-
|
48
47
|
# Commands, where it makes sense to always explicitly return an array.
|
49
48
|
RETURN_ARRAY = [:channels, :outputs, :readmessages, :list,
|
50
49
|
:listallinfo, :find, :search, :listplaylists, :listplaylist, :playlistfind,
|
data/lib/ruby-mpd/song.rb
CHANGED
@@ -20,7 +20,7 @@ class MPD::Song
|
|
20
20
|
|
21
21
|
# Two songs are the same when they are the same file.
|
22
22
|
def ==(another)
|
23
|
-
self.file == another.file
|
23
|
+
self.class == another.class && self.file == another.file
|
24
24
|
end
|
25
25
|
|
26
26
|
# @return [String] A formatted representation of the song length ("1:02")
|
data/lib/ruby-mpd/version.rb
CHANGED
data/test/test_parser.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative '../lib/ruby-mpd'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
Parser = Class.new do
|
5
|
+
include MPD::Parser
|
6
|
+
end
|
7
|
+
Parser.send(:public, *MPD::Parser.private_instance_methods)
|
8
|
+
|
9
|
+
class TestParser < MiniTest::Test
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@parser = Parser.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
# Conversions for commands to the server
|
20
|
+
def test_convert_bool
|
21
|
+
assert_equal @parser.convert_command(:pause, true), 'pause 1'
|
22
|
+
assert_equal @parser.convert_command(:pause, false), 'pause 0'
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_convert_range
|
26
|
+
# inclusive range
|
27
|
+
assert_equal @parser.convert_command(:playlistinfo, 1..10), 'playlistinfo 1:11'
|
28
|
+
# exclusive range
|
29
|
+
assert_equal @parser.convert_command(:playlistinfo, 2...5), 'playlistinfo 2:5'
|
30
|
+
|
31
|
+
# negative means "till end of range"
|
32
|
+
assert_equal @parser.convert_command(:playlistinfo, 2...-1), 'playlistinfo 2:'
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_convert_escape_whitespace
|
36
|
+
assert_equal @parser.convert_command(:lsinfo, '/media/Storage/epic music'), 'lsinfo "/media/Storage/epic music"'
|
37
|
+
end
|
38
|
+
|
39
|
+
# Parse replies from server
|
40
|
+
def test_parse_empty_listall_command
|
41
|
+
assert_equal @parser.parse_response(:listall, ''), {}
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_parse_playlist_uint
|
45
|
+
assert_equal @parser.parse_key(:playlist, '31'), 31
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_parse_playlist_name
|
49
|
+
assert_equal @parser.parse_key(:playlist, 'leftover/classics.m3u'), 'leftover/classics.m3u'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-mpd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blaž Hrastnik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A powerful, modern and feature complete library for the Music Player
|
14
14
|
Daemon.
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- .gitignore
|
22
22
|
- COPYING
|
23
23
|
- README.rdoc
|
24
|
+
- Rakefile
|
24
25
|
- lib/ruby-mpd.rb
|
25
26
|
- lib/ruby-mpd/exceptions.rb
|
26
27
|
- lib/ruby-mpd/parser.rb
|
@@ -38,7 +39,7 @@ files:
|
|
38
39
|
- lib/ruby-mpd/song.rb
|
39
40
|
- lib/ruby-mpd/version.rb
|
40
41
|
- ruby-mpd.gemspec
|
41
|
-
- test/
|
42
|
+
- test/test_parser.rb
|
42
43
|
homepage: https://github.com/archSeer/ruby-mpd
|
43
44
|
licenses: []
|
44
45
|
metadata: {}
|
@@ -63,5 +64,5 @@ signing_key:
|
|
63
64
|
specification_version: 4
|
64
65
|
summary: Modern client library for MPD
|
65
66
|
test_files:
|
66
|
-
- test/
|
67
|
+
- test/test_parser.rb
|
67
68
|
has_rdoc:
|
data/test/libtests.rb
DELETED
@@ -1,1134 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Unit tests for ruby-mpd
|
3
|
-
#
|
4
|
-
|
5
|
-
require '../lib/ruby-mpd'
|
6
|
-
require 'test/unit'
|
7
|
-
|
8
|
-
class MPDTester < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
begin
|
12
|
-
@mpd = MPD.new 'localhost', 94942
|
13
|
-
end
|
14
|
-
|
15
|
-
def teardown
|
16
|
-
@mpd.disconnect
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_connect
|
20
|
-
ret = @mpd.connect
|
21
|
-
assert ret
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_connected?
|
25
|
-
# test a good connection
|
26
|
-
@mpd.connect
|
27
|
-
assert @mpd.connected?
|
28
|
-
|
29
|
-
# Test a disconnect
|
30
|
-
@server.stop
|
31
|
-
assert !@mpd.connected?
|
32
|
-
|
33
|
-
# test a bad connection
|
34
|
-
bad = MPD.new 'no-connection', 6600
|
35
|
-
assert !bad.connected?
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_disconnect
|
39
|
-
# test a good connection
|
40
|
-
@mpd.connect
|
41
|
-
assert @mpd.connected?
|
42
|
-
@mpd.disconnect
|
43
|
-
assert !@mpd.connected?
|
44
|
-
@mpd.disconnect
|
45
|
-
assert !@mpd.connected?
|
46
|
-
|
47
|
-
# test a bad connection
|
48
|
-
bad = MPD.new 'no-connection'
|
49
|
-
bad.disconnect
|
50
|
-
assert !bad.connected?
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_add
|
54
|
-
@mpd.connect
|
55
|
-
assert @mpd.connected?
|
56
|
-
|
57
|
-
assert @mpd.add('Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg')
|
58
|
-
|
59
|
-
pls = @mpd.playlist
|
60
|
-
assert_equal 1, pls.size
|
61
|
-
assert_equal 'Shpongle', pls[0].artist
|
62
|
-
assert_equal 'Are You Shpongled?', pls[0].album
|
63
|
-
assert_equal 'Shpongle Falls', pls[0].title
|
64
|
-
|
65
|
-
assert_raise(MPD::ServerError) {@mpd.add('Does/Not/Exist')}
|
66
|
-
|
67
|
-
@mpd.disconnect
|
68
|
-
assert_raise(MPD::ServerError) {@mpd.add('Shpongle')}
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_clear
|
72
|
-
@mpd.connect
|
73
|
-
assert @mpd.connected?
|
74
|
-
|
75
|
-
assert @mpd.add('Shpongle')
|
76
|
-
|
77
|
-
pls = @mpd.playlist
|
78
|
-
assert_equal 27, pls.size
|
79
|
-
|
80
|
-
assert @mpd.clear
|
81
|
-
|
82
|
-
pls = @mpd.playlist
|
83
|
-
assert_equal 0, pls.size
|
84
|
-
|
85
|
-
@mpd.disconnect
|
86
|
-
assert_raise(MPD::ServerError) {@mpd.clear}
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_clearerror
|
90
|
-
@mpd.connect
|
91
|
-
assert @mpd.connected?
|
92
|
-
|
93
|
-
assert @mpd.clearerror
|
94
|
-
|
95
|
-
@mpd.disconnect
|
96
|
-
assert_raise(MPD::ServerError) {@mpd.clearerror}
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_crossfade
|
100
|
-
@mpd.connect
|
101
|
-
|
102
|
-
@mpd.crossfade = 40
|
103
|
-
|
104
|
-
assert_equal 40, @mpd.crossfade
|
105
|
-
assert_equal '40', @mpd.status['xfade']
|
106
|
-
|
107
|
-
@mpd.disconnect
|
108
|
-
assert_raise(MPD::ServerError) {@mpd.crossfade = 20}
|
109
|
-
assert_raise(MPD::ServerError) {@mpd.crossfade}
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_current_song
|
113
|
-
@mpd.connect
|
114
|
-
|
115
|
-
s = @mpd.current_song
|
116
|
-
assert_nil s
|
117
|
-
|
118
|
-
assert @mpd.add('Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg')
|
119
|
-
|
120
|
-
assert @mpd.play
|
121
|
-
|
122
|
-
sleep 2
|
123
|
-
|
124
|
-
assert @mpd.playing?
|
125
|
-
|
126
|
-
s = @mpd.current_song
|
127
|
-
|
128
|
-
assert_equal 'Shpongle', s.artist
|
129
|
-
assert_equal 'Are You Shpongled?', s.album
|
130
|
-
assert_equal 'Shpongle Falls', s.title
|
131
|
-
assert_equal '1', s.track
|
132
|
-
|
133
|
-
@mpd.stop
|
134
|
-
|
135
|
-
sleep 2
|
136
|
-
|
137
|
-
assert !@mpd.playing?
|
138
|
-
|
139
|
-
s = @mpd.current_song
|
140
|
-
|
141
|
-
assert_equal 'Shpongle', s.artist
|
142
|
-
assert_equal 'Are You Shpongled?', s.album
|
143
|
-
assert_equal 'Shpongle Falls', s.title
|
144
|
-
assert_equal '1', s.track
|
145
|
-
|
146
|
-
@mpd.disconnect
|
147
|
-
assert_raise(MPD::ServerError) {@mpd.current_song}
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_delete
|
151
|
-
@mpd.connect
|
152
|
-
|
153
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
154
|
-
|
155
|
-
assert @mpd.delete(3)
|
156
|
-
|
157
|
-
pls = @mpd.playlist
|
158
|
-
assert_equal 7, pls.size
|
159
|
-
pls.each do |song|
|
160
|
-
assert_not_equal 'No On Ever Dreams', song.title
|
161
|
-
end
|
162
|
-
|
163
|
-
assert_raise(MPD::ServerError) {@mpd.delete(999)}
|
164
|
-
|
165
|
-
@mpd.disconnect
|
166
|
-
assert_raise(MPD::ServerError) {@mpd.delete(3)}
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_deleteid
|
170
|
-
@mpd.connect
|
171
|
-
|
172
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
173
|
-
|
174
|
-
assert @mpd.deleteid(10)
|
175
|
-
|
176
|
-
pls = @mpd.playlist
|
177
|
-
assert_equal 7, pls.size
|
178
|
-
pls.each do |song|
|
179
|
-
assert_not_equal 'No One Ever Dreams', song.title
|
180
|
-
end
|
181
|
-
|
182
|
-
assert_raise(MPD::ServerError) {@mpd.deleteid(999)}
|
183
|
-
|
184
|
-
@mpd.disconnect
|
185
|
-
assert_raise(MPD::ServerError) {@mpd.deleteid(11)}
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_find
|
189
|
-
@mpd.connect
|
190
|
-
|
191
|
-
a = @mpd.find 'album', 'Are You Shpongled?'
|
192
|
-
assert_equal 7, a.size
|
193
|
-
assert_equal 'Shpongle Falls', a[0].title
|
194
|
-
assert_equal 'Monster Hit', a[1].title
|
195
|
-
assert_equal 'Vapour Rumours', a[2].title
|
196
|
-
assert_equal 'Shpongle Spores', a[3].title
|
197
|
-
assert_equal 'Behind Closed Eyelids', a[4].title
|
198
|
-
assert_equal 'Divine Moments of Truth', a[5].title
|
199
|
-
assert_equal '... and the Day Turned to Night', a[6].title
|
200
|
-
|
201
|
-
b = @mpd.find 'artist', 'Carbon Based Lifeforms'
|
202
|
-
assert_equal 11, b.size
|
203
|
-
assert_equal 'Central Plains', b[0].title
|
204
|
-
assert_equal 'Tensor', b[1].title
|
205
|
-
assert_equal 'MOS 6581 (Album Version)', b[2].title
|
206
|
-
assert_equal 'Silent Running', b[3].title
|
207
|
-
assert_equal 'Neurotransmitter', b[4].title
|
208
|
-
assert_equal 'Hydroponic Garden', b[5].title
|
209
|
-
assert_equal 'Exosphere', b[6].title
|
210
|
-
assert_equal 'Comsat', b[7].title
|
211
|
-
assert_equal 'Epicentre (First Movement)', b[8].title
|
212
|
-
assert_equal 'Artificial Island', b[9].title
|
213
|
-
assert_equal 'Refraction 1.33', b[10].title
|
214
|
-
|
215
|
-
c = @mpd.find 'title', 'Silent Running'
|
216
|
-
assert_equal 1, c.size
|
217
|
-
assert_equal 'Silent Running', c[0].title
|
218
|
-
|
219
|
-
d = @mpd.find 'artist', 'no artist'
|
220
|
-
assert_equal 0, d.size
|
221
|
-
|
222
|
-
assert_raise(MPD::ServerError) {@mpd.find('error', 'no-such')}
|
223
|
-
|
224
|
-
@mpd.disconnect
|
225
|
-
assert_raise(MPD::ServerError) {@mpd.find('album', 'Are You Shpongled')}
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_kill
|
229
|
-
@mpd.connect
|
230
|
-
|
231
|
-
assert @mpd.kill
|
232
|
-
|
233
|
-
assert !@mpd.connected?
|
234
|
-
|
235
|
-
assert_raise(MPD::ServerError) {@mpd.kill}
|
236
|
-
end
|
237
|
-
|
238
|
-
def test_albums
|
239
|
-
@mpd.connect
|
240
|
-
|
241
|
-
albums = @mpd.albums
|
242
|
-
|
243
|
-
assert_equal 4, albums.size
|
244
|
-
assert_equal 'Are You Shpongled?', albums[0]
|
245
|
-
assert_equal 'Dancing Galaxy', albums[1]
|
246
|
-
assert_equal 'Hydroponic Garden', albums[2]
|
247
|
-
assert_equal 'Nothing Lasts... But Nothing Is Lost', albums[3]
|
248
|
-
|
249
|
-
sh = @mpd.albums 'Shpongle'
|
250
|
-
|
251
|
-
assert_equal 2, sh.size
|
252
|
-
assert_equal 'Are You Shpongled?', sh[0]
|
253
|
-
assert_equal 'Nothing Lasts... But Nothing Is Lost', sh[1]
|
254
|
-
|
255
|
-
@mpd.disconnect
|
256
|
-
assert_raise(MPD::ServerError) {@mpd.albums}
|
257
|
-
end
|
258
|
-
|
259
|
-
def test_artists
|
260
|
-
@mpd.connect
|
261
|
-
|
262
|
-
artists = @mpd.artists
|
263
|
-
|
264
|
-
assert_equal 3, artists.size
|
265
|
-
assert_equal 'Astral Projection', artists[0]
|
266
|
-
assert_equal 'Carbon Based Lifeforms', artists[1]
|
267
|
-
assert_equal 'Shpongle', artists[2]
|
268
|
-
|
269
|
-
@mpd.disconnect
|
270
|
-
assert_raise(MPD::ServerError) {@mpd.artists}
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_list
|
274
|
-
@mpd.connect
|
275
|
-
|
276
|
-
albums = @mpd.list 'album'
|
277
|
-
|
278
|
-
assert_equal 4, albums.size
|
279
|
-
assert_equal 'Are You Shpongled?', albums[0]
|
280
|
-
assert_equal 'Dancing Galaxy', albums[1]
|
281
|
-
assert_equal 'Hydroponic Garden', albums[2]
|
282
|
-
assert_equal 'Nothing Lasts... But Nothing Is Lost', albums[3]
|
283
|
-
|
284
|
-
artists = @mpd.list 'artist'
|
285
|
-
|
286
|
-
assert_equal 3, artists.size
|
287
|
-
assert_equal 'Astral Projection', artists[0]
|
288
|
-
assert_equal 'Carbon Based Lifeforms', artists[1]
|
289
|
-
assert_equal 'Shpongle', artists[2]
|
290
|
-
|
291
|
-
arg = @mpd.list 'album', 'Shpongle'
|
292
|
-
|
293
|
-
assert_equal 2, arg.size
|
294
|
-
assert_equal 'Are You Shpongled?', arg[0]
|
295
|
-
assert_equal 'Nothing Lasts... But Nothing Is Lost', arg[1]
|
296
|
-
|
297
|
-
assert_raise(MPD::ServerError) {@mpd.list('fail')}
|
298
|
-
assert_raise(MPD::ServerError) {@mpd.list('fail', 'Shpongle')}
|
299
|
-
|
300
|
-
@mpd.disconnect
|
301
|
-
assert_raise(MPD::ServerError) {@mpd.artists}
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_directories
|
305
|
-
@mpd.connect
|
306
|
-
|
307
|
-
dirs = @mpd.directories
|
308
|
-
|
309
|
-
assert_equal 7, dirs.size
|
310
|
-
assert_equal 'Astral_Projection', dirs[0]
|
311
|
-
assert_equal 'Astral_Projection/Dancing_Galaxy', dirs[1]
|
312
|
-
assert_equal 'Carbon_Based_Lifeforms', dirs[2]
|
313
|
-
assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden', dirs[3]
|
314
|
-
assert_equal 'Shpongle', dirs[4]
|
315
|
-
assert_equal 'Shpongle/Are_You_Shpongled', dirs[5]
|
316
|
-
assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', dirs[6]
|
317
|
-
|
318
|
-
shpongle = @mpd.directories 'Shpongle'
|
319
|
-
|
320
|
-
assert_equal 3, shpongle.size
|
321
|
-
assert_equal 'Shpongle', shpongle[0]
|
322
|
-
assert_equal 'Shpongle/Are_You_Shpongled', shpongle[1]
|
323
|
-
assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', shpongle[2]
|
324
|
-
|
325
|
-
assert_raise(MPD::ServerError) {@mpd.directories('no-dirs')}
|
326
|
-
|
327
|
-
@mpd.disconnect
|
328
|
-
assert_raise(MPD::ServerError) {@mpd.directories}
|
329
|
-
end
|
330
|
-
|
331
|
-
def test_files
|
332
|
-
@mpd.connect
|
333
|
-
|
334
|
-
files = @mpd.files
|
335
|
-
|
336
|
-
assert_equal 46, files.size
|
337
|
-
|
338
|
-
assert_equal 'Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', files[0]
|
339
|
-
assert_equal 'Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', files[7]
|
340
|
-
assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', files[8]
|
341
|
-
assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/11.Refraction_1.33.ogg', files[18]
|
342
|
-
assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', files[19]
|
343
|
-
assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', files[25]
|
344
|
-
assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', files[26]
|
345
|
-
assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg', files[45]
|
346
|
-
|
347
|
-
sh = @mpd.files 'Shpongle'
|
348
|
-
|
349
|
-
assert_equal 27, sh.size
|
350
|
-
|
351
|
-
assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', sh[0]
|
352
|
-
assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', sh[6]
|
353
|
-
assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', sh[7]
|
354
|
-
assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg', sh[26]
|
355
|
-
|
356
|
-
assert_raise(MPD::ServerError) {@mpd.files('no-files')}
|
357
|
-
|
358
|
-
@mpd.disconnect
|
359
|
-
assert_raise(MPD::ServerError) {@mpd.files}
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_playlists
|
363
|
-
@mpd.connect
|
364
|
-
|
365
|
-
pls = @mpd.playlists
|
366
|
-
|
367
|
-
assert_equal 2, pls.size
|
368
|
-
|
369
|
-
assert_equal 'Shpongle_-_Are_You_Shpongled', pls[0]
|
370
|
-
assert_equal 'Astral_Projection_-_Dancing_Galaxy', pls[1]
|
371
|
-
|
372
|
-
@mpd.disconnect
|
373
|
-
assert_raise(MPD::ServerError) {@mpd.playlists}
|
374
|
-
end
|
375
|
-
|
376
|
-
def test_songs
|
377
|
-
@mpd.connect
|
378
|
-
|
379
|
-
songs = @mpd.songs
|
380
|
-
|
381
|
-
assert_equal 46, songs.size
|
382
|
-
|
383
|
-
assert_equal 'Dancing Galaxy', songs[0].title
|
384
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[7].title
|
385
|
-
assert_equal 'Central Plains', songs[8].title
|
386
|
-
assert_equal 'Refraction 1.33', songs[18].title
|
387
|
-
assert_equal 'Shpongle Falls', songs[19].title
|
388
|
-
assert_equal '... and the Day Turned to Night', songs[25].title
|
389
|
-
assert_equal 'Botanical Dimensions', songs[26].title
|
390
|
-
assert_equal 'Falling Awake', songs[45].title
|
391
|
-
|
392
|
-
sh = @mpd.songs 'Shpongle'
|
393
|
-
|
394
|
-
assert_equal 27, sh.size
|
395
|
-
|
396
|
-
sh.each do |s|
|
397
|
-
assert_equal 'Shpongle', s.artist
|
398
|
-
end
|
399
|
-
|
400
|
-
assert_equal 'Shpongle Falls', sh[0].title
|
401
|
-
assert_equal '... and the Day Turned to Night', sh[6].title
|
402
|
-
assert_equal 'Botanical Dimensions', sh[7].title
|
403
|
-
assert_equal 'Falling Awake', sh[26].title
|
404
|
-
|
405
|
-
assert_raise(MPD::ServerError) {@mpd.songs('no-songs')}
|
406
|
-
|
407
|
-
@mpd.disconnect
|
408
|
-
assert_raise(MPD::ServerError) {@mpd.songs}
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_songs_by_artist
|
412
|
-
@mpd.connect
|
413
|
-
|
414
|
-
songs = @mpd.songs_by_artist 'Shpongle'
|
415
|
-
|
416
|
-
assert_equal 27, songs.size
|
417
|
-
|
418
|
-
songs.each do |s|
|
419
|
-
assert_equal 'Shpongle', s.artist
|
420
|
-
end
|
421
|
-
|
422
|
-
assert_equal 'Shpongle Falls', songs[0].title
|
423
|
-
assert_equal '... and the Day Turned to Night', songs[6].title
|
424
|
-
assert_equal 'Botanical Dimensions', songs[7].title
|
425
|
-
assert_equal 'Falling Awake', songs[26].title
|
426
|
-
|
427
|
-
songs = @mpd.songs_by_artist 'no-songs'
|
428
|
-
assert_equal 0, songs.size
|
429
|
-
|
430
|
-
@mpd.disconnect
|
431
|
-
assert_raise(MPD::ServerError) {@mpd.songs_by_artist('Shpongle')}
|
432
|
-
end
|
433
|
-
|
434
|
-
def test_load
|
435
|
-
@mpd.connect
|
436
|
-
|
437
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
438
|
-
|
439
|
-
pls = @mpd.playlist
|
440
|
-
|
441
|
-
assert_equal 8, pls.size
|
442
|
-
|
443
|
-
pls.each do |song|
|
444
|
-
assert_equal 'Astral Projection', song.artist
|
445
|
-
assert_equal 'Dancing Galaxy', song.album
|
446
|
-
end
|
447
|
-
|
448
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
449
|
-
assert_equal 'Soundform', pls[1].title
|
450
|
-
assert_equal 'Flying Into A Star', pls[2].title
|
451
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
452
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
453
|
-
assert_equal 'Life On Mars', pls[5].title
|
454
|
-
assert_equal 'Liquid Sun', pls[6].title
|
455
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
|
456
|
-
|
457
|
-
assert_raise(MPD::ServerError) {@mpd.load('No-PLS')}
|
458
|
-
|
459
|
-
@mpd.disconnect
|
460
|
-
assert_raise(MPD::ServerError) {@mpd.load('Astral_Projection_-_Dancing_Galaxy')}
|
461
|
-
end
|
462
|
-
|
463
|
-
def test_move
|
464
|
-
@mpd.connect
|
465
|
-
|
466
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
467
|
-
|
468
|
-
assert @mpd.move( 3, 1 )
|
469
|
-
|
470
|
-
pls = @mpd.playlist
|
471
|
-
|
472
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
473
|
-
assert_equal 'No One Ever Dreams', pls[1].title
|
474
|
-
assert_equal 'Soundform', pls[2].title
|
475
|
-
assert_equal 'Flying Into A Star', pls[3].title
|
476
|
-
|
477
|
-
assert @mpd.move( 2, 7 )
|
478
|
-
|
479
|
-
pls = @mpd.playlist
|
480
|
-
|
481
|
-
assert_equal 'No One Ever Dreams', pls[1].title
|
482
|
-
assert_equal 'Flying Into A Star', pls[2].title
|
483
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[3].title
|
484
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[6].title
|
485
|
-
assert_equal 'Soundform', pls[7].title
|
486
|
-
|
487
|
-
assert_raise(MPD::ServerError) {@mpd.move(999,1)}
|
488
|
-
|
489
|
-
@mpd.disconnect
|
490
|
-
assert_raise(MPD::ServerError) {@mpd.move(3,1)}
|
491
|
-
end
|
492
|
-
|
493
|
-
def test_moveid
|
494
|
-
@mpd.connect
|
495
|
-
|
496
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
497
|
-
|
498
|
-
assert @mpd.moveid( 10, 1 )
|
499
|
-
|
500
|
-
pls = @mpd.playlist
|
501
|
-
|
502
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
503
|
-
assert_equal 'No One Ever Dreams', pls[1].title
|
504
|
-
assert_equal 'Soundform', pls[2].title
|
505
|
-
assert_equal 'Flying Into A Star', pls[3].title
|
506
|
-
|
507
|
-
assert @mpd.moveid( 8, 7 )
|
508
|
-
|
509
|
-
pls = @mpd.playlist
|
510
|
-
|
511
|
-
assert_equal 'No One Ever Dreams', pls[1].title
|
512
|
-
assert_equal 'Flying Into A Star', pls[2].title
|
513
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[3].title
|
514
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[6].title
|
515
|
-
assert_equal 'Soundform', pls[7].title
|
516
|
-
|
517
|
-
assert_raise(MPD::ServerError) {@mpd.moveid(999,1)}
|
518
|
-
|
519
|
-
@mpd.disconnect
|
520
|
-
assert_raise(MPD::ServerError) {@mpd.moveid(10,1)}
|
521
|
-
|
522
|
-
end
|
523
|
-
|
524
|
-
def test_next
|
525
|
-
@mpd.connect
|
526
|
-
|
527
|
-
@mpd.load 'Astral_Projection_-_Dancing_Galaxy'
|
528
|
-
|
529
|
-
@mpd.play 3
|
530
|
-
|
531
|
-
pos = @mpd.status['song'].to_i
|
532
|
-
|
533
|
-
assert @mpd.next
|
534
|
-
|
535
|
-
assert_equal pos + 1, @mpd.status['song'].to_i
|
536
|
-
|
537
|
-
@mpd.disconnect
|
538
|
-
assert_raise(MPD::ServerError) {@mpd.next}
|
539
|
-
end
|
540
|
-
|
541
|
-
def test_pause
|
542
|
-
@mpd.connect
|
543
|
-
assert @mpd.connected?
|
544
|
-
|
545
|
-
@mpd.load 'Astral_Projection_-_Dancing_Galaxy'
|
546
|
-
|
547
|
-
assert @mpd.play
|
548
|
-
assert @mpd.playing?
|
549
|
-
|
550
|
-
@mpd.pause = true
|
551
|
-
assert @mpd.paused?
|
552
|
-
|
553
|
-
@mpd.pause = false
|
554
|
-
assert !@mpd.paused?
|
555
|
-
|
556
|
-
assert @mpd.stop
|
557
|
-
assert @mpd.stopped?
|
558
|
-
|
559
|
-
@mpd.pause = true
|
560
|
-
assert @mpd.stopped?
|
561
|
-
|
562
|
-
assert !@mpd.paused?
|
563
|
-
|
564
|
-
@mpd.disconnect
|
565
|
-
assert_raise(MPD::ServerError) {@mpd.pause = true}
|
566
|
-
assert_raise(MPD::ServerError) {@mpd.paused?}
|
567
|
-
end
|
568
|
-
|
569
|
-
def test_password
|
570
|
-
@mpd.connect
|
571
|
-
|
572
|
-
assert_raise(MPD::ServerError) {@mpd.password('wrong')}
|
573
|
-
|
574
|
-
assert @mpd.password('test')
|
575
|
-
|
576
|
-
@mpd.disconnect
|
577
|
-
assert_raise(MPD::ServerError) {@mpd.password('test')}
|
578
|
-
end
|
579
|
-
|
580
|
-
def test_ping
|
581
|
-
@mpd.connect
|
582
|
-
|
583
|
-
assert @mpd.ping
|
584
|
-
|
585
|
-
@mpd.disconnect
|
586
|
-
assert_raise(MPD::ServerError) {@mpd.ping}
|
587
|
-
end
|
588
|
-
|
589
|
-
def test_play
|
590
|
-
@mpd.connect
|
591
|
-
assert @mpd.connected?
|
592
|
-
|
593
|
-
@mpd.load 'Astral_Projection_-_Dancing_Galaxy'
|
594
|
-
|
595
|
-
assert @mpd.play
|
596
|
-
|
597
|
-
sleep 2
|
598
|
-
|
599
|
-
assert @mpd.playing?
|
600
|
-
|
601
|
-
song = @mpd.current_song
|
602
|
-
|
603
|
-
assert_equal 'Dancing Galaxy', song.title
|
604
|
-
|
605
|
-
assert @mpd.play(2)
|
606
|
-
|
607
|
-
sleep 2
|
608
|
-
|
609
|
-
assert @mpd.playing?
|
610
|
-
|
611
|
-
song = @mpd.current_song
|
612
|
-
|
613
|
-
assert_equal 'Flying Into A Star', song.title
|
614
|
-
|
615
|
-
@mpd.disconnect
|
616
|
-
assert_raise(MPD::ServerError) {@mpd.play}
|
617
|
-
assert_raise(MPD::ServerError) {@mpd.playing?}
|
618
|
-
end
|
619
|
-
|
620
|
-
def test_playid
|
621
|
-
@mpd.connect
|
622
|
-
assert @mpd.connected?
|
623
|
-
|
624
|
-
@mpd.load 'Astral_Projection_-_Dancing_Galaxy'
|
625
|
-
|
626
|
-
assert @mpd.playid
|
627
|
-
|
628
|
-
sleep 2
|
629
|
-
|
630
|
-
assert @mpd.playing?
|
631
|
-
|
632
|
-
song = @mpd.current_song
|
633
|
-
|
634
|
-
assert_equal 'Dancing Galaxy', song.title
|
635
|
-
|
636
|
-
assert @mpd.playid(9)
|
637
|
-
|
638
|
-
sleep 2
|
639
|
-
|
640
|
-
assert @mpd.playing?
|
641
|
-
|
642
|
-
song = @mpd.current_song
|
643
|
-
|
644
|
-
assert_equal 'Flying Into A Star', song.title
|
645
|
-
|
646
|
-
@mpd.disconnect
|
647
|
-
assert_raise(MPD::ServerError) {@mpd.playid}
|
648
|
-
assert_raise(MPD::ServerError) {@mpd.playing?}
|
649
|
-
|
650
|
-
end
|
651
|
-
|
652
|
-
def test_playlist_version
|
653
|
-
@mpd.connect
|
654
|
-
|
655
|
-
ver = @mpd.playlist_version
|
656
|
-
|
657
|
-
assert_equal 1, ver
|
658
|
-
|
659
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
660
|
-
|
661
|
-
ver = @mpd.playlist_version
|
662
|
-
|
663
|
-
assert_equal 9, ver
|
664
|
-
|
665
|
-
@mpd.disconnect
|
666
|
-
assert_raise(MPD::ServerError) {@mpd.playlist_version}
|
667
|
-
end
|
668
|
-
|
669
|
-
def test_playlist
|
670
|
-
@mpd.connect
|
671
|
-
|
672
|
-
pls = @mpd.playlist
|
673
|
-
|
674
|
-
assert_equal 0, pls.size
|
675
|
-
|
676
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
677
|
-
|
678
|
-
pls = @mpd.playlist
|
679
|
-
|
680
|
-
assert_equal 8, pls.size
|
681
|
-
|
682
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
683
|
-
assert_equal 'Soundform', pls[1].title
|
684
|
-
assert_equal 'Flying Into A Star', pls[2].title
|
685
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
686
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
687
|
-
assert_equal 'Life On Mars', pls[5].title
|
688
|
-
assert_equal 'Liquid Sun', pls[6].title
|
689
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
|
690
|
-
|
691
|
-
@mpd.disconnect
|
692
|
-
assert_raise(MPD::ServerError) {@mpd.playlist}
|
693
|
-
end
|
694
|
-
|
695
|
-
def test_song_at_pos
|
696
|
-
@mpd.connect
|
697
|
-
|
698
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
699
|
-
|
700
|
-
assert_equal 'Dancing Galaxy', @mpd.song_at_pos(0).title
|
701
|
-
assert_equal 'Soundform', @mpd.song_at_pos(1).title
|
702
|
-
assert_equal 'Flying Into A Star', @mpd.song_at_pos(2).title
|
703
|
-
assert_equal 'No One Ever Dreams', @mpd.song_at_pos(3).title
|
704
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', @mpd.song_at_pos(4).title
|
705
|
-
assert_equal 'Life On Mars', @mpd.song_at_pos(5).title
|
706
|
-
assert_equal 'Liquid Sun', @mpd.song_at_pos(6).title
|
707
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', @mpd.song_at_pos(7).title
|
708
|
-
|
709
|
-
assert_raise(MPD::ServerError) {@mpd.song_at_pos(999)}
|
710
|
-
|
711
|
-
@mpd.disconnect
|
712
|
-
assert_raise(MPD::ServerError) {@mpd.song_at_pos(0)}
|
713
|
-
end
|
714
|
-
|
715
|
-
def test_song_with_id
|
716
|
-
@mpd.connect
|
717
|
-
|
718
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
719
|
-
|
720
|
-
assert_equal 'Dancing Galaxy', @mpd.song_with_id(7).title
|
721
|
-
assert_equal 'Soundform', @mpd.song_with_id(8).title
|
722
|
-
assert_equal 'Flying Into A Star', @mpd.song_with_id(9).title
|
723
|
-
assert_equal 'No One Ever Dreams', @mpd.song_with_id(10).title
|
724
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', @mpd.song_with_id(11).title
|
725
|
-
assert_equal 'Life On Mars', @mpd.song_with_id(12).title
|
726
|
-
assert_equal 'Liquid Sun', @mpd.song_with_id(13).title
|
727
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', @mpd.song_with_id(14).title
|
728
|
-
|
729
|
-
assert_raise(MPD::ServerError) {@mpd.song_with_id(999)}
|
730
|
-
|
731
|
-
@mpd.disconnect
|
732
|
-
assert_raise(MPD::ServerError) {@mpd.song_with_id(10)}
|
733
|
-
end
|
734
|
-
|
735
|
-
def test_playlist_changes
|
736
|
-
@mpd.connect
|
737
|
-
|
738
|
-
assert @mpd.add('Astral_Projection')
|
739
|
-
|
740
|
-
changes = @mpd.playlist_changes 8
|
741
|
-
|
742
|
-
assert_equal 1, changes.size
|
743
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', changes[0].title
|
744
|
-
|
745
|
-
changes = @mpd.playlist_changes 1
|
746
|
-
|
747
|
-
assert_equal 8, changes.size
|
748
|
-
assert_equal 'Dancing Galaxy', changes[0].title
|
749
|
-
assert_equal 'Soundform', changes[1].title
|
750
|
-
assert_equal 'Flying Into A Star', changes[2].title
|
751
|
-
assert_equal 'No One Ever Dreams', changes[3].title
|
752
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', changes[4].title
|
753
|
-
assert_equal 'Life On Mars', changes[5].title
|
754
|
-
assert_equal 'Liquid Sun', changes[6].title
|
755
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', changes[7].title
|
756
|
-
|
757
|
-
changes = @mpd.playlist_changes 999
|
758
|
-
|
759
|
-
assert_equal 8, changes.size
|
760
|
-
|
761
|
-
@mpd.disconnect
|
762
|
-
assert_raise(MPD::ServerError) {@mpd.playlist_changes(9)}
|
763
|
-
end
|
764
|
-
|
765
|
-
def test_previous
|
766
|
-
@mpd.connect
|
767
|
-
|
768
|
-
@mpd.load 'Astral_Projection_-_Dancing_Galaxy'
|
769
|
-
|
770
|
-
@mpd.play 3
|
771
|
-
|
772
|
-
sleep 2
|
773
|
-
|
774
|
-
assert @mpd.playing?
|
775
|
-
|
776
|
-
pos = @mpd.status['song'].to_i
|
777
|
-
|
778
|
-
assert @mpd.previous
|
779
|
-
|
780
|
-
assert_equal pos - 1, @mpd.status['song'].to_i
|
781
|
-
|
782
|
-
@mpd.disconnect
|
783
|
-
assert_raise(MPD::ServerError) {@mpd.previous}
|
784
|
-
end
|
785
|
-
|
786
|
-
def test_random
|
787
|
-
@mpd.connect
|
788
|
-
|
789
|
-
@mpd.random = true
|
790
|
-
assert @mpd.random?
|
791
|
-
|
792
|
-
@mpd.random = false
|
793
|
-
assert !@mpd.random?
|
794
|
-
|
795
|
-
@mpd.disconnect
|
796
|
-
assert_raise(MPD::ServerError) {@mpd.random = false}
|
797
|
-
assert_raise(MPD::ServerError) {@mpd.random?}
|
798
|
-
end
|
799
|
-
|
800
|
-
def test_repeat
|
801
|
-
@mpd.connect
|
802
|
-
|
803
|
-
@mpd.repeat = true
|
804
|
-
assert @mpd.repeat?
|
805
|
-
|
806
|
-
@mpd.repeat = false
|
807
|
-
assert !@mpd.repeat?
|
808
|
-
|
809
|
-
@mpd.disconnect
|
810
|
-
assert_raise(MPD::ServerError) {@mpd.repeat = false}
|
811
|
-
assert_raise(MPD::ServerError) {@mpd.repeat?}
|
812
|
-
end
|
813
|
-
|
814
|
-
def test_rm
|
815
|
-
@mpd.connect
|
816
|
-
|
817
|
-
assert @mpd.rm('Astral_Projection_-_Dancing_Galaxy')
|
818
|
-
|
819
|
-
pls = @mpd.playlists
|
820
|
-
|
821
|
-
assert 1, pls.size
|
822
|
-
|
823
|
-
assert_equal 'Shpongle_-_Are_You_Shpongled', pls[0]
|
824
|
-
|
825
|
-
assert_raise(MPD::ServerError) {@mpd.rm('Not-Exist')}
|
826
|
-
|
827
|
-
@mpd.disconnect
|
828
|
-
assert_raise(MPD::ServerError) {@mpd.rm('Astral_Projection_-_Dancing_Galaxy')}
|
829
|
-
end
|
830
|
-
|
831
|
-
def test_save
|
832
|
-
@mpd.connect
|
833
|
-
|
834
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
835
|
-
assert @mpd.load('Shpongle_-_Are_You_Shpongled')
|
836
|
-
|
837
|
-
assert @mpd.save('UnitTests')
|
838
|
-
|
839
|
-
assert @mpd.clear
|
840
|
-
|
841
|
-
assert @mpd.load('UnitTests')
|
842
|
-
|
843
|
-
pls = @mpd.playlist
|
844
|
-
|
845
|
-
assert_equal 15, pls.size
|
846
|
-
|
847
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
848
|
-
assert_equal 'Soundform', pls[1].title
|
849
|
-
assert_equal 'Flying Into A Star', pls[2].title
|
850
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
851
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
852
|
-
assert_equal 'Life On Mars', pls[5].title
|
853
|
-
assert_equal 'Liquid Sun', pls[6].title
|
854
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
|
855
|
-
assert_equal 'Shpongle Falls', pls[8].title
|
856
|
-
assert_equal 'Monster Hit', pls[9].title
|
857
|
-
assert_equal 'Vapour Rumours', pls[10].title
|
858
|
-
assert_equal 'Shpongle Spores', pls[11].title
|
859
|
-
assert_equal 'Behind Closed Eyelids', pls[12].title
|
860
|
-
assert_equal 'Divine Moments of Truth', pls[13].title
|
861
|
-
assert_equal '... and the Day Turned to Night', pls[14].title
|
862
|
-
|
863
|
-
@mpd.disconnect
|
864
|
-
assert_raise(MPD::ServerError) {@mpd.save('test')}
|
865
|
-
end
|
866
|
-
|
867
|
-
def test_search
|
868
|
-
@mpd.connect
|
869
|
-
|
870
|
-
a = @mpd.search 'album', 'ydroponic gar'
|
871
|
-
|
872
|
-
assert_equal 11, a.size
|
873
|
-
a.each do |song|
|
874
|
-
assert_equal 'Carbon Based Lifeforms', song.artist
|
875
|
-
assert_equal 'Hydroponic Garden', song.album
|
876
|
-
end
|
877
|
-
|
878
|
-
b = @mpd.search 'artist', 'hpon'
|
879
|
-
|
880
|
-
assert_equal 27, b.size
|
881
|
-
b.each do |song|
|
882
|
-
assert_equal 'Shpongle', song.artist
|
883
|
-
end
|
884
|
-
|
885
|
-
c = @mpd.search 'title', 'falls'
|
886
|
-
assert_equal 1, c.size
|
887
|
-
assert_equal 'Shpongle', c[0].artist
|
888
|
-
assert_equal 'Shpongle Falls', c[0].title
|
889
|
-
assert_equal 'Are You Shpongled?', c[0].album
|
890
|
-
|
891
|
-
d = @mpd.search 'filename', 'disco_valley'
|
892
|
-
assert_equal 1, d.size
|
893
|
-
assert_equal 'Astral Projection', d[0].artist
|
894
|
-
assert_equal 'Dancing Galaxy', d[0].album
|
895
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', d[0].title
|
896
|
-
|
897
|
-
z = @mpd.search 'title', 'no-title'
|
898
|
-
assert_equal 0, z.size
|
899
|
-
|
900
|
-
assert_raise(MPD::ServerError) {@mpd.search('error', 'nosuch')}
|
901
|
-
|
902
|
-
@mpd.disconnect
|
903
|
-
assert_raise(MPD::ServerError) {@mpd.search('artist','searching')}
|
904
|
-
end
|
905
|
-
|
906
|
-
def test_seek
|
907
|
-
@mpd.connect
|
908
|
-
|
909
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
910
|
-
|
911
|
-
assert @mpd.play
|
912
|
-
|
913
|
-
sleep 2
|
914
|
-
|
915
|
-
assert @mpd.pause = true
|
916
|
-
|
917
|
-
sleep 2
|
918
|
-
|
919
|
-
assert @mpd.seek(2, 200)
|
920
|
-
|
921
|
-
sleep 2
|
922
|
-
|
923
|
-
song = @mpd.current_song
|
924
|
-
|
925
|
-
assert_equal 'Flying Into A Star', song.title
|
926
|
-
|
927
|
-
status = @mpd.status
|
928
|
-
|
929
|
-
assert_equal '200:585', status['time']
|
930
|
-
|
931
|
-
@mpd.disconnect
|
932
|
-
assert_raise(MPD::ServerError) {@mpd.seek(1, 100)}
|
933
|
-
end
|
934
|
-
|
935
|
-
def test_seekid
|
936
|
-
@mpd.connect
|
937
|
-
|
938
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
939
|
-
|
940
|
-
assert @mpd.play
|
941
|
-
|
942
|
-
sleep 2
|
943
|
-
|
944
|
-
assert @mpd.pause = true
|
945
|
-
|
946
|
-
sleep 2
|
947
|
-
|
948
|
-
assert @mpd.seekid(9, 200)
|
949
|
-
|
950
|
-
sleep 2
|
951
|
-
|
952
|
-
song = @mpd.current_song
|
953
|
-
|
954
|
-
assert_equal 'Flying Into A Star', song.title
|
955
|
-
|
956
|
-
status = @mpd.status
|
957
|
-
|
958
|
-
assert_equal '200:585', status['time']
|
959
|
-
|
960
|
-
@mpd.disconnect
|
961
|
-
assert_raise(MPD::ServerError) {@mpd.seekid(1, 100)}
|
962
|
-
end
|
963
|
-
|
964
|
-
def test_volume
|
965
|
-
@mpd.connect
|
966
|
-
|
967
|
-
vol = @mpd.volume
|
968
|
-
|
969
|
-
@mpd.volume = 30
|
970
|
-
assert_equal 30, @mpd.volume
|
971
|
-
|
972
|
-
@mpd.volume = vol
|
973
|
-
assert_equal vol, @mpd.volume
|
974
|
-
|
975
|
-
@mpd.disconnect
|
976
|
-
assert_raise(MPD::ServerError) {@mpd.volume = 10}
|
977
|
-
assert_raise(MPD::ServerError) {@mpd.volume}
|
978
|
-
end
|
979
|
-
|
980
|
-
def test_shuffle
|
981
|
-
@mpd.connect
|
982
|
-
|
983
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
984
|
-
|
985
|
-
assert @mpd.shuffle
|
986
|
-
|
987
|
-
pls = @mpd.playlist
|
988
|
-
|
989
|
-
assert_equal 8, pls.size
|
990
|
-
assert_not_equal 'Dancing Galaxy', pls[0].title
|
991
|
-
|
992
|
-
@mpd.disconnect
|
993
|
-
assert_raise(MPD::ServerError) {@mpd.shuffle}
|
994
|
-
end
|
995
|
-
|
996
|
-
def test_stats
|
997
|
-
@mpd.connect
|
998
|
-
|
999
|
-
stats = @mpd.stats
|
1000
|
-
|
1001
|
-
assert_equal '3', stats['artists']
|
1002
|
-
assert_equal '4', stats['albums']
|
1003
|
-
assert_equal '46', stats['songs']
|
1004
|
-
assert_equal '500', stats['uptime']
|
1005
|
-
|
1006
|
-
@mpd.disconnect
|
1007
|
-
assert_raise(MPD::ServerError) {@mpd.stats}
|
1008
|
-
end
|
1009
|
-
|
1010
|
-
def test_status
|
1011
|
-
@mpd.connect
|
1012
|
-
|
1013
|
-
status = @mpd.status
|
1014
|
-
|
1015
|
-
assert_equal 'stop', status['state']
|
1016
|
-
assert_equal '0', status['repeat']
|
1017
|
-
assert_equal '0', status['random']
|
1018
|
-
|
1019
|
-
@mpd.disconnect
|
1020
|
-
assert_raise(MPD::ServerError) {@mpd.status}
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
def test_stop
|
1024
|
-
@mpd.connect
|
1025
|
-
assert @mpd.connected?
|
1026
|
-
|
1027
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
1028
|
-
|
1029
|
-
assert @mpd.play
|
1030
|
-
assert @mpd.playing?
|
1031
|
-
|
1032
|
-
assert @mpd.stop
|
1033
|
-
assert @mpd.stopped?
|
1034
|
-
|
1035
|
-
assert !@mpd.playing?
|
1036
|
-
|
1037
|
-
@mpd.disconnect
|
1038
|
-
assert_raise(MPD::ServerError) {@mpd.stop}
|
1039
|
-
assert_raise(MPD::ServerError) {@mpd.stopped?}
|
1040
|
-
end
|
1041
|
-
|
1042
|
-
def test_swap
|
1043
|
-
@mpd.connect
|
1044
|
-
|
1045
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
1046
|
-
|
1047
|
-
assert @mpd.swap(2,5)
|
1048
|
-
|
1049
|
-
pls = @mpd.playlist
|
1050
|
-
|
1051
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
1052
|
-
assert_equal 'Soundform', pls[1].title
|
1053
|
-
assert_equal 'Flying Into A Star', pls[5].title
|
1054
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
1055
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
1056
|
-
assert_equal 'Life On Mars', pls[2].title
|
1057
|
-
assert_equal 'Liquid Sun', pls[6].title
|
1058
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
|
1059
|
-
|
1060
|
-
assert @mpd.swap(7,1)
|
1061
|
-
|
1062
|
-
pls = @mpd.playlist
|
1063
|
-
|
1064
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
1065
|
-
assert_equal 'Soundform', pls[7].title
|
1066
|
-
assert_equal 'Flying Into A Star', pls[5].title
|
1067
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
1068
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
1069
|
-
assert_equal 'Life On Mars', pls[2].title
|
1070
|
-
assert_equal 'Liquid Sun', pls[6].title
|
1071
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[1].title
|
1072
|
-
|
1073
|
-
assert_raise(MPD::ServerError) {@mpd.swap(999,1)}
|
1074
|
-
|
1075
|
-
@mpd.disconnect
|
1076
|
-
assert_raise(MPD::ServerError) {@mpd.swap(2, 5)}
|
1077
|
-
end
|
1078
|
-
|
1079
|
-
def test_swapid
|
1080
|
-
@mpd.connect
|
1081
|
-
|
1082
|
-
assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
|
1083
|
-
|
1084
|
-
assert @mpd.swapid(9,12)
|
1085
|
-
|
1086
|
-
pls = @mpd.playlist
|
1087
|
-
|
1088
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
1089
|
-
assert_equal 'Soundform', pls[1].title
|
1090
|
-
assert_equal 'Flying Into A Star', pls[5].title
|
1091
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
1092
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
1093
|
-
assert_equal 'Life On Mars', pls[2].title
|
1094
|
-
assert_equal 'Liquid Sun', pls[6].title
|
1095
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
|
1096
|
-
|
1097
|
-
assert @mpd.swapid(14,8)
|
1098
|
-
|
1099
|
-
pls = @mpd.playlist
|
1100
|
-
|
1101
|
-
assert_equal 'Dancing Galaxy', pls[0].title
|
1102
|
-
assert_equal 'Soundform', pls[7].title
|
1103
|
-
assert_equal 'Flying Into A Star', pls[5].title
|
1104
|
-
assert_equal 'No One Ever Dreams', pls[3].title
|
1105
|
-
assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
|
1106
|
-
assert_equal 'Life On Mars', pls[2].title
|
1107
|
-
assert_equal 'Liquid Sun', pls[6].title
|
1108
|
-
assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[1].title
|
1109
|
-
|
1110
|
-
assert_raise(MPD::ServerError) {@mpd.swapid(999,8)}
|
1111
|
-
|
1112
|
-
@mpd.disconnect
|
1113
|
-
assert_raise(MPD::ServerError) {@mpd.swapid(9, 12)}
|
1114
|
-
end
|
1115
|
-
|
1116
|
-
def test_update
|
1117
|
-
@mpd.connect
|
1118
|
-
|
1119
|
-
ret = @mpd.update
|
1120
|
-
|
1121
|
-
assert_equal 1, ret
|
1122
|
-
|
1123
|
-
status = @mpd.status
|
1124
|
-
|
1125
|
-
assert_equal '1', status['updating_db']
|
1126
|
-
|
1127
|
-
status = @mpd.status
|
1128
|
-
|
1129
|
-
assert_nil status['updating_db']
|
1130
|
-
|
1131
|
-
@mpd.disconnect
|
1132
|
-
assert_raise(MPD::ServerError) {@mpd.update}
|
1133
|
-
end
|
1134
|
-
end
|