ruby-mpd 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,88 @@
1
+ class MPD
2
+ module Plugins
3
+ # Commands related to setting various aspects and modes of playback.
4
+ #
5
+ # Changes: setvol -> volume.
6
+ module PlaybackOptions
7
+
8
+ # Enable/disable consume mode.
9
+ # @since MPD 0.16
10
+ # When consume is activated, each song played is removed from playlist
11
+ # after playing.
12
+ # @macro returnraise
13
+ def consume=(toggle)
14
+ send_command :consume, toggle
15
+ end
16
+
17
+ # Set the crossfade between songs in seconds.
18
+ # @macro returnraise
19
+ def crossfade=(seconds)
20
+ send_command :crossfade, seconds
21
+ end
22
+
23
+ # Sets the threshold at which songs will be overlapped. Like crossfading
24
+ # but doesn't fade the track volume, just overlaps. The songs need to have
25
+ # MixRamp tags added by an external tool. 0dB is the normalized maximum
26
+ # volume so use negative values, I prefer -17dB. In the absence of mixramp
27
+ # tags crossfading will be used. See http://sourceforge.net/projects/mixramp
28
+ # @param [Float] decibels Maximum volume level in decibels.
29
+ def mixrampdb=(decibels)
30
+ send_command :mixrampdb, decibels
31
+ end
32
+
33
+ # Additional time subtracted from the overlap calculated by mixrampdb.
34
+ # A value of "nan" or Float::NAN disables MixRamp overlapping and falls
35
+ # back to crossfading.
36
+ def mixrampdelay=(seconds)
37
+ send_command :mixrampdelay, seconds
38
+ end
39
+
40
+ # Enable/disable random playback.
41
+ # @macro returnraise
42
+ def random=(toggle)
43
+ send_command :random, toggle
44
+ end
45
+
46
+ # Enable/disable repeat mode.
47
+ # @macro returnraise
48
+ def repeat=(toggle)
49
+ send_command :repeat, toggle
50
+ end
51
+
52
+ # Sets the volume level. (Maps to MPD's +setvol+)
53
+ # @param [Integer] vol Volume level between 0 and 100.
54
+ # @macro returnraise
55
+ def volume=(vol)
56
+ send_command :setvol, vol
57
+ end
58
+
59
+ # Enable/disable single mode.
60
+ # @since MPD 0.15
61
+ # When single is activated, playback is stopped after current song,
62
+ # or song is repeated if the 'repeat' mode is enabled.
63
+ # @macro returnraise
64
+ def single=(toggle)
65
+ send_command :single, toggle
66
+ end
67
+
68
+ # Sets the replay gain mode. One of :off, :track, :album, :auto.
69
+ # @since MPD 0.16
70
+ # Changing the mode during playback may take several seconds, because
71
+ # the new settings does not affect the buffered data.
72
+ #
73
+ # This command triggers the options idle event.
74
+ # @macro returnraise
75
+ def replay_gain_mode=(mode)
76
+ send_command :replay_gain_mode, mode
77
+ end
78
+
79
+ # Prints replay gain options. Currently, only the variable
80
+ # +:replay_gain_mode+ is returned.
81
+ # @since MPD 0.16
82
+ def replay_gain_status
83
+ send_command :replay_gain_status
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,17 @@
1
+ class MPD
2
+ module Plugins
3
+ # These commands manipulate stored playlists.
4
+ #
5
+ # Changes: listplaylists -> playlists.
6
+ module Playlists
7
+
8
+ # List all of the playlists in the database
9
+ #
10
+ # @return [Array<Hash>] Array of playlists
11
+ def playlists
12
+ send_command(:listplaylists).map {|opt| MPD::Playlist.new(self, opt)}
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,125 @@
1
+ class MPD
2
+ module Plugins
3
+ # These commands manipulate the current playlist, what's playing now.
4
+ # For a distinction between this and other playlists, this is called
5
+ # queue.
6
+ # Changes: playlistinfo -> queue, plchanges -> queue_changes,
7
+ # playlistid -> song_with_id.
8
+ module Queue
9
+
10
+ # List the current playlist/queue.
11
+ # An Integer or Range can be used to limit the information returned
12
+ # to a specific subset.
13
+ #
14
+ # @return [MPD::Song, Array<MPD::Song>] Array of songs in the queue
15
+ # or a single song.
16
+ def queue(limit=nil)
17
+ build_songs_list send_command(:playlistinfo, limit)
18
+ end
19
+
20
+ # Add the file _path_ to the queue. If path is a directory,
21
+ # it will be added *recursively*.
22
+ # @macro returnraise
23
+ def add(path)
24
+ send_command :add, path
25
+ end
26
+
27
+ # Adds a song to the queue (*non-recursive*) and returns the song id.
28
+ # Optionally, one can specify the position on which to add the song (since MPD 0.14).
29
+ def addid(path, pos=nil)
30
+ send_command :addid, pos
31
+ end
32
+
33
+ # Clears the current queue.
34
+ # @macro returnraise
35
+ def clear
36
+ send_command :clear
37
+ end
38
+
39
+ # Deletes the song from the queue.
40
+ #
41
+ # Since MPD 0.15 a range can also be passed. Songs with positions within range will be deleted.
42
+ # @param [Integer, Range] pos Song with position in the queue will be deleted,
43
+ # if range is passed, songs with positions within range will be deleted.
44
+ # @macro returnraise
45
+ def delete(pos)
46
+ send_command :delete, pos
47
+ end
48
+
49
+ # Delete the song with the +songid+ from the queue.
50
+ # @macro returnraise
51
+ def deleteid(songid)
52
+ send_command :deleteid, songid
53
+ end
54
+
55
+ # Move the song at +from+ to +to+ in the queue.
56
+ # * Since 0.14, +to+ can be a negative number, which is the offset
57
+ # of the song from the currently playing (or to-be-played) song.
58
+ # So -1 would mean the song would be moved to be the next song in the queue.
59
+ # Moving a song to -queue.length will move it to the song _before_ the current
60
+ # song on the queue; so this will work for repeating playlists, too.
61
+ # * Since 0.15, +from+ can be a range of songs to move.
62
+ # @macro returnraise
63
+ def move(from, to)
64
+ send_command :move, from, to
65
+ end
66
+
67
+ # Move the song with the +songid+ to +to+ in the queue.
68
+ # @macro returnraise
69
+ def moveid(songid, to)
70
+ send_command :moveid, songid, to
71
+ end
72
+
73
+ # playlistfind
74
+
75
+ # Returns the song with the +songid+ in the playlist,
76
+ # @return [MPD::Song]
77
+ def song_with_id(songid)
78
+ Song.new send_command(:playlistid, songid)
79
+ end
80
+
81
+ # playlistsearch
82
+
83
+ # List the changes since the specified version in the queue.
84
+ # @return [Array<MPD::Song>]
85
+ def queue_changes(version)
86
+ build_songs_list send_command(:plchanges, version)
87
+ end
88
+
89
+ # plchangesposid
90
+
91
+ # prio
92
+
93
+ # prioid
94
+
95
+ # Shuffles the queue.
96
+ # Optionally, a Range can be used to shuffle a specific subset.
97
+ # @macro returnraise
98
+ def shuffle(range)
99
+ send_command :shuffle, range
100
+ end
101
+
102
+ # Swaps the song at position +posA+ with the song
103
+ # as position +posB+ in the queue.
104
+ # @macro returnraise
105
+ def swap(posA, posB)
106
+ send_command :swap, posA, posB
107
+ end
108
+
109
+ # Swaps the positions of the song with the id +songidA+
110
+ # with the song with the id +songidB+ in the queue.
111
+ # @macro returnraise
112
+ def swapid(songidA, songidB)
113
+ send_command :swapid, songidA, songidB
114
+ end
115
+
116
+ # Saves the current playlist/queue to +playlist+.m3u in the
117
+ # playlist directory.
118
+ # @macro returnraise
119
+ def save(playlist)
120
+ send_command :save, playlist
121
+ end
122
+
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,46 @@
1
+ class MPD
2
+ module Plugins
3
+ # Informational commands regarding MPD's internals and config.
4
+ #
5
+ # Changes: tagtypes was mapped to tags and gets fetched only once.
6
+ module Reflection
7
+ # Returns the config of MPD (currently only music_directory).
8
+ # Only works if connected trough an UNIX domain socket.
9
+ # @return [Hash] Configuration of MPD
10
+ def config
11
+ send_command :config
12
+ end
13
+
14
+ # Shows which commands the current user has access to.
15
+ # @return [Array<Symbol>] Array of command names.
16
+ def commands
17
+ send_command :commands
18
+ end
19
+
20
+ # Shows which commands the current user does not have access to.
21
+ # @return [Array<Symbol>] Array of command names.
22
+ def notcommands
23
+ send_command :notcommands
24
+ end
25
+
26
+ # Gets a list of available URL handlers.
27
+ # @return [Array<String>] Array of URL's MPD can handle.
28
+ def url_handlers
29
+ send_command :urlhandlers
30
+ end
31
+
32
+ # Get a list of decoder plugins, with by their supported suffixes
33
+ # and MIME types.
34
+ # @return [Array<Hash>] An array of hashes, one per decoder.
35
+ def decoders
36
+ send_command :decoders
37
+ end
38
+
39
+ # Get a list of available song metadata.
40
+ # @return [Array] An array of tags.
41
+ def tags
42
+ @tags ||= send_command(:tagtypes).map {|tag| tag.downcase }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ class MPD
2
+ module Plugins
3
+ # "Stickers" are pieces of information attached to existing MPD objects
4
+ # (e.g. song files, directories, albums). Clients can create arbitrary
5
+ # name/value pairs. MPD itself does not assume any special meaning in them.
6
+ #
7
+ # The goal is to allow clients to share additional (possibly dynamic) information
8
+ # about songs, which is neither stored on the client (not available to other clients),
9
+ # nor stored in the song files (MPD has no write access).
10
+ #
11
+ # Client developers should create a standard for common sticker names, to ensure
12
+ # interoperability.
13
+ #
14
+ # Objects which may have stickers are addressed by their object type ("song" for song objects)
15
+ # and their URI (the path within the database for songs).
16
+ module Stickers
17
+
18
+ # seems that type is always :song, supposedly directory and
19
+ # playlist too "(e.g. song files, directories, albums)"
20
+
21
+ # Reads a sticker value for the specified object.
22
+ def get_sticker(type, uri, name)
23
+ send_command :sticker, :get, type, uri, name
24
+ end
25
+
26
+ # Adds a sticker value to the specified object. If a sticker
27
+ # item with that name already exists, it is replaced.
28
+ def set_sticker(type, uri, name, value)
29
+ send_command :sticker, :set, type, uri, name
30
+ end
31
+
32
+ # Deletes a sticker value from the specified object. If you do
33
+ # not specify a sticker name, all sticker values are deleted.
34
+ def delete_sticker(type, uri, name = nil)
35
+ send_command :sticker, :delete, type, uri, name
36
+ end
37
+
38
+ # Lists the stickers for the specified object.
39
+ def list_stickers(type, uri)
40
+ send_command :sticker, :list, type, uri
41
+ end
42
+
43
+ # Searches the sticker database for stickers with the specified name,
44
+ # below the specified directory (URI). For each matching song, it prints
45
+ # the URI and that one sticker's value.
46
+ def find_sticker(type, uri, name)
47
+ send_command :sticker, :find, type, uri, name
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ class MPD; end
2
+
3
+ # This class is a glorified Hash used to represent a song.
4
+ #
5
+ # If the field doesn't exist or isn't set, nil will be returned
6
+ class MPD::Song
7
+ def initialize(options)
8
+ @data = {}
9
+ @data.merge! options
10
+ end
11
+
12
+ # Two songs are the same when they are the same file.
13
+ def ==(another)
14
+ self.file == another.file
15
+ end
16
+
17
+ def length
18
+ return "#{(@data.time / 60)}:#{"%02d" % (@data.time % 60)}"
19
+ end
20
+
21
+ def method_missing(m, *a)
22
+ key = m #.to_s
23
+ if key =~ /=$/
24
+ @data[$`] = a[0]
25
+ elsif a.empty?
26
+ @data[key]
27
+ else
28
+ raise NoMethodError, "#{m}"
29
+ end
30
+ end
31
+ end
data/ruby-mpd.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.platform = Gem::Platform::RUBY
5
+ s.name = 'ruby-mpd'
6
+ s.version = '0.1.4'
7
+ s.homepage = 'https://github.com/archSeer/ruby-mpd'
8
+ s.authors = ["Blaž Hrastnik"]
9
+ s.email = ['speed.the.bboy@gmail.com']
10
+ s.summary = "Modern client library for MPD"
11
+ s.description = "A powerful, modern and feature complete library for the Music Player Daemon."
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ end
data/tests/libtests.rb ADDED
@@ -0,0 +1,1145 @@
1
+ #
2
+ # Unit tests for librmpd
3
+ #
4
+ # This uses the included mpdserver.rb test server
5
+
6
+ require '../lib/librmpd'
7
+ require '../lib/mpdserver'
8
+ require 'test/unit'
9
+
10
+ class MPDTester < Test::Unit::TestCase
11
+
12
+ def setup
13
+ begin
14
+ @port = 93932
15
+ @server = MPDTestServer.new @port
16
+ @server.start
17
+ rescue Errno::EADDRINUSE
18
+ @port = 94942
19
+ @server = MPDTestServer.new @port
20
+ @server.start
21
+ end
22
+ @mpd = MPD.new 'localhost', @port
23
+ end
24
+
25
+ def teardown
26
+ @mpd.disconnect
27
+ @server.stop
28
+ end
29
+
30
+ def test_connect
31
+ ret = @mpd.connect
32
+ assert_match /OK MPD [0-9.]*\n/, ret
33
+ end
34
+
35
+ def test_connected?
36
+ # test a good connection
37
+ @mpd.connect
38
+ assert @mpd.connected?
39
+
40
+ # Test a disconnect
41
+ @server.stop
42
+ assert !@mpd.connected?
43
+
44
+ # test a bad connection
45
+ bad = MPD.new 'no-connection', 6600
46
+ assert !bad.connected?
47
+ end
48
+
49
+ def test_disconnect
50
+ # test a good connection
51
+ @mpd.connect
52
+ assert @mpd.connected?
53
+ @mpd.disconnect
54
+ assert !@mpd.connected?
55
+ @mpd.disconnect
56
+ assert !@mpd.connected?
57
+
58
+ # test a bad connection
59
+ bad = MPD.new 'no-connection'
60
+ bad.disconnect
61
+ assert !bad.connected?
62
+ end
63
+
64
+ def test_add
65
+ @mpd.connect
66
+ assert @mpd.connected?
67
+
68
+ assert @mpd.add('Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg')
69
+
70
+ pls = @mpd.playlist
71
+ assert_equal 1, pls.size
72
+ assert_equal 'Shpongle', pls[0].artist
73
+ assert_equal 'Are You Shpongled?', pls[0].album
74
+ assert_equal 'Shpongle Falls', pls[0].title
75
+
76
+ assert_raise(MPD::MPDError) {@mpd.add('Does/Not/Exist')}
77
+
78
+ @mpd.disconnect
79
+ assert_raise(MPD::MPDError) {@mpd.add('Shpongle')}
80
+ end
81
+
82
+ def test_clear
83
+ @mpd.connect
84
+ assert @mpd.connected?
85
+
86
+ assert @mpd.add('Shpongle')
87
+
88
+ pls = @mpd.playlist
89
+ assert_equal 27, pls.size
90
+
91
+ assert @mpd.clear
92
+
93
+ pls = @mpd.playlist
94
+ assert_equal 0, pls.size
95
+
96
+ @mpd.disconnect
97
+ assert_raise(MPD::MPDError) {@mpd.clear}
98
+ end
99
+
100
+ def test_clearerror
101
+ @mpd.connect
102
+ assert @mpd.connected?
103
+
104
+ assert @mpd.clearerror
105
+
106
+ @mpd.disconnect
107
+ assert_raise(MPD::MPDError) {@mpd.clearerror}
108
+ end
109
+
110
+ def test_crossfade
111
+ @mpd.connect
112
+
113
+ @mpd.crossfade = 40
114
+
115
+ assert_equal 40, @mpd.crossfade
116
+ assert_equal '40', @mpd.status['xfade']
117
+
118
+ @mpd.disconnect
119
+ assert_raise(MPD::MPDError) {@mpd.crossfade = 20}
120
+ assert_raise(MPD::MPDError) {@mpd.crossfade}
121
+ end
122
+
123
+ def test_current_song
124
+ @mpd.connect
125
+
126
+ s = @mpd.current_song
127
+ assert_nil s
128
+
129
+ assert @mpd.add('Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg')
130
+
131
+ assert @mpd.play
132
+
133
+ sleep 2
134
+
135
+ assert @mpd.playing?
136
+
137
+ s = @mpd.current_song
138
+
139
+ assert_equal 'Shpongle', s.artist
140
+ assert_equal 'Are You Shpongled?', s.album
141
+ assert_equal 'Shpongle Falls', s.title
142
+ assert_equal '1', s.track
143
+
144
+ @mpd.stop
145
+
146
+ sleep 2
147
+
148
+ assert !@mpd.playing?
149
+
150
+ s = @mpd.current_song
151
+
152
+ assert_equal 'Shpongle', s.artist
153
+ assert_equal 'Are You Shpongled?', s.album
154
+ assert_equal 'Shpongle Falls', s.title
155
+ assert_equal '1', s.track
156
+
157
+ @mpd.disconnect
158
+ assert_raise(MPD::MPDError) {@mpd.current_song}
159
+ end
160
+
161
+ def test_delete
162
+ @mpd.connect
163
+
164
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
165
+
166
+ assert @mpd.delete(3)
167
+
168
+ pls = @mpd.playlist
169
+ assert_equal 7, pls.size
170
+ pls.each do |song|
171
+ assert_not_equal 'No On Ever Dreams', song.title
172
+ end
173
+
174
+ assert_raise(MPD::MPDError) {@mpd.delete(999)}
175
+
176
+ @mpd.disconnect
177
+ assert_raise(MPD::MPDError) {@mpd.delete(3)}
178
+ end
179
+
180
+ def test_deleteid
181
+ @mpd.connect
182
+
183
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
184
+
185
+ assert @mpd.deleteid(10)
186
+
187
+ pls = @mpd.playlist
188
+ assert_equal 7, pls.size
189
+ pls.each do |song|
190
+ assert_not_equal 'No One Ever Dreams', song.title
191
+ end
192
+
193
+ assert_raise(MPD::MPDError) {@mpd.deleteid(999)}
194
+
195
+ @mpd.disconnect
196
+ assert_raise(MPD::MPDError) {@mpd.deleteid(11)}
197
+ end
198
+
199
+ def test_find
200
+ @mpd.connect
201
+
202
+ a = @mpd.find 'album', 'Are You Shpongled?'
203
+ assert_equal 7, a.size
204
+ assert_equal 'Shpongle Falls', a[0].title
205
+ assert_equal 'Monster Hit', a[1].title
206
+ assert_equal 'Vapour Rumours', a[2].title
207
+ assert_equal 'Shpongle Spores', a[3].title
208
+ assert_equal 'Behind Closed Eyelids', a[4].title
209
+ assert_equal 'Divine Moments of Truth', a[5].title
210
+ assert_equal '... and the Day Turned to Night', a[6].title
211
+
212
+ b = @mpd.find 'artist', 'Carbon Based Lifeforms'
213
+ assert_equal 11, b.size
214
+ assert_equal 'Central Plains', b[0].title
215
+ assert_equal 'Tensor', b[1].title
216
+ assert_equal 'MOS 6581 (Album Version)', b[2].title
217
+ assert_equal 'Silent Running', b[3].title
218
+ assert_equal 'Neurotransmitter', b[4].title
219
+ assert_equal 'Hydroponic Garden', b[5].title
220
+ assert_equal 'Exosphere', b[6].title
221
+ assert_equal 'Comsat', b[7].title
222
+ assert_equal 'Epicentre (First Movement)', b[8].title
223
+ assert_equal 'Artificial Island', b[9].title
224
+ assert_equal 'Refraction 1.33', b[10].title
225
+
226
+ c = @mpd.find 'title', 'Silent Running'
227
+ assert_equal 1, c.size
228
+ assert_equal 'Silent Running', c[0].title
229
+
230
+ d = @mpd.find 'artist', 'no artist'
231
+ assert_equal 0, d.size
232
+
233
+ assert_raise(MPD::MPDError) {@mpd.find('error', 'no-such')}
234
+
235
+ @mpd.disconnect
236
+ assert_raise(MPD::MPDError) {@mpd.find('album', 'Are You Shpongled')}
237
+ end
238
+
239
+ def test_kill
240
+ @mpd.connect
241
+
242
+ assert @mpd.kill
243
+
244
+ assert !@mpd.connected?
245
+
246
+ assert_raise(MPD::MPDError) {@mpd.kill}
247
+ end
248
+
249
+ def test_albums
250
+ @mpd.connect
251
+
252
+ albums = @mpd.albums
253
+
254
+ assert_equal 4, albums.size
255
+ assert_equal 'Are You Shpongled?', albums[0]
256
+ assert_equal 'Dancing Galaxy', albums[1]
257
+ assert_equal 'Hydroponic Garden', albums[2]
258
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', albums[3]
259
+
260
+ sh = @mpd.albums 'Shpongle'
261
+
262
+ assert_equal 2, sh.size
263
+ assert_equal 'Are You Shpongled?', sh[0]
264
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', sh[1]
265
+
266
+ @mpd.disconnect
267
+ assert_raise(MPD::MPDError) {@mpd.albums}
268
+ end
269
+
270
+ def test_artists
271
+ @mpd.connect
272
+
273
+ artists = @mpd.artists
274
+
275
+ assert_equal 3, artists.size
276
+ assert_equal 'Astral Projection', artists[0]
277
+ assert_equal 'Carbon Based Lifeforms', artists[1]
278
+ assert_equal 'Shpongle', artists[2]
279
+
280
+ @mpd.disconnect
281
+ assert_raise(MPD::MPDError) {@mpd.artists}
282
+ end
283
+
284
+ def test_list
285
+ @mpd.connect
286
+
287
+ albums = @mpd.list 'album'
288
+
289
+ assert_equal 4, albums.size
290
+ assert_equal 'Are You Shpongled?', albums[0]
291
+ assert_equal 'Dancing Galaxy', albums[1]
292
+ assert_equal 'Hydroponic Garden', albums[2]
293
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', albums[3]
294
+
295
+ artists = @mpd.list 'artist'
296
+
297
+ assert_equal 3, artists.size
298
+ assert_equal 'Astral Projection', artists[0]
299
+ assert_equal 'Carbon Based Lifeforms', artists[1]
300
+ assert_equal 'Shpongle', artists[2]
301
+
302
+ arg = @mpd.list 'album', 'Shpongle'
303
+
304
+ assert_equal 2, arg.size
305
+ assert_equal 'Are You Shpongled?', arg[0]
306
+ assert_equal 'Nothing Lasts... But Nothing Is Lost', arg[1]
307
+
308
+ assert_raise(MPD::MPDError) {@mpd.list('fail')}
309
+ assert_raise(MPD::MPDError) {@mpd.list('fail', 'Shpongle')}
310
+
311
+ @mpd.disconnect
312
+ assert_raise(MPD::MPDError) {@mpd.artists}
313
+ end
314
+
315
+ def test_directories
316
+ @mpd.connect
317
+
318
+ dirs = @mpd.directories
319
+
320
+ assert_equal 7, dirs.size
321
+ assert_equal 'Astral_Projection', dirs[0]
322
+ assert_equal 'Astral_Projection/Dancing_Galaxy', dirs[1]
323
+ assert_equal 'Carbon_Based_Lifeforms', dirs[2]
324
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden', dirs[3]
325
+ assert_equal 'Shpongle', dirs[4]
326
+ assert_equal 'Shpongle/Are_You_Shpongled', dirs[5]
327
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', dirs[6]
328
+
329
+ shpongle = @mpd.directories 'Shpongle'
330
+
331
+ assert_equal 3, shpongle.size
332
+ assert_equal 'Shpongle', shpongle[0]
333
+ assert_equal 'Shpongle/Are_You_Shpongled', shpongle[1]
334
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost', shpongle[2]
335
+
336
+ assert_raise(MPD::MPDError) {@mpd.directories('no-dirs')}
337
+
338
+ @mpd.disconnect
339
+ assert_raise(MPD::MPDError) {@mpd.directories}
340
+ end
341
+
342
+ def test_files
343
+ @mpd.connect
344
+
345
+ files = @mpd.files
346
+
347
+ assert_equal 46, files.size
348
+
349
+ assert_equal 'Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg', files[0]
350
+ assert_equal 'Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg', files[7]
351
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg', files[8]
352
+ assert_equal 'Carbon_Based_Lifeforms/Hydroponic_Garden/11.Refraction_1.33.ogg', files[18]
353
+ assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', files[19]
354
+ assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', files[25]
355
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', files[26]
356
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg', files[45]
357
+
358
+ sh = @mpd.files 'Shpongle'
359
+
360
+ assert_equal 27, sh.size
361
+
362
+ assert_equal 'Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg', sh[0]
363
+ assert_equal 'Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg', sh[6]
364
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg', sh[7]
365
+ assert_equal 'Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg', sh[26]
366
+
367
+ assert_raise(MPD::MPDError) {@mpd.files('no-files')}
368
+
369
+ @mpd.disconnect
370
+ assert_raise(MPD::MPDError) {@mpd.files}
371
+ end
372
+
373
+ def test_playlists
374
+ @mpd.connect
375
+
376
+ pls = @mpd.playlists
377
+
378
+ assert_equal 2, pls.size
379
+
380
+ assert_equal 'Shpongle_-_Are_You_Shpongled', pls[0]
381
+ assert_equal 'Astral_Projection_-_Dancing_Galaxy', pls[1]
382
+
383
+ @mpd.disconnect
384
+ assert_raise(MPD::MPDError) {@mpd.playlists}
385
+ end
386
+
387
+ def test_songs
388
+ @mpd.connect
389
+
390
+ songs = @mpd.songs
391
+
392
+ assert_equal 46, songs.size
393
+
394
+ assert_equal 'Dancing Galaxy', songs[0].title
395
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', songs[7].title
396
+ assert_equal 'Central Plains', songs[8].title
397
+ assert_equal 'Refraction 1.33', songs[18].title
398
+ assert_equal 'Shpongle Falls', songs[19].title
399
+ assert_equal '... and the Day Turned to Night', songs[25].title
400
+ assert_equal 'Botanical Dimensions', songs[26].title
401
+ assert_equal 'Falling Awake', songs[45].title
402
+
403
+ sh = @mpd.songs 'Shpongle'
404
+
405
+ assert_equal 27, sh.size
406
+
407
+ sh.each do |s|
408
+ assert_equal 'Shpongle', s.artist
409
+ end
410
+
411
+ assert_equal 'Shpongle Falls', sh[0].title
412
+ assert_equal '... and the Day Turned to Night', sh[6].title
413
+ assert_equal 'Botanical Dimensions', sh[7].title
414
+ assert_equal 'Falling Awake', sh[26].title
415
+
416
+ assert_raise(MPD::MPDError) {@mpd.songs('no-songs')}
417
+
418
+ @mpd.disconnect
419
+ assert_raise(MPD::MPDError) {@mpd.songs}
420
+ end
421
+
422
+ def test_songs_by_artist
423
+ @mpd.connect
424
+
425
+ songs = @mpd.songs_by_artist 'Shpongle'
426
+
427
+ assert_equal 27, songs.size
428
+
429
+ songs.each do |s|
430
+ assert_equal 'Shpongle', s.artist
431
+ end
432
+
433
+ assert_equal 'Shpongle Falls', songs[0].title
434
+ assert_equal '... and the Day Turned to Night', songs[6].title
435
+ assert_equal 'Botanical Dimensions', songs[7].title
436
+ assert_equal 'Falling Awake', songs[26].title
437
+
438
+ songs = @mpd.songs_by_artist 'no-songs'
439
+ assert_equal 0, songs.size
440
+
441
+ @mpd.disconnect
442
+ assert_raise(MPD::MPDError) {@mpd.songs_by_artist('Shpongle')}
443
+ end
444
+
445
+ def test_load
446
+ @mpd.connect
447
+
448
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
449
+
450
+ pls = @mpd.playlist
451
+
452
+ assert_equal 8, pls.size
453
+
454
+ pls.each do |song|
455
+ assert_equal 'Astral Projection', song.artist
456
+ assert_equal 'Dancing Galaxy', song.album
457
+ end
458
+
459
+ assert_equal 'Dancing Galaxy', pls[0].title
460
+ assert_equal 'Soundform', pls[1].title
461
+ assert_equal 'Flying Into A Star', pls[2].title
462
+ assert_equal 'No One Ever Dreams', pls[3].title
463
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
464
+ assert_equal 'Life On Mars', pls[5].title
465
+ assert_equal 'Liquid Sun', pls[6].title
466
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
467
+
468
+ assert_raise(MPD::MPDError) {@mpd.load('No-PLS')}
469
+
470
+ @mpd.disconnect
471
+ assert_raise(MPD::MPDError) {@mpd.load('Astral_Projection_-_Dancing_Galaxy')}
472
+ end
473
+
474
+ def test_move
475
+ @mpd.connect
476
+
477
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
478
+
479
+ assert @mpd.move( 3, 1 )
480
+
481
+ pls = @mpd.playlist
482
+
483
+ assert_equal 'Dancing Galaxy', pls[0].title
484
+ assert_equal 'No One Ever Dreams', pls[1].title
485
+ assert_equal 'Soundform', pls[2].title
486
+ assert_equal 'Flying Into A Star', pls[3].title
487
+
488
+ assert @mpd.move( 2, 7 )
489
+
490
+ pls = @mpd.playlist
491
+
492
+ assert_equal 'No One Ever Dreams', pls[1].title
493
+ assert_equal 'Flying Into A Star', pls[2].title
494
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[3].title
495
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[6].title
496
+ assert_equal 'Soundform', pls[7].title
497
+
498
+ assert_raise(MPD::MPDError) {@mpd.move(999,1)}
499
+
500
+ @mpd.disconnect
501
+ assert_raise(MPD::MPDError) {@mpd.move(3,1)}
502
+ end
503
+
504
+ def test_moveid
505
+ @mpd.connect
506
+
507
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
508
+
509
+ assert @mpd.moveid( 10, 1 )
510
+
511
+ pls = @mpd.playlist
512
+
513
+ assert_equal 'Dancing Galaxy', pls[0].title
514
+ assert_equal 'No One Ever Dreams', pls[1].title
515
+ assert_equal 'Soundform', pls[2].title
516
+ assert_equal 'Flying Into A Star', pls[3].title
517
+
518
+ assert @mpd.moveid( 8, 7 )
519
+
520
+ pls = @mpd.playlist
521
+
522
+ assert_equal 'No One Ever Dreams', pls[1].title
523
+ assert_equal 'Flying Into A Star', pls[2].title
524
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[3].title
525
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[6].title
526
+ assert_equal 'Soundform', pls[7].title
527
+
528
+ assert_raise(MPD::MPDError) {@mpd.moveid(999,1)}
529
+
530
+ @mpd.disconnect
531
+ assert_raise(MPD::MPDError) {@mpd.moveid(10,1)}
532
+
533
+ end
534
+
535
+ def test_next
536
+ @mpd.connect
537
+
538
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
539
+
540
+ @mpd.play 3
541
+
542
+ pos = @mpd.status['song'].to_i
543
+
544
+ assert @mpd.next
545
+
546
+ assert_equal pos + 1, @mpd.status['song'].to_i
547
+
548
+ @mpd.disconnect
549
+ assert_raise(MPD::MPDError) {@mpd.next}
550
+ end
551
+
552
+ def test_pause
553
+ @mpd.connect
554
+ assert @mpd.connected?
555
+
556
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
557
+
558
+ assert @mpd.play
559
+ assert @mpd.playing?
560
+
561
+ @mpd.pause = true
562
+ assert @mpd.paused?
563
+
564
+ @mpd.pause = false
565
+ assert !@mpd.paused?
566
+
567
+ assert @mpd.stop
568
+ assert @mpd.stopped?
569
+
570
+ @mpd.pause = true
571
+ assert @mpd.stopped?
572
+
573
+ assert !@mpd.paused?
574
+
575
+ @mpd.disconnect
576
+ assert_raise(MPD::MPDError) {@mpd.pause = true}
577
+ assert_raise(MPD::MPDError) {@mpd.paused?}
578
+ end
579
+
580
+ def test_password
581
+ @mpd.connect
582
+
583
+ assert_raise(MPD::MPDError) {@mpd.password('wrong')}
584
+
585
+ assert @mpd.password('test')
586
+
587
+ @mpd.disconnect
588
+ assert_raise(MPD::MPDError) {@mpd.password('test')}
589
+ end
590
+
591
+ def test_ping
592
+ @mpd.connect
593
+
594
+ assert @mpd.ping
595
+
596
+ @mpd.disconnect
597
+ assert_raise(MPD::MPDError) {@mpd.ping}
598
+ end
599
+
600
+ def test_play
601
+ @mpd.connect
602
+ assert @mpd.connected?
603
+
604
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
605
+
606
+ assert @mpd.play
607
+
608
+ sleep 2
609
+
610
+ assert @mpd.playing?
611
+
612
+ song = @mpd.current_song
613
+
614
+ assert_equal 'Dancing Galaxy', song.title
615
+
616
+ assert @mpd.play(2)
617
+
618
+ sleep 2
619
+
620
+ assert @mpd.playing?
621
+
622
+ song = @mpd.current_song
623
+
624
+ assert_equal 'Flying Into A Star', song.title
625
+
626
+ @mpd.disconnect
627
+ assert_raise(MPD::MPDError) {@mpd.play}
628
+ assert_raise(MPD::MPDError) {@mpd.playing?}
629
+ end
630
+
631
+ def test_playid
632
+ @mpd.connect
633
+ assert @mpd.connected?
634
+
635
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
636
+
637
+ assert @mpd.playid
638
+
639
+ sleep 2
640
+
641
+ assert @mpd.playing?
642
+
643
+ song = @mpd.current_song
644
+
645
+ assert_equal 'Dancing Galaxy', song.title
646
+
647
+ assert @mpd.playid(9)
648
+
649
+ sleep 2
650
+
651
+ assert @mpd.playing?
652
+
653
+ song = @mpd.current_song
654
+
655
+ assert_equal 'Flying Into A Star', song.title
656
+
657
+ @mpd.disconnect
658
+ assert_raise(MPD::MPDError) {@mpd.playid}
659
+ assert_raise(MPD::MPDError) {@mpd.playing?}
660
+
661
+ end
662
+
663
+ def test_playlist_version
664
+ @mpd.connect
665
+
666
+ ver = @mpd.playlist_version
667
+
668
+ assert_equal 1, ver
669
+
670
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
671
+
672
+ ver = @mpd.playlist_version
673
+
674
+ assert_equal 9, ver
675
+
676
+ @mpd.disconnect
677
+ assert_raise(MPD::MPDError) {@mpd.playlist_version}
678
+ end
679
+
680
+ def test_playlist
681
+ @mpd.connect
682
+
683
+ pls = @mpd.playlist
684
+
685
+ assert_equal 0, pls.size
686
+
687
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
688
+
689
+ pls = @mpd.playlist
690
+
691
+ assert_equal 8, pls.size
692
+
693
+ assert_equal 'Dancing Galaxy', pls[0].title
694
+ assert_equal 'Soundform', pls[1].title
695
+ assert_equal 'Flying Into A Star', pls[2].title
696
+ assert_equal 'No One Ever Dreams', pls[3].title
697
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
698
+ assert_equal 'Life On Mars', pls[5].title
699
+ assert_equal 'Liquid Sun', pls[6].title
700
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
701
+
702
+ @mpd.disconnect
703
+ assert_raise(MPD::MPDError) {@mpd.playlist}
704
+ end
705
+
706
+ def test_song_at_pos
707
+ @mpd.connect
708
+
709
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
710
+
711
+ assert_equal 'Dancing Galaxy', @mpd.song_at_pos(0).title
712
+ assert_equal 'Soundform', @mpd.song_at_pos(1).title
713
+ assert_equal 'Flying Into A Star', @mpd.song_at_pos(2).title
714
+ assert_equal 'No One Ever Dreams', @mpd.song_at_pos(3).title
715
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', @mpd.song_at_pos(4).title
716
+ assert_equal 'Life On Mars', @mpd.song_at_pos(5).title
717
+ assert_equal 'Liquid Sun', @mpd.song_at_pos(6).title
718
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', @mpd.song_at_pos(7).title
719
+
720
+ assert_raise(MPD::MPDError) {@mpd.song_at_pos(999)}
721
+
722
+ @mpd.disconnect
723
+ assert_raise(MPD::MPDError) {@mpd.song_at_pos(0)}
724
+ end
725
+
726
+ def test_song_with_id
727
+ @mpd.connect
728
+
729
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
730
+
731
+ assert_equal 'Dancing Galaxy', @mpd.song_with_id(7).title
732
+ assert_equal 'Soundform', @mpd.song_with_id(8).title
733
+ assert_equal 'Flying Into A Star', @mpd.song_with_id(9).title
734
+ assert_equal 'No One Ever Dreams', @mpd.song_with_id(10).title
735
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', @mpd.song_with_id(11).title
736
+ assert_equal 'Life On Mars', @mpd.song_with_id(12).title
737
+ assert_equal 'Liquid Sun', @mpd.song_with_id(13).title
738
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', @mpd.song_with_id(14).title
739
+
740
+ assert_raise(MPD::MPDError) {@mpd.song_with_id(999)}
741
+
742
+ @mpd.disconnect
743
+ assert_raise(MPD::MPDError) {@mpd.song_with_id(10)}
744
+ end
745
+
746
+ def test_playlist_changes
747
+ @mpd.connect
748
+
749
+ assert @mpd.add('Astral_Projection')
750
+
751
+ changes = @mpd.playlist_changes 8
752
+
753
+ assert_equal 1, changes.size
754
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', changes[0].title
755
+
756
+ changes = @mpd.playlist_changes 1
757
+
758
+ assert_equal 8, changes.size
759
+ assert_equal 'Dancing Galaxy', changes[0].title
760
+ assert_equal 'Soundform', changes[1].title
761
+ assert_equal 'Flying Into A Star', changes[2].title
762
+ assert_equal 'No One Ever Dreams', changes[3].title
763
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', changes[4].title
764
+ assert_equal 'Life On Mars', changes[5].title
765
+ assert_equal 'Liquid Sun', changes[6].title
766
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', changes[7].title
767
+
768
+ changes = @mpd.playlist_changes 999
769
+
770
+ assert_equal 8, changes.size
771
+
772
+ @mpd.disconnect
773
+ assert_raise(MPD::MPDError) {@mpd.playlist_changes(9)}
774
+ end
775
+
776
+ def test_previous
777
+ @mpd.connect
778
+
779
+ @mpd.load 'Astral_Projection_-_Dancing_Galaxy'
780
+
781
+ @mpd.play 3
782
+
783
+ sleep 2
784
+
785
+ assert @mpd.playing?
786
+
787
+ pos = @mpd.status['song'].to_i
788
+
789
+ assert @mpd.previous
790
+
791
+ assert_equal pos - 1, @mpd.status['song'].to_i
792
+
793
+ @mpd.disconnect
794
+ assert_raise(MPD::MPDError) {@mpd.previous}
795
+ end
796
+
797
+ def test_random
798
+ @mpd.connect
799
+
800
+ @mpd.random = true
801
+ assert @mpd.random?
802
+
803
+ @mpd.random = false
804
+ assert !@mpd.random?
805
+
806
+ @mpd.disconnect
807
+ assert_raise(MPD::MPDError) {@mpd.random = false}
808
+ assert_raise(MPD::MPDError) {@mpd.random?}
809
+ end
810
+
811
+ def test_repeat
812
+ @mpd.connect
813
+
814
+ @mpd.repeat = true
815
+ assert @mpd.repeat?
816
+
817
+ @mpd.repeat = false
818
+ assert !@mpd.repeat?
819
+
820
+ @mpd.disconnect
821
+ assert_raise(MPD::MPDError) {@mpd.repeat = false}
822
+ assert_raise(MPD::MPDError) {@mpd.repeat?}
823
+ end
824
+
825
+ def test_rm
826
+ @mpd.connect
827
+
828
+ assert @mpd.rm('Astral_Projection_-_Dancing_Galaxy')
829
+
830
+ pls = @mpd.playlists
831
+
832
+ assert 1, pls.size
833
+
834
+ assert_equal 'Shpongle_-_Are_You_Shpongled', pls[0]
835
+
836
+ assert_raise(MPD::MPDError) {@mpd.rm('Not-Exist')}
837
+
838
+ @mpd.disconnect
839
+ assert_raise(MPD::MPDError) {@mpd.rm('Astral_Projection_-_Dancing_Galaxy')}
840
+ end
841
+
842
+ def test_save
843
+ @mpd.connect
844
+
845
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
846
+ assert @mpd.load('Shpongle_-_Are_You_Shpongled')
847
+
848
+ assert @mpd.save('UnitTests')
849
+
850
+ assert @mpd.clear
851
+
852
+ assert @mpd.load('UnitTests')
853
+
854
+ pls = @mpd.playlist
855
+
856
+ assert_equal 15, pls.size
857
+
858
+ assert_equal 'Dancing Galaxy', pls[0].title
859
+ assert_equal 'Soundform', pls[1].title
860
+ assert_equal 'Flying Into A Star', pls[2].title
861
+ assert_equal 'No One Ever Dreams', pls[3].title
862
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
863
+ assert_equal 'Life On Mars', pls[5].title
864
+ assert_equal 'Liquid Sun', pls[6].title
865
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
866
+ assert_equal 'Shpongle Falls', pls[8].title
867
+ assert_equal 'Monster Hit', pls[9].title
868
+ assert_equal 'Vapour Rumours', pls[10].title
869
+ assert_equal 'Shpongle Spores', pls[11].title
870
+ assert_equal 'Behind Closed Eyelids', pls[12].title
871
+ assert_equal 'Divine Moments of Truth', pls[13].title
872
+ assert_equal '... and the Day Turned to Night', pls[14].title
873
+
874
+ @mpd.disconnect
875
+ assert_raise(MPD::MPDError) {@mpd.save('test')}
876
+ end
877
+
878
+ def test_search
879
+ @mpd.connect
880
+
881
+ a = @mpd.search 'album', 'ydroponic gar'
882
+
883
+ assert_equal 11, a.size
884
+ a.each do |song|
885
+ assert_equal 'Carbon Based Lifeforms', song.artist
886
+ assert_equal 'Hydroponic Garden', song.album
887
+ end
888
+
889
+ b = @mpd.search 'artist', 'hpon'
890
+
891
+ assert_equal 27, b.size
892
+ b.each do |song|
893
+ assert_equal 'Shpongle', song.artist
894
+ end
895
+
896
+ c = @mpd.search 'title', 'falls'
897
+ assert_equal 1, c.size
898
+ assert_equal 'Shpongle', c[0].artist
899
+ assert_equal 'Shpongle Falls', c[0].title
900
+ assert_equal 'Are You Shpongled?', c[0].album
901
+
902
+ d = @mpd.search 'filename', 'disco_valley'
903
+ assert_equal 1, d.size
904
+ assert_equal 'Astral Projection', d[0].artist
905
+ assert_equal 'Dancing Galaxy', d[0].album
906
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', d[0].title
907
+
908
+ z = @mpd.search 'title', 'no-title'
909
+ assert_equal 0, z.size
910
+
911
+ assert_raise(MPD::MPDError) {@mpd.search('error', 'nosuch')}
912
+
913
+ @mpd.disconnect
914
+ assert_raise(MPD::MPDError) {@mpd.search('artist','searching')}
915
+ end
916
+
917
+ def test_seek
918
+ @mpd.connect
919
+
920
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
921
+
922
+ assert @mpd.play
923
+
924
+ sleep 2
925
+
926
+ assert @mpd.pause = true
927
+
928
+ sleep 2
929
+
930
+ assert @mpd.seek(2, 200)
931
+
932
+ sleep 2
933
+
934
+ song = @mpd.current_song
935
+
936
+ assert_equal 'Flying Into A Star', song.title
937
+
938
+ status = @mpd.status
939
+
940
+ assert_equal '200:585', status['time']
941
+
942
+ @mpd.disconnect
943
+ assert_raise(MPD::MPDError) {@mpd.seek(1, 100)}
944
+ end
945
+
946
+ def test_seekid
947
+ @mpd.connect
948
+
949
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
950
+
951
+ assert @mpd.play
952
+
953
+ sleep 2
954
+
955
+ assert @mpd.pause = true
956
+
957
+ sleep 2
958
+
959
+ assert @mpd.seekid(9, 200)
960
+
961
+ sleep 2
962
+
963
+ song = @mpd.current_song
964
+
965
+ assert_equal 'Flying Into A Star', song.title
966
+
967
+ status = @mpd.status
968
+
969
+ assert_equal '200:585', status['time']
970
+
971
+ @mpd.disconnect
972
+ assert_raise(MPD::MPDError) {@mpd.seekid(1, 100)}
973
+ end
974
+
975
+ def test_volume
976
+ @mpd.connect
977
+
978
+ vol = @mpd.volume
979
+
980
+ @mpd.volume = 30
981
+ assert_equal 30, @mpd.volume
982
+
983
+ @mpd.volume = vol
984
+ assert_equal vol, @mpd.volume
985
+
986
+ @mpd.disconnect
987
+ assert_raise(MPD::MPDError) {@mpd.volume = 10}
988
+ assert_raise(MPD::MPDError) {@mpd.volume}
989
+ end
990
+
991
+ def test_shuffle
992
+ @mpd.connect
993
+
994
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
995
+
996
+ assert @mpd.shuffle
997
+
998
+ pls = @mpd.playlist
999
+
1000
+ assert_equal 8, pls.size
1001
+ assert_not_equal 'Dancing Galaxy', pls[0].title
1002
+
1003
+ @mpd.disconnect
1004
+ assert_raise(MPD::MPDError) {@mpd.shuffle}
1005
+ end
1006
+
1007
+ def test_stats
1008
+ @mpd.connect
1009
+
1010
+ stats = @mpd.stats
1011
+
1012
+ assert_equal '3', stats['artists']
1013
+ assert_equal '4', stats['albums']
1014
+ assert_equal '46', stats['songs']
1015
+ assert_equal '500', stats['uptime']
1016
+
1017
+ @mpd.disconnect
1018
+ assert_raise(MPD::MPDError) {@mpd.stats}
1019
+ end
1020
+
1021
+ def test_status
1022
+ @mpd.connect
1023
+
1024
+ status = @mpd.status
1025
+
1026
+ assert_equal 'stop', status['state']
1027
+ assert_equal '0', status['repeat']
1028
+ assert_equal '0', status['random']
1029
+
1030
+ @mpd.disconnect
1031
+ assert_raise(MPD::MPDError) {@mpd.status}
1032
+ end
1033
+
1034
+ def test_stop
1035
+ @mpd.connect
1036
+ assert @mpd.connected?
1037
+
1038
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
1039
+
1040
+ assert @mpd.play
1041
+ assert @mpd.playing?
1042
+
1043
+ assert @mpd.stop
1044
+ assert @mpd.stopped?
1045
+
1046
+ assert !@mpd.playing?
1047
+
1048
+ @mpd.disconnect
1049
+ assert_raise(MPD::MPDError) {@mpd.stop}
1050
+ assert_raise(MPD::MPDError) {@mpd.stopped?}
1051
+ end
1052
+
1053
+ def test_swap
1054
+ @mpd.connect
1055
+
1056
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
1057
+
1058
+ assert @mpd.swap(2,5)
1059
+
1060
+ pls = @mpd.playlist
1061
+
1062
+ assert_equal 'Dancing Galaxy', pls[0].title
1063
+ assert_equal 'Soundform', pls[1].title
1064
+ assert_equal 'Flying Into A Star', pls[5].title
1065
+ assert_equal 'No One Ever Dreams', pls[3].title
1066
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1067
+ assert_equal 'Life On Mars', pls[2].title
1068
+ assert_equal 'Liquid Sun', pls[6].title
1069
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
1070
+
1071
+ assert @mpd.swap(7,1)
1072
+
1073
+ pls = @mpd.playlist
1074
+
1075
+ assert_equal 'Dancing Galaxy', pls[0].title
1076
+ assert_equal 'Soundform', pls[7].title
1077
+ assert_equal 'Flying Into A Star', pls[5].title
1078
+ assert_equal 'No One Ever Dreams', pls[3].title
1079
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1080
+ assert_equal 'Life On Mars', pls[2].title
1081
+ assert_equal 'Liquid Sun', pls[6].title
1082
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[1].title
1083
+
1084
+ assert_raise(MPD::MPDError) {@mpd.swap(999,1)}
1085
+
1086
+ @mpd.disconnect
1087
+ assert_raise(MPD::MPDError) {@mpd.swap(2, 5)}
1088
+ end
1089
+
1090
+ def test_swapid
1091
+ @mpd.connect
1092
+
1093
+ assert @mpd.load('Astral_Projection_-_Dancing_Galaxy')
1094
+
1095
+ assert @mpd.swapid(9,12)
1096
+
1097
+ pls = @mpd.playlist
1098
+
1099
+ assert_equal 'Dancing Galaxy', pls[0].title
1100
+ assert_equal 'Soundform', pls[1].title
1101
+ assert_equal 'Flying Into A Star', pls[5].title
1102
+ assert_equal 'No One Ever Dreams', pls[3].title
1103
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1104
+ assert_equal 'Life On Mars', pls[2].title
1105
+ assert_equal 'Liquid Sun', pls[6].title
1106
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[7].title
1107
+
1108
+ assert @mpd.swapid(14,8)
1109
+
1110
+ pls = @mpd.playlist
1111
+
1112
+ assert_equal 'Dancing Galaxy', pls[0].title
1113
+ assert_equal 'Soundform', pls[7].title
1114
+ assert_equal 'Flying Into A Star', pls[5].title
1115
+ assert_equal 'No One Ever Dreams', pls[3].title
1116
+ assert_equal 'Cosmic Ascension (ft. DJ Jorg)', pls[4].title
1117
+ assert_equal 'Life On Mars', pls[2].title
1118
+ assert_equal 'Liquid Sun', pls[6].title
1119
+ assert_equal 'Ambient Galaxy (Disco Valley Mix)', pls[1].title
1120
+
1121
+ assert_raise(MPD::MPDError) {@mpd.swapid(999,8)}
1122
+
1123
+ @mpd.disconnect
1124
+ assert_raise(MPD::MPDError) {@mpd.swapid(9, 12)}
1125
+ end
1126
+
1127
+ def test_update
1128
+ @mpd.connect
1129
+
1130
+ ret = @mpd.update
1131
+
1132
+ assert_equal 1, ret
1133
+
1134
+ status = @mpd.status
1135
+
1136
+ assert_equal '1', status['updating_db']
1137
+
1138
+ status = @mpd.status
1139
+
1140
+ assert_nil status['updating_db']
1141
+
1142
+ @mpd.disconnect
1143
+ assert_raise(MPD::MPDError) {@mpd.update}
1144
+ end
1145
+ end