changeset 539:5cf326ef965a

cleanup asco to use song uris consistently. showPaths are now file: uris Ignore-this: 8ca9cfa22e340760c02a980009499ca3
author drewp@bigasterisk.com
date Sun, 13 Jun 2010 09:19:49 +0000
parents 571d058c9838
children 15169d92c4b7
files light9/ascoltami/index.html light9/ascoltami/webapp.py show/dance2010/config.n3
diffstat 3 files changed, 50 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/light9/ascoltami/index.html	Sun Jun 13 07:57:29 2010 +0000
+++ b/light9/ascoltami/index.html	Sun Jun 13 09:19:49 2010 +0000
@@ -67,7 +67,7 @@
     function showCurrentSong(uri) {
 	$(".songs div").each(function (i, row) {
 	    row = $(row);
-	    if (row.find("button").data("path") == uri) {
+	    if (row.find("button").data("uri") == uri) {
 		row.addClass("currentSong");
 	    } else {
 		row.removeClass("currentSong");
@@ -81,7 +81,7 @@
 	    button.text(song.label);
 	    button.data(song);
 	    button.click(function () {
-		$.post("song", button.data("path"), 
+		$.post("song", button.data("uri"), 
 		       function (data, textStatus, xhr) {
 			   showCurrentSong(song.uri);
 		       });
--- a/light9/ascoltami/webapp.py	Sun Jun 13 07:57:29 2010 +0000
+++ b/light9/ascoltami/webapp.py	Sun Jun 13 09:19:49 2010 +0000
@@ -1,11 +1,24 @@
 import web, jsonlib
 from twisted.python.util import sibpath
 from light9.namespaces import L9
-
+from rdflib import URIRef
 player = None
 graph = None
 show = None
 
+
+def songLocation(graph, songUri):
+    loc = graph.value(songUri, L9['showPath'])
+    if loc is None:
+        raise ValueError("no showPath for %r" % songUri)
+    return loc
+    
+def songUri(graph, locationUri):
+    try:
+        return graph.subjects(L9['showPath'], locationUri).next()
+    except StopIteration:
+        raise ValueError("no song has :showPath of %r" % locationUri)
+
 class root(object):
     def GET(self):
         web.header("Content-type", "application/xhtml+xml")
@@ -15,13 +28,24 @@
 
 class timeResource(object):
     def GET(self):
-        return jsonlib.write({"song" : player.playbin.get_property("uri"),
-                              "started" : player.playStartTime,
-                              "duration" : player.duration(),
-                              "playing" : player.isPlaying(),
-                              "t" : player.currentTime()})
+        playingLocation = player.playbin.get_property("uri")
+        if playingLocation:
+            song = songUri(graph, URIRef(playingLocation))
+        else:
+            song = None
+        return jsonlib.write({
+            "song" : song,
+            "started" : player.playStartTime,
+            "duration" : player.duration(),
+            "playing" : player.isPlaying(),
+            "t" : player.currentTime()})
 
     def POST(self):
+        """
+        post a json object with {pause: true} or {resume: true} if you
+        want those actions. Use {t: <seconds>} to seek, optionally
+        with a pause/resume command too.
+        """
         params = jsonlib.read(web.data(), use_float=True)
         if params.get('pause', False):
             player.pause()
@@ -48,7 +72,7 @@
 class songResource(object):
     def POST(self):
         """post a uri of song to switch to (and start playing)"""
-        player.setSong(web.data())
+        player.setSong(songLocation(graph, URIRef(web.data())))
         return "ok"
     
 class seekPlayOrPause(object):
--- a/show/dance2010/config.n3	Sun Jun 13 07:57:29 2010 +0000
+++ b/show/dance2010/config.n3	Sun Jun 13 09:19:49 2010 +0000
@@ -25,23 +25,23 @@
    sh:song11, sh:song12, sh:song13, sh:song14, sh:song15, sh:song16,
    sh:song17 .
 
-sh:song1 rdfs:label "1 chorus";		:showPath "file:///my/proj/light9/show/dance2010/music/01-chorusmix.wav" .
-sh:song2 rdfs:label "2 dolly";		:showPath "file:///my/proj/light9/show/dance2010/music/02-dolly.wav" .
-sh:song3 rdfs:label "3 opposites";	:showPath "file:///my/proj/light9/show/dance2010/music/03-oppositesmix.wav" .
-sh:song4 rdfs:label "4 top hat";	:showPath "file:///my/proj/light9/show/dance2010/music/04-tophat.wav" .
-sh:song5 rdfs:label "5 temple";		:showPath "file:///my/proj/light9/show/dance2010/music/05-temple.wav" .
-sh:song6 rdfs:label "6 ";		:showPath "file:///my/proj/light9/show/dance2010/music/06-contemporarymix.wav" .
-sh:song7 rdfs:label "7 jackson";	:showPath "file:///my/proj/light9/show/dance2010/music/07-jacksonmix-complete.wav" .
-sh:song8 rdfs:label "8 singing";	:showPath "file:///my/proj/light9/show/dance2010/music/08-singingmix.wav" .
-sh:song9 rdfs:label "9 abc";		:showPath "file:///my/proj/light9/show/dance2010/music/09-abc.wav" .
-sh:song10 rdfs:label "10 ritz";		:showPath "file:///my/proj/light9/show/dance2010/music/10-ritz.wav" .
-sh:song11 rdfs:label "11 black or white";		:showPath "file:///my/proj/light9/show/dance2010/music/11-blackmix.wav" .
-sh:song12 rdfs:label "12 eleanor";	:showPath "file:///my/proj/light9/show/dance2010/music/12-eleanor.wav" .
-sh:song13 rdfs:label "13 sleeping";		:showPath "file:///my/proj/light9/show/dance2010/music/13-sleepingmix.wav" .
-sh:song14 rdfs:label "14 charity";	:showPath "file:///my/proj/light9/show/dance2010/music/14-charitymix.wav" .
-sh:song15 rdfs:label "15 fosse";	:showPath "file:///my/proj/light9/show/dance2010/music/15-fossemix.wav" .
-sh:song16 rdfs:label "16 hip hop";	:showPath "file:///my/proj/light9/show/dance2010/music/16-hiphopmix.wav" .
-sh:song17 rdfs:label "17 broadway";	:showPath "file:///my/proj/light9/show/dance2010/music/17-broadwaymix.wav" .
+sh:song1 rdfs:label "1 chorus";            :showPath <file:///my/proj/light9/show/dance2010/music/01-chorusmix.wav> .
+sh:song2 rdfs:label "2 dolly";             :showPath <file:///my/proj/light9/show/dance2010/music/02-dolly.wav> .
+sh:song3 rdfs:label "3 opposites";         :showPath <file:///my/proj/light9/show/dance2010/music/03-oppositesmix.wav> .
+sh:song4 rdfs:label "4 top hat";           :showPath <file:///my/proj/light9/show/dance2010/music/04-tophat.wav> .
+sh:song5 rdfs:label "5 temple";            :showPath <file:///my/proj/light9/show/dance2010/music/05-temple.wav> .
+sh:song6 rdfs:label "6 ";                  :showPath <file:///my/proj/light9/show/dance2010/music/06-contemporarymix.wav> .
+sh:song7 rdfs:label "7 jackson";           :showPath <file:///my/proj/light9/show/dance2010/music/07-jacksonmix-complete.wav> .
+sh:song8 rdfs:label "8 singing";           :showPath <file:///my/proj/light9/show/dance2010/music/08-singingmix.wav> .
+sh:song9 rdfs:label "9 abc";               :showPath <file:///my/proj/light9/show/dance2010/music/09-abc.wav> .
+sh:song10 rdfs:label "10 ritz";            :showPath <file:///my/proj/light9/show/dance2010/music/10-ritz.wav> .
+sh:song11 rdfs:label "11 black or white";  :showPath <file:///my/proj/light9/show/dance2010/music/11-blackmix.wav> .
+sh:song12 rdfs:label "12 eleanor";         :showPath <file:///my/proj/light9/show/dance2010/music/12-eleanor.wav> .
+sh:song13 rdfs:label "13 sleeping";        :showPath <file:///my/proj/light9/show/dance2010/music/13-sleepingmix.wav> .
+sh:song14 rdfs:label "14 charity";         :showPath <file:///my/proj/light9/show/dance2010/music/14-charitymix.wav> .
+sh:song15 rdfs:label "15 fosse";           :showPath <file:///my/proj/light9/show/dance2010/music/15-fossemix.wav> .
+sh:song16 rdfs:label "16 hip hop";         :showPath <file:///my/proj/light9/show/dance2010/music/16-hiphopmix.wav> .
+sh:song17 rdfs:label "17 broadway";        :showPath <file:///my/proj/light9/show/dance2010/music/17-broadwaymix.wav> .
 
 sub:red :group group:strip; :order 0 .
 sub:orange :group group:strip; :order 1 .