From: Richard Kettlewell Date: Sun, 9 Dec 2007 19:56:40 +0000 (+0000) Subject: play now returns the new track's ID, and disorder.play() returns it. X-Git-Tag: 1.5.99+dev10~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/81e440cef0e926bb730916f50edc635f75822cf1 play now returns the new track's ID, and disorder.play() returns it. queue.py takes advantage of this in some new tests. --- diff --git a/doc/disorder_protocol.5.in b/doc/disorder_protocol.5.in index b98c0f5..a9d973d 100644 --- a/doc/disorder_protocol.5.in +++ b/doc/disorder_protocol.5.in @@ -145,7 +145,7 @@ or 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. diff --git a/python/disorder.py.in b/python/disorder.py.in index 9585438..7582979 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -403,8 +403,11 @@ class client: 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. @@ -711,6 +714,21 @@ class client: 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. diff --git a/server/server.c b/server/server.c index 5d88db4..413b43e 100644 --- a/server/server.c +++ b/server/server.c @@ -225,7 +225,7 @@ static int c_play(struct conn *c, char **vec, * 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); diff --git a/tests/play.py b/tests/play.py index 5c2df1b..96cc2fd 100755 --- a/tests/play.py +++ b/tests/play.py @@ -27,14 +27,14 @@ def test(): 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) @@ -42,7 +42,7 @@ def test(): 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() @@ -51,6 +51,18 @@ def test(): 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() diff --git a/tests/queue.py b/tests/queue.py index b26bdf3..cc0b619 100755 --- a/tests/queue.py +++ b/tests/queue.py @@ -33,6 +33,46 @@ def test(): "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()