changeset 551:ad5043f70fda

bin/curvecalc (with no song choice) defaults to whatever-ascoltami-is-currently-on Ignore-this: 22a936edc1548675f97fcfc785573457
author drewp@bigasterisk.com
date Tue, 15 Jun 2010 06:27:52 +0000
parents f233fa1ec801
children 1026574e90b0
files bin/curvecalc
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Tue Jun 15 06:22:40 2010 +0000
+++ b/bin/curvecalc	Tue Jun 15 06:27:52 2010 +0000
@@ -17,7 +17,7 @@
 except ImportError:
     import louie as dispatcher 
 from twisted.internet import reactor,tksupport
-import jsonlib
+import jsonlib, restkit
 import twisted
 from twisted.web.client import Agent
 from twisted.internet.protocol import Protocol
@@ -453,10 +453,16 @@
                         anchor='w')
         line.pack(side='top',fill='x')
 
+def currentlyPlayingSong():
+    """ask the music player what song it's on"""
+    t = jsonlib.read(restkit.Resource(networking.musicUrl()).get("time").body)
+    if t['song'] is None:
+        raise ValueError("music player is not playing any song")
+    return URIRef(t['song'])
 
 def main():
     parser = optparse.OptionParser()
-    parser.set_usage("%prog [opts] songURI")
+    parser.set_usage("%prog [opts] [songURI]")
     parser.add_option("--sliders", action='store_true',
                       help='use hardware sliders')
     parser.add_option("--skip-music", action='store_true',
@@ -466,7 +472,7 @@
     try:
         song = URIRef(args[0])
     except IndexError:
-        raise SystemExit("song URI is required, e.g. 'http://light9.bigasterisk.com/show/dance2008/song3'")
+        song = currentlyPlayingSong()
 
     log.debug("music")
     music=Music()