chiark / gitweb /
play now returns the new track's ID, and disorder.play() returns it.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 9 Dec 2007 19:56:40 +0000 (19:56 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 9 Dec 2007 19:56:40 +0000 (19:56 +0000)
queue.py takes advantage of this in some new tests.

doc/disorder_protocol.5.in
python/disorder.py.in
server/server.c
tests/play.py
tests/queue.py

index b98c0f5ab787f16a13f1c75fd941d46eff31e090..a9d973d1693639facb3f1af023524c0c25204a53 100644 (file)
@@ -145,7 +145,7 @@ or
 Pause the current track.
 .TP
 .B play \fITRACK\fR
 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.
 .TP
 .B playing
 Reports what track is playing.
index 95854383f6768912530fa5280f50d3992973994c..7582979ee14a5479062776358443731877d86589 100644 (file)
@@ -403,8 +403,11 @@ class client:
 
     Arguments:
     track -- the path of the track to play.
 
     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.
 
   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)
 
     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.
 
   def log(self, callback):
     """Read event log entries as they happen.
 
index 5d88db4f04aac15a2323c812c0eb763d3ba11388..413b43e875273a05a0d6602569ea0634e0eec78a 100644 (file)
@@ -225,7 +225,7 @@ static int c_play(struct conn *c, char **vec,
    * anything. */
   if(q == qhead.next && playing)
     prepare(c->ev, q);
    * 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);
   /* If the queue was empty but we are for some reason paused then
    * unpause. */
   if(!playing) resume_playing(0);
index 5c2df1bddaad49606e870a1d4a9d781f34408377..96cc2fd986d9d9be4a6d458d3e314bf49ccb9aec 100755 (executable)
@@ -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)
     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']
     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)
     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()
         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()
     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"
     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()
 
 if __name__ == '__main__':
     dtest.run()
index b26bdf3102ca8c0517f19c8b6bc17af63ee1730e..cc0b619a31e719b97fc81640e08e4fb1694e9c17 100755 (executable)
@@ -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"
                        "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()
 
 if __name__ == '__main__':
     dtest.run()