changeset 592:776401dea077

vidref: try not to stop gathering time even upon error; don't scan dirs repeatedly, which was ruining seeks Ignore-this: a303b02cbdc2e1224534b8d5a2500fcc
author drewp@bigasterisk.com
date Sun, 20 Jun 2010 05:04:47 +0000
parents 58e2e6ca1ff1
children 39752169b803
files light9/vidref/main.py light9/vidref/replay.py
diffstat 2 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/light9/vidref/main.py	Sun Jun 20 05:04:32 2010 +0000
+++ b/light9/vidref/main.py	Sun Jun 20 05:04:47 2010 +0000
@@ -51,16 +51,20 @@
 
     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):
--- a/light9/vidref/replay.py	Sun Jun 20 05:04:32 2010 +0000
+++ b/light9/vidref/replay.py	Sun Jun 20 05:04:47 2010 +0000
@@ -182,6 +182,8 @@
                 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 @@
     """
     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)