ruby-mpd 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/AUTHORS +1 -0
- data/COPYING +340 -0
- data/DOC.rdoc +78 -0
- data/README.rdoc +174 -0
- data/data/database.yaml +347 -0
- data/examples/rmpc.rb +67 -0
- data/examples/tailmpc.rb +115 -0
- data/lib/mpdserver.rb +1206 -0
- data/lib/ruby-mpd.rb +310 -0
- data/lib/ruby-mpd/parser.rb +151 -0
- data/lib/ruby-mpd/playlist.rb +77 -0
- data/lib/ruby-mpd/plugins/channels.rb +58 -0
- data/lib/ruby-mpd/plugins/controls.rb +72 -0
- data/lib/ruby-mpd/plugins/database.rb +79 -0
- data/lib/ruby-mpd/plugins/information.rb +146 -0
- data/lib/ruby-mpd/plugins/outputs.rb +26 -0
- data/lib/ruby-mpd/plugins/playback_options.rb +88 -0
- data/lib/ruby-mpd/plugins/playlists.rb +17 -0
- data/lib/ruby-mpd/plugins/queue.rb +125 -0
- data/lib/ruby-mpd/plugins/reflection.rb +46 -0
- data/lib/ruby-mpd/plugins/stickers.rb +52 -0
- data/lib/ruby-mpd/song.rb +31 -0
- data/ruby-mpd.gemspec +17 -0
- data/tests/libtests.rb +1145 -0
- data/tests/servertests.rb +3405 -0
- metadata +73 -0
data/data/database.yaml
ADDED
@@ -0,0 +1,347 @@
|
|
1
|
+
- &songs
|
2
|
+
- &song1
|
3
|
+
file: "Shpongle/Are_You_Shpongled/1.Shpongle_Falls.ogg"
|
4
|
+
time: 514
|
5
|
+
artist: "Shpongle"
|
6
|
+
album: "Are You Shpongled?"
|
7
|
+
title: "Shpongle Falls"
|
8
|
+
track: 1
|
9
|
+
- &song2
|
10
|
+
file: "Shpongle/Are_You_Shpongled/2.Monster_Hit.ogg"
|
11
|
+
time: 537
|
12
|
+
artist: "Shpongle"
|
13
|
+
album: "Are You Shpongled?"
|
14
|
+
title: "Monster Hit"
|
15
|
+
track: 2
|
16
|
+
- &song3
|
17
|
+
file: "Shpongle/Are_You_Shpongled/3.Vapour_Rumours.ogg"
|
18
|
+
time: 626
|
19
|
+
artist: "Shpongle"
|
20
|
+
album: "Are You Shpongled?"
|
21
|
+
title: "Vapour Rumours"
|
22
|
+
track: 3
|
23
|
+
- &song4
|
24
|
+
file: "Shpongle/Are_You_Shpongled/4.Shpongle_Spores.ogg"
|
25
|
+
time: 436
|
26
|
+
artist: "Shpongle"
|
27
|
+
album: "Are You Shpongled?"
|
28
|
+
title: "Shpongle Spores"
|
29
|
+
track: 4
|
30
|
+
- &song5
|
31
|
+
file: "Shpongle/Are_You_Shpongled/5.Behind_Closed_Eyelids.ogg"
|
32
|
+
time: 749
|
33
|
+
artist: "Shpongle"
|
34
|
+
album: "Are You Shpongled?"
|
35
|
+
title: "Behind Closed Eyelids"
|
36
|
+
track: 5
|
37
|
+
- &song6
|
38
|
+
file: "Shpongle/Are_You_Shpongled/6.Divine_Moments_of_Truth.ogg"
|
39
|
+
time: 620
|
40
|
+
artist: "Shpongle"
|
41
|
+
album: "Are You Shpongled?"
|
42
|
+
title: "Divine Moments of Truth"
|
43
|
+
track: 6
|
44
|
+
- &song7
|
45
|
+
file: "Shpongle/Are_You_Shpongled/7...._and_the_Day_Turned_to_Night.ogg"
|
46
|
+
time: 1198
|
47
|
+
artist: "Shpongle"
|
48
|
+
album: "Are You Shpongled?"
|
49
|
+
title: "... and the Day Turned to Night"
|
50
|
+
track: 7
|
51
|
+
- &song8
|
52
|
+
file: "Astral_Projection/Dancing_Galaxy/1.Dancing_Galaxy.ogg"
|
53
|
+
time: 558
|
54
|
+
artist: "Astral Projection"
|
55
|
+
album: "Dancing Galaxy"
|
56
|
+
title: "Dancing Galaxy"
|
57
|
+
track: 1
|
58
|
+
- &song9
|
59
|
+
file: "Astral_Projection/Dancing_Galaxy/2.Soundform.ogg"
|
60
|
+
time: 492
|
61
|
+
artist: "Astral Projection"
|
62
|
+
album: "Dancing Galaxy"
|
63
|
+
title: "Soundform"
|
64
|
+
track: 2
|
65
|
+
- &song10
|
66
|
+
file: "Astral_Projection/Dancing_Galaxy/3.Flying_Into_A_Star.ogg"
|
67
|
+
time: 585
|
68
|
+
artist: "Astral Projection"
|
69
|
+
album: "Dancing Galaxy"
|
70
|
+
title: "Flying Into A Star"
|
71
|
+
track: 3
|
72
|
+
- &song11
|
73
|
+
file: "Astral_Projection/Dancing_Galaxy/4.No_One_Ever_Dreams.ogg"
|
74
|
+
time: 505
|
75
|
+
artist: "Astral Projection"
|
76
|
+
album: "Dancing Galaxy"
|
77
|
+
title: "No One Ever Dreams"
|
78
|
+
track: 4
|
79
|
+
- &song12
|
80
|
+
file: "Astral_Projection/Dancing_Galaxy/5.Cosmic_Ascension_(ft._DJ_Jorg).ogg"
|
81
|
+
time: 619
|
82
|
+
artist: "Astral Projection"
|
83
|
+
album: "Dancing Galaxy"
|
84
|
+
title: "Cosmic Ascension (ft. DJ Jorg)"
|
85
|
+
track: 5
|
86
|
+
- &song13
|
87
|
+
file: "Astral_Projection/Dancing_Galaxy/6.Life_On_Mars.ogg"
|
88
|
+
time: 549
|
89
|
+
artist: "Astral Projection"
|
90
|
+
album: "Dancing Galaxy"
|
91
|
+
title: "Life On Mars"
|
92
|
+
track: 6
|
93
|
+
- &song14
|
94
|
+
file: "Astral_Projection/Dancing_Galaxy/7.Liquid_Sun.ogg"
|
95
|
+
time: 660
|
96
|
+
artist: "Astral Projection"
|
97
|
+
album: "Dancing Galaxy"
|
98
|
+
title: "Liquid Sun"
|
99
|
+
track: 7
|
100
|
+
- &song15
|
101
|
+
file: "Astral_Projection/Dancing_Galaxy/8.Ambient_Galaxy_(Disco_Valley_Mix).ogg"
|
102
|
+
time: 825
|
103
|
+
artist: "Astral Projection"
|
104
|
+
album: "Dancing Galaxy"
|
105
|
+
title: "Ambient Galaxy (Disco Valley Mix)"
|
106
|
+
track: 8
|
107
|
+
- &song16
|
108
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/01.Central_Plains.ogg"
|
109
|
+
time: 488
|
110
|
+
artist: "Carbon Based Lifeforms"
|
111
|
+
album: "Hydroponic Garden"
|
112
|
+
title: "Central Plains"
|
113
|
+
track: 1
|
114
|
+
- &song17
|
115
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/02.Tensor.ogg"
|
116
|
+
time: 344
|
117
|
+
artist: "Carbon Based Lifeforms"
|
118
|
+
album: "Hydroponic Garden"
|
119
|
+
title: "Tensor"
|
120
|
+
track: 2
|
121
|
+
- &song18
|
122
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/03.MOS_6581_(Album_Version).ogg"
|
123
|
+
time: 431
|
124
|
+
artist: "Carbon Based Lifeforms"
|
125
|
+
album: "Hydroponic Garden"
|
126
|
+
title: "MOS 6581 (Album Version)"
|
127
|
+
track: 3
|
128
|
+
- &song19
|
129
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/04.Silent_Running.ogg"
|
130
|
+
time: 425
|
131
|
+
artist: "Carbon Based Lifeforms"
|
132
|
+
album: "Hydroponic Garden"
|
133
|
+
title: "Silent Running"
|
134
|
+
track: 4
|
135
|
+
- &song20
|
136
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/05.Neurotransmitter.ogg"
|
137
|
+
time: 448
|
138
|
+
artist: "Carbon Based Lifeforms"
|
139
|
+
album: "Hydroponic Garden"
|
140
|
+
title: "Neurotransmitter"
|
141
|
+
track: 5
|
142
|
+
- &song21
|
143
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/06.Hydroponic_Garden.ogg"
|
144
|
+
time: 553
|
145
|
+
artist: "Carbon Based Lifeforms"
|
146
|
+
album: "Hydroponic Garden"
|
147
|
+
title: "Hydroponic Garden"
|
148
|
+
track: 6
|
149
|
+
- &song22
|
150
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/07.Exosphere.ogg"
|
151
|
+
time: 306
|
152
|
+
artist: "Carbon Based Lifeforms"
|
153
|
+
album: "Hydroponic Garden"
|
154
|
+
title: "Exosphere"
|
155
|
+
track: 7
|
156
|
+
- &song23
|
157
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/08.Comsat.ogg"
|
158
|
+
time: 429
|
159
|
+
artist: "Carbon Based Lifeforms"
|
160
|
+
album: "Hydroponic Garden"
|
161
|
+
title: "Comsat"
|
162
|
+
track: 8
|
163
|
+
- &song24
|
164
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/09.Epicentre_(First_Movement).ogg"
|
165
|
+
time: 358
|
166
|
+
artist: "Carbon Based Lifeforms"
|
167
|
+
album: "Hydroponic Garden"
|
168
|
+
title: "Epicentre (First Movement)"
|
169
|
+
track: 9
|
170
|
+
- &song25
|
171
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/10.Artificial_Island.ogg"
|
172
|
+
time: 312
|
173
|
+
artist: "Carbon Based Lifeforms"
|
174
|
+
album: "Hydroponic Garden"
|
175
|
+
title: "Artificial Island"
|
176
|
+
track: 10
|
177
|
+
- &song26
|
178
|
+
file: "Carbon_Based_Lifeforms/Hydroponic_Garden/11.Refraction_1.33.ogg"
|
179
|
+
time: 500
|
180
|
+
artist: "Carbon Based Lifeforms"
|
181
|
+
album: "Hydroponic Garden"
|
182
|
+
title: "Refraction 1.33"
|
183
|
+
track: 11
|
184
|
+
- &song27
|
185
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/01.Botanical_Dimensions.ogg"
|
186
|
+
time: 278
|
187
|
+
artist: "Shpongle"
|
188
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
189
|
+
title: "Botanical Dimensions"
|
190
|
+
track: 1
|
191
|
+
- &song28
|
192
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/02.Outer_Shpongolia.ogg"
|
193
|
+
time: 153
|
194
|
+
artist: "Shpongle"
|
195
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
196
|
+
title: "Outer Shpongolia"
|
197
|
+
track: 2
|
198
|
+
- &song29
|
199
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/03.Levitation_Nation.ogg"
|
200
|
+
time: 220
|
201
|
+
artist: "Shpongle"
|
202
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
203
|
+
title: "Levitation Nation"
|
204
|
+
track: 3
|
205
|
+
- &song30
|
206
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/04.Periscopes_of_Consciousness.ogg"
|
207
|
+
time: 114
|
208
|
+
artist: "Shpongle"
|
209
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
210
|
+
title: "Periscopes of Consciousness"
|
211
|
+
track: 4
|
212
|
+
- &song31
|
213
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/05.Schmaltz_Herring.ogg"
|
214
|
+
time: 141
|
215
|
+
artist: "Shpongle"
|
216
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
217
|
+
title: "Schmaltz Herring"
|
218
|
+
track: 5
|
219
|
+
- &song32
|
220
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/06.Nothing_Lasts....ogg"
|
221
|
+
time: 269
|
222
|
+
artist: "Shpongle"
|
223
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
224
|
+
title: "Nothing Lasts..."
|
225
|
+
track: 6
|
226
|
+
- &song33
|
227
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/07.Shnitzled_in_the_Negev.ogg"
|
228
|
+
time: 258
|
229
|
+
artist: "Shpongle"
|
230
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
231
|
+
title: "Shnitzled in the Negev"
|
232
|
+
track: 7
|
233
|
+
- &song34
|
234
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/08....But_Nothing_Is_Lost.ogg"
|
235
|
+
time: 279
|
236
|
+
artist: "Shpongle"
|
237
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
238
|
+
title: "...But Nothing Is Lost"
|
239
|
+
track: 8
|
240
|
+
- &song35
|
241
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/09.When_Shall_I_Be_Free.ogg"
|
242
|
+
time: 277
|
243
|
+
artist: "Shpongle"
|
244
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
245
|
+
title: "When Shall I Be Free"
|
246
|
+
track: 9
|
247
|
+
- &song36
|
248
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/10.The_Stamen_of_the_Shamen.ogg"
|
249
|
+
time: 251
|
250
|
+
artist: "Shpongle"
|
251
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
252
|
+
title: "The Stamen of the Shamen"
|
253
|
+
track: 10
|
254
|
+
- &song37
|
255
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/11.Circuits_of_the_Imagination.ogg"
|
256
|
+
time: 192
|
257
|
+
artist: "Shpongle"
|
258
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
259
|
+
title: "Circuits of the Imagination"
|
260
|
+
track: 11
|
261
|
+
- &song38
|
262
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/12.Linguistic_Mystic.ogg"
|
263
|
+
time: 96
|
264
|
+
artist: "Shpongle"
|
265
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
266
|
+
title: "Linguistic Mystic"
|
267
|
+
track: 12
|
268
|
+
- &song39
|
269
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/13.Mentalism.ogg"
|
270
|
+
time: 174
|
271
|
+
artist: "Shpongle"
|
272
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
273
|
+
title: "Mentalism"
|
274
|
+
track: 13
|
275
|
+
- &song40
|
276
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/14.Invocation.ogg"
|
277
|
+
time: 160
|
278
|
+
artist: "Shpongle"
|
279
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
280
|
+
title: "Invocation"
|
281
|
+
track: 14
|
282
|
+
- &song41
|
283
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/15.Molecular_Superstructure.ogg"
|
284
|
+
time: 287
|
285
|
+
artist: "Shpongle"
|
286
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
287
|
+
title: "Molecular Superstructure"
|
288
|
+
track: 15
|
289
|
+
- &song42
|
290
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/16.Turn_Up_the_Silence.ogg"
|
291
|
+
time: 202
|
292
|
+
artist: "Shpongle"
|
293
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
294
|
+
title: "Turn Up the Silence"
|
295
|
+
track: 16
|
296
|
+
- &song43
|
297
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/17.Exhalation.ogg"
|
298
|
+
time: 136
|
299
|
+
artist: "Shpongle"
|
300
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
301
|
+
title: "Exhalation"
|
302
|
+
track: 17
|
303
|
+
- &song44
|
304
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/18.Connoisseur_of_Hallucinations.ogg"
|
305
|
+
time: 212
|
306
|
+
artist: "Shpongle"
|
307
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
308
|
+
title: "Connoisseur of Hallucinations"
|
309
|
+
track: 18
|
310
|
+
- &song45
|
311
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/19.The_Nebbish_Route.ogg"
|
312
|
+
time: 215
|
313
|
+
artist: "Shpongle"
|
314
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
315
|
+
title: "The Nebbish Route"
|
316
|
+
track: 19
|
317
|
+
- &song46
|
318
|
+
file: "Shpongle/Nothing_Lasts..._But_Nothing_Is_Lost/20.Falling_Awake.ogg"
|
319
|
+
time: 110
|
320
|
+
artist: "Shpongle"
|
321
|
+
album: "Nothing Lasts... But Nothing Is Lost"
|
322
|
+
title: "Falling Awake"
|
323
|
+
track: 20
|
324
|
+
|
325
|
+
- &playlists
|
326
|
+
- &playlist1
|
327
|
+
file: "Shpongle_-_Are_You_Shpongled.m3u"
|
328
|
+
songs:
|
329
|
+
- *song1
|
330
|
+
- *song2
|
331
|
+
- *song3
|
332
|
+
- *song4
|
333
|
+
- *song5
|
334
|
+
- *song6
|
335
|
+
- *song7
|
336
|
+
- &playlist2
|
337
|
+
file: "Astral_Projection_-_Dancing_Galaxy.m3u"
|
338
|
+
songs:
|
339
|
+
- *song8
|
340
|
+
- *song9
|
341
|
+
- *song10
|
342
|
+
- *song11
|
343
|
+
- *song12
|
344
|
+
- *song13
|
345
|
+
- *song14
|
346
|
+
- *song15
|
347
|
+
|
data/examples/rmpc.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
# This is a very simple MPD client that just sends commands to the server
|
4
|
+
# from the command line
|
5
|
+
#
|
6
|
+
# Copyright 2006 Andrew Rader ( bitwise_mcgee AT yahoo.com | http://nymb.us )
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'librmpd'
|
10
|
+
|
11
|
+
if ARGV.length == 0
|
12
|
+
puts "Usage: rmpc.rb <command> <command options>"
|
13
|
+
puts "\tUse --help for commands / command options"
|
14
|
+
|
15
|
+
else
|
16
|
+
if ARGV.include?( '--help' ) or ARGV.include?( '-h' )
|
17
|
+
puts "Usage: rmpc.rb <command> <command options>"
|
18
|
+
puts "\tAvailable Commands / Command Options:\n\n"
|
19
|
+
puts "\tcmd\topts\tdescription"
|
20
|
+
puts "\tplay\t[pos]\tbegin playback, optionally play song at position pos"
|
21
|
+
puts "\tpause\tnone\ttoggle the pause flag"
|
22
|
+
puts "\tstop\tnone\tstop playback"
|
23
|
+
puts "\tnext\tnone\tplay next in playlist"
|
24
|
+
puts "\tprev\tnone\tplay previous in playlist"
|
25
|
+
puts "\tvolume\t[vol]\tprint the current volume, or, sets the volume to vol"
|
26
|
+
puts "\trepeat\tnone\ttoggle the repeat flag"
|
27
|
+
puts "\trandom\tnone\ttoggle the random flag"
|
28
|
+
puts "\tstats\tnone\tprint the server stats"
|
29
|
+
else
|
30
|
+
mpd = MPD.new
|
31
|
+
mpd.connect
|
32
|
+
case ARGV[0]
|
33
|
+
when 'play'
|
34
|
+
mpd.play ARGV[1].to_i - 1
|
35
|
+
when 'pause'
|
36
|
+
mpd.pause = !mpd.paused?
|
37
|
+
when 'stop'
|
38
|
+
mpd.stop
|
39
|
+
when 'next'
|
40
|
+
mpd.next
|
41
|
+
when 'prev'
|
42
|
+
mpd.previous
|
43
|
+
when 'volume'
|
44
|
+
if ARGV[1].nil?
|
45
|
+
puts "Volume: #{mpd.volume}"
|
46
|
+
else
|
47
|
+
mpd.volume = ARGV[1].to_i
|
48
|
+
end
|
49
|
+
when 'consume'
|
50
|
+
mpd.consume = !mpd.consume?
|
51
|
+
when 'single'
|
52
|
+
mpd.single = !mpd.single?
|
53
|
+
when 'repeat'
|
54
|
+
mpd.repeat = !mpd.repeat?
|
55
|
+
when 'random'
|
56
|
+
mpd.random = !mpd.random?
|
57
|
+
when 'stats'
|
58
|
+
hash = mpd.stats
|
59
|
+
hash.each_pair do |key, value|
|
60
|
+
puts "#{key} => #{value}"
|
61
|
+
end
|
62
|
+
else
|
63
|
+
puts "Unknown Command #{ARGV[0]}"
|
64
|
+
end
|
65
|
+
mpd.disconnect
|
66
|
+
end
|
67
|
+
end
|
data/examples/tailmpc.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
|
3
|
+
#
|
4
|
+
# This is a very simple MPD client that just spews changes on the server
|
5
|
+
# out to the console (much like tail works on normal files)
|
6
|
+
#
|
7
|
+
# Copyright 2006 Andrew Rader ( bitwise_mcgee AT yahoo.com | http://nymb.us )
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'librmpd'
|
11
|
+
|
12
|
+
class TailMPC
|
13
|
+
|
14
|
+
def initialize( time_cb = false )
|
15
|
+
@mpd = MPD.new
|
16
|
+
|
17
|
+
@mpd.register_callback( self.method('playlist_cb'), MPD::PLAYLIST_CALLBACK )
|
18
|
+
@mpd.register_callback( self.method('song_cb'), MPD::CURRENT_SONG_CALLBACK )
|
19
|
+
@mpd.register_callback( self.method('state_cb'), MPD::STATE_CALLBACK )
|
20
|
+
@mpd.register_callback( self.method('time_cb'), MPD::TIME_CALLBACK ) if time_cb
|
21
|
+
@mpd.register_callback( self.method('vol_cb'), MPD::VOLUME_CALLBACK )
|
22
|
+
@mpd.register_callback( self.method('repeat_cb'), MPD::REPEAT_CALLBACK )
|
23
|
+
@mpd.register_callback( self.method('random_cb'), MPD::RANDOM_CALLBACK )
|
24
|
+
@mpd.register_callback( self.method('pls_length_cb'), MPD::PLAYLIST_LENGTH_CALLBACK )
|
25
|
+
@mpd.register_callback( self.method('xfade_cb'), MPD::CROSSFADE_CALLBACK )
|
26
|
+
@mpd.register_callback( self.method('songid_cb'), MPD::CURRENT_SONGID_CALLBACK )
|
27
|
+
@mpd.register_callback( self.method('bitrate_cb'), MPD::BITRATE_CALLBACK )
|
28
|
+
@mpd.register_callback( self.method('audio_cb'), MPD::AUDIO_CALLBACK )
|
29
|
+
@mpd.register_callback( self.method('connection_cb'), MPD::CONNECTION_CALLBACK )
|
30
|
+
end
|
31
|
+
|
32
|
+
def start
|
33
|
+
puts "Starting TailMPC - Press Ctrl-D to quit\n\n"
|
34
|
+
@mpd.connect true
|
35
|
+
t = Thread.new do
|
36
|
+
gets
|
37
|
+
end
|
38
|
+
|
39
|
+
t.join
|
40
|
+
end
|
41
|
+
|
42
|
+
def stop
|
43
|
+
puts "Shutting Down TailMPC"
|
44
|
+
@mpd.disconnect true
|
45
|
+
end
|
46
|
+
|
47
|
+
def time_cb( elapsed, total )
|
48
|
+
el_min = elapsed / 60
|
49
|
+
el_sec = elapsed % 60
|
50
|
+
|
51
|
+
elapsed = "#{el_min}:#{el_sec}"
|
52
|
+
|
53
|
+
tot_min = total / 60
|
54
|
+
tot_sec = total % 60
|
55
|
+
|
56
|
+
total = "#{tot_min}:#{tot_sec}"
|
57
|
+
puts "Time: #{elapsed} / #{total}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def state_cb( newstate )
|
61
|
+
puts "State: #{newstate}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def song_cb( current )
|
65
|
+
if not current.nil?
|
66
|
+
puts "Current Song: \n\tID: #{current.songid}\n\tPosition: #{current.pos}\n\tFile: #{current.file}\n\tArtist: #{current.artist}\n\tTitle: #{current.title}"
|
67
|
+
else
|
68
|
+
puts "Curent Song: nil"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def playlist_cb( pls )
|
73
|
+
puts "Playlist: Version ##{pls}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def vol_cb( vol )
|
77
|
+
puts "Volume: #{vol}%"
|
78
|
+
end
|
79
|
+
|
80
|
+
def repeat_cb( rep )
|
81
|
+
puts(rep ? 'Repeat: On' : 'Repeat: Off')
|
82
|
+
end
|
83
|
+
|
84
|
+
def random_cb( ran )
|
85
|
+
puts(ran ? 'Random: On' : 'Random: Off')
|
86
|
+
end
|
87
|
+
|
88
|
+
def pls_length_cb( len )
|
89
|
+
puts "Playlist Length: #{len}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def xfade_cb( xfade )
|
93
|
+
puts "Crossfade: #{xfade}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def songid_cb( id )
|
97
|
+
puts "Current Song ID: #{id}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def bitrate_cb( rate )
|
101
|
+
puts "Bitrate: #{rate}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def audio_cb( sample, bits, channels )
|
105
|
+
puts "Audio:\n\tSample Rate: #{sample}\n\tBits: #{bits}\n\tChannels: #{channels}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def connection_cb( connected )
|
109
|
+
puts( connected ? 'Connected' : 'Disconnected' )
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
client = TailMPC.new #true # Uncomment the true to enable the time callback
|
114
|
+
|
115
|
+
client.start
|