]> www.vanbest.org Git - motioneye-debian/commitdiff
added a placeholder icon for when no media preview is available
authorCalin Crisan <ccrisan@gmail.com>
Sat, 11 Jan 2014 10:40:42 +0000 (12:40 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 11 Jan 2014 10:40:42 +0000 (12:40 +0200)
src/handlers.py
src/mediafiles.py
static/img/no-preview.svg [new file with mode: 0644]

index f604d634b400f001bbf053d0536bdd8af20f8c79..5229a6f4d708b714b27a583123a0a8f4d343774c 100644 (file)
@@ -26,6 +26,7 @@ import config
 import mediafiles
 import motionctl
 import remote
+import settings
 import template
 import update
 import v4l2ctl
@@ -680,20 +681,15 @@ class PictureHandler(BaseHandler):
         
         camera_config = config.get_camera(camera_id)
         if camera_config['@proto'] != 'v4l2':
-            def on_response(response):
-                camera_url = remote.make_remote_camera_url(
-                        camera_config.get('@host'),
-                        camera_config.get('@port'),
-                        camera_config.get('@remote_camera_id'))
-                
-                camera_full_url = camera_config['@proto'] + '://' + camera_url
+            def on_response(content):
+                if content:
+                    self.set_header('Content-Type', 'image/jpeg')
+                    
+                else:
+                    self.set_header('Content-Type', 'image/svg+xml')
+                    content = open(os.path.join(settings.STATIC_PATH, 'img', 'no-preview.svg')).read()
                 
-                if response is None:
-                    return self.finish_json({'error': 'Failed to get picture preview for %(url)s.' % {
-                            'url': camera_full_url}})
-
-                self.set_header('Content-Type', 'image/jpeg')
-                self.finish(response)
+                self.finish(content)
             
             remote.get_media_preview(
                     camera_config.get('@host'),
@@ -712,7 +708,13 @@ class PictureHandler(BaseHandler):
                     width=self.get_argument('width', None),
                     height=self.get_argument('height', None))
             
-            self.set_header('Content-Type', 'image/jpeg')
+            if content:
+                self.set_header('Content-Type', 'image/jpeg')
+                
+            else:
+                self.set_header('Content-Type', 'image/svg+xml')
+                content = open(os.path.join(settings.STATIC_PATH, 'img', 'no-preview.svg')).read()
+                
             self.finish(content)
 
 
@@ -834,20 +836,15 @@ class MovieHandler(BaseHandler):
         
         camera_config = config.get_camera(camera_id)
         if camera_config['@proto'] != 'v4l2':
-            def on_response(response):
-                camera_url = remote.make_remote_camera_url(
-                        camera_config.get('@host'),
-                        camera_config.get('@port'),
-                        camera_config.get('@remote_camera_id'))
-                
-                camera_full_url = camera_config['@proto'] + '://' + camera_url
-                
-                if response is None:
-                    return self.finish_json({'error': 'Failed to get movie preview for %(url)s.' % {
-                            'url': camera_full_url}})
+            def on_response(content):
+                if content:
+                    self.set_header('Content-Type', 'image/jpeg')
+                    
+                else:
+                    self.set_header('Content-Type', 'image/svg+xml')
+                    content = open(os.path.join(settings.STATIC_PATH, 'img', 'no-preview.svg')).read()
 
-                self.set_header('Content-Type', 'image/jpeg')
-                self.finish(response)
+                self.finish(content)
             
             remote.get_media_preview(
                     camera_config.get('@host'),
@@ -866,7 +863,13 @@ class MovieHandler(BaseHandler):
                     width=self.get_argument('width', None),
                     height=self.get_argument('height', None))
             
-            self.set_header('Content-Type', 'image/jpeg')
+            if content:
+                self.set_header('Content-Type', 'image/jpeg')
+                
+            else:
+                self.set_header('Content-Type', 'image/svg+xml')
+                content = open(os.path.join(settings.STATIC_PATH, 'img', 'no-preview.svg')).read()
+            
             self.finish(content)
 
 
index 579acdc12fb8ca26a76860a3e7bb218862429f5f..9e8d2357c3d1a711697f0516ad3e712c13de368e 100644 (file)
@@ -148,8 +148,17 @@ def make_movie_preview(camera_config, full_path):
         
         return None
     
-    if os.path.getsize(full_path + '.thumb') == 0:
-        logging.debug('movie was too short, grabbing first frame from %(path)s...' % {'path': full_path})
+    try:
+        st = os.stat(full_path + '.thumb')
+    
+    except os.error:
+        logging.error('failed to create movie preview for %(path)s: ffmpeg error' % {
+                'path': full_path})
+
+        return None
+
+    if st.st_size == 0:
+        logging.debug('movie is too short, grabbing first frame from %(path)s...' % {'path': full_path})
         
         # try again, this time grabbing the very first frame
         try:
diff --git a/static/img/no-preview.svg b/static/img/no-preview.svg
new file mode 100644 (file)
index 0000000..17c39f3
--- /dev/null
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.48.4 r9939"
+   width="64"
+   height="64"
+   xml:space="preserve"
+   sodipodi:docname="no-preview.svg"
+   inkscape:export-filename="/home/ccrisan/projects/motioneye/static/img/motioneye-logo.png"
+   inkscape:export-xdpi="960"
+   inkscape:export-ydpi="960"><metadata
+     id="metadata8"><rdf:RDF><cc:Work
+         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
+     id="defs6" /><sodipodi:namedview
+     pagecolor="#969696"
+     bordercolor="#666666"
+     borderopacity="1"
+     objecttolerance="10"
+     gridtolerance="10"
+     guidetolerance="10"
+     inkscape:pageopacity="1"
+     inkscape:pageshadow="2"
+     inkscape:window-width="1920"
+     inkscape:window-height="1030"
+     id="namedview4"
+     showgrid="false"
+     inkscape:zoom="5.0625"
+     inkscape:cx="53.237951"
+     inkscape:cy="28.106834"
+     inkscape:window-x="0"
+     inkscape:window-y="25"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="g10"
+     showguides="true"
+     inkscape:guide-bbox="true" /><g
+     id="g10"
+     inkscape:groupmode="layer"
+     inkscape:label="ink_ext_XXXXXX"
+     transform="matrix(1.25,0,0,-1.25,0,64)"><g
+       id="g3757"
+       style="opacity:0.7"><rect
+         transform="scale(1,-1)"
+         y="-42.400002"
+         x="4"
+         height="34.400002"
+         width="43.200001"
+         id="rect3751"
+         style="fill:none;stroke:#ffffff;stroke-width:1.60000001999999997;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /><path
+         sodipodi:nodetypes="cccccc"
+         transform="matrix(0.8,0,0,-0.8,0,51.2)"
+         inkscape:connector-curvature="0"
+         id="path3753"
+         d="m 11.5,46.5 11,-14 6,6 11,-14 13,22 z"
+         style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" /><path
+         transform="matrix(1.0251562,0,0,-1.0251562,-4.199999,56.75)"
+         d="m 20.484682,24.142662 a 2.3411067,2.3411067 0 1 1 -4.682213,0 2.3411067,2.3411067 0 1 1 4.682213,0 z"
+         sodipodi:ry="2.3411067"
+         sodipodi:rx="2.3411067"
+         sodipodi:cy="24.142662"
+         sodipodi:cx="18.143576"
+         id="path3755"
+         style="fill:#ffffff;fill-opacity:1;stroke:#ffffff;stroke-width:1.56073773000000005;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+         sodipodi:type="arc" /></g></g></svg>
\ No newline at end of file