From 7c92a516732206df5ee64177fa97c3b28cff60e5 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 16 Nov 2013 23:08:52 +0200 Subject: [PATCH] os.stat is avoided now for faster file list loading --- src/handlers.py | 2 +- src/mediafiles.py | 21 +++++++++++++++++---- static/js/main.js | 11 ++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/handlers.py b/src/handlers.py index f32b62f..d8fd132 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -553,7 +553,7 @@ class PictureHandler(BaseHandler): else: def on_response(jpg): if jpg is None: - self.finish({}) + self.finish() else: self.finish(jpg) diff --git a/src/mediafiles.py b/src/mediafiles.py index 1119165..32bfc86 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -90,7 +90,8 @@ def make_movie_preview(camera_config, full_path): framerate = camera_config['framerate'] pre_capture = camera_config['pre_capture'] offs = pre_capture / framerate - + offs *= 2 + cmd = 'ffmpeg -i "%(path)s" -f mjpeg -vframes 1 -ss %(offs)s -y %(path)s.thumb' % { 'path': full_path, 'offs': offs} @@ -149,12 +150,24 @@ def list_media(camera_config, media_type): path = p[len(target_dir):] if not path.startswith('/'): path = '/' + path + +# try: +# stat = os.stat(p) +# +# except Exception as e: +# logging.error('stat call failed for file %(path)s: %(msg)s' % { +# 'path': path, 'msg': unicode(e)}) +# +# continue +# +# timestamp = stat.st_mtime +# size = stat.st_size media_files.append({ 'path': path, - 'momentStr': utils.pretty_date_time(datetime.datetime.fromtimestamp(os.path.getmtime(p))), - 'sizeStr': utils.pretty_size(os.path.getsize(p)), - 'timestamp': os.path.getmtime(p) + #'momentStr': utils.pretty_date_time(datetime.datetime.fromtimestamp(timestamp)), + #'sizeStr': utils.pretty_size(size), + #'timestamp': timestamp }) # TODO files listed here may not belong to the given camera diff --git a/static/js/main.js b/static/js/main.js index c47dcd4..9dde017 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1395,9 +1395,14 @@ function runMediaDialog(cameraId, mediaType) { var nameDiv = $('
' + entry.name + '
'); entryDiv.append(nameDiv); - var detailsDiv = $('
'); - detailsDiv.html(entry.momentStr + ' | ' + entry.sizeStr); - entryDiv.append(detailsDiv); + if (entry.momentStr && entry.sizeStr) { + var detailsDiv = $('
'); + detailsDiv.html(entry.momentStr + ' | ' + entry.sizeStr); + entryDiv.append(detailsDiv); + } + else { + nameDiv.css('line-height', '2.3em'); + } downloadButton[0]._onClick = function () { window.location.href = '/picture/' + cameraId + '/download' + entry.path; -- 2.39.5