Changeset - 9f774fd3c926
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 13 years ago 2012-06-16 04:34:49
drewp@bigasterisk.com
don't break on a hovertime failur
Ignore-this: 5fc6734a6f8f52c560583796acf31d6a
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
light9/vidref/main.py
Show inline comments
 
@@ -8,24 +8,25 @@ gst-launch dv1394src ! dvdemux name=d ! 
 
"""
 
import pygst
 
pygst.require("0.10")
 
import gst, gobject, time, json, restkit, logging, os, traceback
 
import gtk
 
from twisted.python.util import sibpath
 
import Image
 
from threading import Thread
 
from Queue import Queue
 
from light9 import networking
 
from light9.vidref.replay import ReplayViews, songDir, takeDir, framerate
 
from restkit.errors import ResourceNotFound
 
import http_parser.http
 

	
 
log = logging.getLogger()
 

	
 
class MusicTime(object):
 
    """
 
    fetch times from ascoltami in a background thread; return times
 
    upon request, adjusted to be more precise with the system clock
 
    """
 
    def __init__(self, period=.2, onChange=lambda position: None):
 
        """period is the seconds between http time requests.
 

	
 
        We call onChange with the time in seconds and the total time
 
@@ -45,26 +46,28 @@ class MusicTime(object):
 

	
 
    def getLatest(self):
 
        """
 
        dict with 't' and 'song', etc.
 
        """
 
        if not hasattr(self, 'position'):
 
            return {'t' : 0, 'song' : None}
 
        pos = self.position.copy()
 
        if pos['playing']:
 
            pos['t'] = pos['t'] + (time.time() - self.positionFetchTime)
 
        else:
 
            try:
 
                # todo: this is blocking for a long while if CC is
 
                # down. Either make a tiny timeout, or go async
 
                r = self.curveCalc.get("hoverTime")
 
            except ResourceNotFound:
 
            except (ResourceNotFound, http_parser.http.NoMoreData, Exception):
 
                pass
 
            else:
 
                pos['hoverTime'] = json.loads(r.body_string())['hoverTime']
 
        return pos
 

	
 
    def _timeUpdate(self):
 
        while True:
 
            try:
 
                position = json.loads(self.musicResource.get("time").body_string())
 

	
 
                # this is meant to be the time when the server gave me its
 
                # report, and I don't know if that's closer to the
0 comments (0 inline, 0 general)