diff bin/ascoltami2 @ 617:94039df5cdd9

create Playlist class which is now used in wavecurve, musicPad, and ascoltami2. Ignore-this: da54d0239906e81ad5d95741d22f5975 Several other refactorings. Also, totally untested.
author David McClosky <dmcc@bigasterisk.com>
date Tue, 22 Jun 2010 04:41:11 +0000
parents 519adb4e539f
children 9ec0396c6f1f
line wrap: on
line diff
--- a/bin/ascoltami2	Tue Jun 22 02:27:30 2010 +0000
+++ b/bin/ascoltami2	Tue Jun 22 04:41:11 2010 +0000
@@ -3,33 +3,56 @@
 from rdflib import URIRef
 sys.path.append(".")
 from light9.ascoltami.player import Player
+from light9.ascoltami.playlist import Playlist, NoSuchSong
 from light9.ascoltami.webapp import makeApp
 from light9 import networking, showconfig
 
-logging.basicConfig()
-log = logging.getLogger()
-gobject.threads_init()
+class App:
+    def __init__(self, graph, show):
+        self.graph = graph
+        self.player = Player(onEOS=self.onEOS)
+        self.show = show
+        self.playlist = Playlist.fromShow(graph, show)
 
-parser = optparse.OptionParser()
-parser.add_option('--show',
-    help='show URI, like http://light9.bigasterisk.com/show/dance2008')
-parser.add_option("-v", "--verbose", action="store_true",
-                  help="logging.DEBUG")
-(options, args) = parser.parse_args()
+    def run(self, musicPort):
+        # the cherrypy server would wedge when vidref pounds on it; this
+        # one seems to run
+        thread.start_new(web.httpserver.runbasic,
+                         (makeWebApp(self).wsgifunc(),
+                          ('0.0.0.0', musicPort)))
 
-log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
+        mainloop = gobject.MainLoop()
+        mainloop.run()
+
+    def onEOS(self, song):
+        self.player.pause()
+        self.player.seek(0)
 
-if not options.show:
-    raise ValueError("missing --show http://...")
-        
-graph = showconfig.getGraph()
-player = Player()
+        try:
+            nextSong = self.playlist.nextSong(song)
+        except NoSuchSong: # we're at the end of the playlist
+            return
+
+        self.player.setSong(nextSong, play=False)
+
+if __name__ == "__main__":
+    logging.basicConfig()
+    log = logging.getLogger()
+    gobject.threads_init()
 
-# the cherrypy server would wedge when vidref pounds on it; this
-# one seems to run
-thread.start_new(web.httpserver.runbasic,
-                 (makeApp(player, graph, URIRef(options.show)).wsgifunc(),
-                  ('0.0.0.0', networking.musicPort())))
+    parser = optparse.OptionParser()
+    parser.add_option('--show',
+        help='show URI, like http://light9.bigasterisk.com/show/dance2008')
+    parser.add_option("-v", "--verbose", action="store_true",
+                      help="logging.DEBUG")
+    (options, args) = parser.parse_args()
 
-mainloop = gobject.MainLoop()
-mainloop.run()
+    log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
+
+    if not options.show:
+        raise ValueError("missing --show http://...")
+            
+    graph = showconfig.getGraph()
+    app = App(graph, URIRef(options.show))
+    musicPort = networking.musicPort()
+    app.run(musicPort)