annotate bin/ascoltami2 @ 929:c20c2eea6fce

another hack to stop graphfile from thinking its own new empty file means it should delete all the statements in that context Ignore-this: 94639afbbe8d3a0abd8a06e16922394f
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 11 Jun 2013 20:25:02 +0000
parents cca75951554a
children c2faa69099e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
686
a301a0039c66 buildout and rdflib updates
Drew Perttula <drewp@bigasterisk.com>
parents: 674
diff changeset
1 #!bin/python
868
224d6cd7e1e4 asco use colored logs
Drew Perttula <drewp@bigasterisk.com>
parents: 793
diff changeset
2 from run_local import log
907
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
3 from twisted.internet import gireactor, reactor
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
4 import web, thread, sys, optparse, logging
529
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
5 from rdflib import URIRef
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
6 sys.path.append(".")
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
7 from light9.ascoltami.player import Player
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
8 from light9.ascoltami.playlist import Playlist, NoSuchSong
788
8d87a3528369 go button support
drewp@bigasterisk.com
parents: 686
diff changeset
9 from light9.ascoltami.webapp import makeWebApp, songUri, songLocation
529
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
10 from light9 import networking, showconfig
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
11
907
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
12 import gi
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
13 gi.require_version('Gst', '1.0')
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
14 from gi.repository import GObject, Gst, Gtk
673
865532790e62 asco don't log every web request. too much "GET /time"
Drew Perttula <drewp@bigasterisk.com>
parents: 623
diff changeset
15
907
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
16 class App(object):
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
17 def __init__(self, graph, show):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
18 self.graph = graph
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
19 self.player = Player(onEOS=self.onEOS)
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
20 self.show = show
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
21 self.playlist = Playlist.fromShow(graph, show)
529
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
22
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
23 def onEOS(self, song):
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
24 self.player.pause()
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
25 self.player.seek(0)
529
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
26
788
8d87a3528369 go button support
drewp@bigasterisk.com
parents: 686
diff changeset
27 thisSongUri = songUri(graph, URIRef(song))
8d87a3528369 go button support
drewp@bigasterisk.com
parents: 686
diff changeset
28
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
29 try:
788
8d87a3528369 go button support
drewp@bigasterisk.com
parents: 686
diff changeset
30 nextSong = self.playlist.nextSong(thisSongUri)
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
31 except NoSuchSong: # we're at the end of the playlist
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
32 return
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
33
788
8d87a3528369 go button support
drewp@bigasterisk.com
parents: 686
diff changeset
34 self.player.setSong(songLocation(graph, nextSong), play=False)
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
35
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
36 if __name__ == "__main__":
907
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
37 GObject.threads_init()
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
38 Gst.init(None)
529
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
39
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
40 parser = optparse.OptionParser()
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
41 parser.add_option('--show',
623
46d319974176 move networking settings to config.n3
drewp@bigasterisk.com
parents: 621
diff changeset
42 help='show URI, like http://light9.bigasterisk.com/show/dance2008', default=showconfig.showUri())
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
43 parser.add_option("-v", "--verbose", action="store_true",
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
44 help="logging.DEBUG")
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
45 (options, args) = parser.parse_args()
529
1156d3531327 new ascoltami2, using gstreamer
drewp@bigasterisk.com
parents:
diff changeset
46
617
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
47 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
48
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
49 if not options.show:
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
50 raise ValueError("missing --show http://...")
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
51
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
52 graph = showconfig.getGraph()
94039df5cdd9 create Playlist class which is now used in wavecurve, musicPad, and ascoltami2.
David McClosky <dmcc@bigasterisk.com>
parents: 536
diff changeset
53 app = App(graph, URIRef(options.show))
907
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
54 reactor.listenTCP(networking.musicPlayer.port, makeWebApp(app))
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
55 log.info("listening on %s" % networking.musicPlayer.port)
cca75951554a port ascoltami to Gst 1.0, work around the missing message signals
Drew Perttula <drewp@bigasterisk.com>
parents: 868
diff changeset
56 reactor.run()