queue.py takes advantage of this in some new tests.
Pause the current track.
.TP
.B play \fITRACK\fR
-Add a track to the queue.
+Add a track to the queue. The response contains the queue ID of the track.
.TP
.B playing
Reports what track is playing.
Arguments:
track -- the path of the track to play.
+
+ Returns the ID of the new queue entry.
"""
- self._simple("play", track)
+ res, details = self._simple("play", track)
+ return unicode(details) # because it's unicode in queue() output
def remove(self, track):
"""Remove a track from the queue.
ret, details = self._simple("move", track, str(delta))
return int(details)
+ def moveafter(self, target, tracks):
+ """Move a track in the queue
+
+ Arguments:
+ target -- target ID or None
+ tracks -- a list of IDs to move
+
+ If target is '' or is not in the queue then the tracks are moved to
+ the head of the queue.
+
+ Otherwise the tracks are moved to just after the target."""
+ if target is None:
+ target = ''
+ self._simple("moveafter", target, *tracks)
+
def log(self, callback):
"""Read event log entries as they happen.
* anything. */
if(q == qhead.next && playing)
prepare(c->ev, q);
- sink_writes(ev_writer_sink(c->w), "250 queued\n");
+ sink_printf(ev_writer_sink(c->w), "252 %s\n", q->id);
/* If the queue was empty but we are for some reason paused then
* unpause. */
if(!playing) resume_playing(0);
track = u"%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
print "adding track to queue"
c.play(track)
- print "checking track turned up in queue"
+ print " checking track turned up in queue"
q = c.queue()
ts = filter(lambda t: t['track'] == track and 'submitter' in t, q)
assert len(ts) == 1, "checking track appears exactly once in queue"
t = ts[0]
assert t['submitter'] == u'fred', "check queue submitter"
i = t['id']
- print "waiting for track"
+ print " waiting for track"
p = c.playing()
r = c.recent()
while not((p is not None and p['id'] == i)
time.sleep(1)
p = c.playing()
r = c.recent()
- print "checking track turned up in recent list"
+ print " checking track turned up in recent list"
while (p is not None and p['id'] == i):
time.sleep(1)
p = c.playing()
assert len(ts) == 1, "check track appears exactly once in recent"
t = ts[0]
assert t['submitter'] == u'fred', "check recent entry submitter"
+ print " scratching current track"
+ p = c.playing()
+ i = p['id']
+ c.scratch(i)
+ print " checking scratched track turned up in recent list"
+ while (p is not None and p['id'] == i):
+ time.sleep(1)
+ p = c.playing()
+ r = c.recent()
+ ts = filter(lambda t: t['id'] == i, r)
+ assert len(ts) == 1, "check scratched track appears exactly once in recent"
+ assert ts[0]['state'] == 'scratched', "checking track scratched"
if __name__ == '__main__':
dtest.run()
"queue"])
tracks = filter(lambda s: re.match("^track", s), q)
assert len(tracks) == 10, "queue is at proper length"
+ print " disabling random play"
+ c.random_disable()
+ print " emptying queue"
+ for t in c.queue():
+ c.remove(t['id'])
+ print " checking queue is now empty"
+ q = c.queue()
+ assert q == [], "checking queue is empty"
+ print " enabling random play"
+ c.random_enable()
+ print " checking queue refills"
+ q = c.queue()
+ assert len(q) == 10, "queue is at proper length"
+ print " disabling all play"
+ c.random_disable()
+ c.disable()
+ print " emptying queue"
+ for t in c.queue():
+ c.remove(t['id'])
+ t1 = "%s/Joe Bloggs/Third Album/01:First_track.ogg" % dtest.tracks
+ t2 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
+ t3 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
+ print " adding tracks"
+ i1 = c.play(t1)
+ i2 = c.play(t2)
+ i3 = c.play(t3)
+ q = c.queue()
+ assert map(lambda e:e['id'], q) == [i1, i2, i3], "checking queue order(1)"
+ print " moving last track to start"
+ c.moveafter(None, [i3])
+ q = c.queue()
+ assert map(lambda e:e['id'], q) == [i3, i1, i2], "checking queue order(2)"
+ print " moving two tracks"
+ c.moveafter(i1, [i2, i3])
+ q = c.queue()
+ assert map(lambda e:e['id'], q) == [i1, i2 ,i3], "checking queue order(3)"
+ print " removing a track"
+ c.remove(i2)
+ q = c.queue()
+ assert map(lambda e:e['id'], q) == [i1 ,i3], "checking queue order(4)"
if __name__ == '__main__':
dtest.run()