# HG changeset patch # User drewp@bigasterisk.com # Date 2010-06-20 05:04:47 # Node ID 776401dea0777a23ba84c4b51c7c1ddebee216b2 # Parent 58e2e6ca1ff1c6d0686947c743e8e004723d6897 vidref: try not to stop gathering time even upon error; don't scan dirs repeatedly, which was ruining seeks Ignore-this: a303b02cbdc2e1224534b8d5a2500fcc diff --git a/light9/vidref/main.py b/light9/vidref/main.py --- a/light9/vidref/main.py +++ b/light9/vidref/main.py @@ -51,16 +51,20 @@ class MusicTime(object): def _timeUpdate(self): while True: - position = jsonlib.loads(self.musicResource.get("time").body, - use_float=True) + try: + position = jsonlib.loads(self.musicResource.get("time").body, + use_float=True) - # 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 - # beginning of my request or the end of it (or some - # fraction of the way through) - self.positionFetchTime = time.time() - - self.position = position + # 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 + # beginning of my request or the end of it (or some + # fraction of the way through) + self.positionFetchTime = time.time() + + self.position = position + except restkit.RequestError, e: + log.error(e) + time.sleep(1) time.sleep(self.period) class VideoRecordSink(gst.Element): diff --git a/light9/vidref/replay.py b/light9/vidref/replay.py --- a/light9/vidref/replay.py +++ b/light9/vidref/replay.py @@ -182,6 +182,8 @@ class ReplayView(object): self.picWidget.queue_draw_area(0,0,320,240) self.picWidget.get_window().process_updates(True) self.showingPic = inPic + +_existingFrames = {} # takeDir : frames class Replay(object): """ @@ -189,8 +191,13 @@ class Replay(object): """ def __init__(self, takeDir): self.takeDir = takeDir - self.existingFrames = sorted([Decimal(f.split('.jpg')[0]) - for f in os.listdir(self.takeDir)]) + try: + self.existingFrames = _existingFrames[self.takeDir] + except KeyError: + log.info("scanning %s", self.takeDir) + self.existingFrames = sorted([Decimal(f.split('.jpg')[0]) + for f in os.listdir(self.takeDir)]) + _existingFrames[self.takeDir] = self.existingFrames def tooShort(self, minSeconds=5): return len(self.existingFrames) < (minSeconds * framerate)