]> www.vanbest.org Git - motioneye-debian/commitdiff
added initial code for media file listing
authorCalin Crisan <ccrisan@gmail.com>
Sat, 9 Nov 2013 19:52:16 +0000 (21:52 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 9 Nov 2013 19:52:16 +0000 (21:52 +0200)
src/handlers.py
src/mediafiles.py

index cb9d5fafaca62fcec698d1d92dafa213aee86dc9..cdef782eaf05bfb111d7a04c817daaee8fb3f691 100644 (file)
@@ -22,6 +22,7 @@ import logging
 from tornado.web import RequestHandler, HTTPError, asynchronous
 
 import config
+import mediafiles
 import mjpgclient
 import motionctl
 import remote
@@ -591,14 +592,10 @@ class PictureHandler(BaseHandler):
                     camera_config.get('@remote_camera_id'), on_response)
         
         else:
-            pictures = []
+            pictures = mediafiles.list_pictures(camera_config)
             
-            #for 
-                
             self.finish_json({'pictures': pictures})
         
-        self.finish_json()
-    
     @BaseHandler.auth()
     def download(self, camera_id, filename):
         logging.debug('downloading picture %(filename)s of camera %(id)s' % {
index e423698dab159fd989026f15b7af2a5784200bdf..57014732580378dbdf92424b4f282def637c2ca0 100644 (file)
 
 import datetime
 import logging
-import os
+import os.path
 
 import config
 
 
-def _remove_older_files(dir, moment, exts):
+_PICTURE_EXTS = ['.jpg']
+_MOVIE_EXTS = ['.avi', '.mp4']
+
+
+def _list_media_files(dir, exts):
+    full_paths = []
     for root, dirs, files in os.walk(dir):  # @UnusedVariable
         for name in files:
             full_path = os.path.join(root, name)
             if not os.path.isfile(full_path):
                 continue
-            
+             
             full_path_lower = full_path.lower()
             if not [e for e in exts if full_path_lower.endswith(e)]:
                 continue
             
-            file_moment = datetime.datetime.fromtimestamp(os.path.getmtime(full_path))
-            if file_moment < moment:
-                logging.debug('removing file %(path)s...' % {
-                        'path': full_path})
-                
-                os.remove(full_path)
+            full_paths.append(full_path)
+    
+    return full_paths
+
+
+def _remove_older_files(dir, moment, exts):
+    for full_path in _list_media_files(dir, exts):
+        # TODO files listed here may not belong to the given camera
+        
+        file_moment = datetime.datetime.fromtimestamp(os.path.getmtime(full_path))
+        if file_moment < moment:
+            logging.debug('removing file %(path)s...' % {
+                    'path': full_path})
+            
+            os.remove(full_path)
 
 
 def cleanup_pictures():
@@ -56,7 +70,7 @@ def cleanup_pictures():
         preserve_moment = datetime.datetime.now() - datetime.timedelta(days=preserve_pictures)
             
         target_dir = camera_config.get('target_dir')
-        _remove_older_files(target_dir, preserve_moment, exts=['.jpg', '.png'])
+        _remove_older_files(target_dir, preserve_moment, exts=_PICTURE_EXTS)
 
 
 def cleanup_movies():
@@ -74,8 +88,40 @@ def cleanup_movies():
         preserve_moment = datetime.datetime.now() - datetime.timedelta(days=preserve_movies)
             
         target_dir = camera_config.get('target_dir')
-        _remove_older_files(target_dir, preserve_moment, exts=['.avi'])
+        _remove_older_files(target_dir, preserve_moment, exts=_MOVIE_EXTS)
+
+
+def list_pictures(camera_config):
+    target_dir = camera_config.get('target_dir')
+#     output_all = camera_config.get('output_all')
+#     output_normal = camera_config.get('output_normal')
+#     jpeg_filename = camera_config.get('jpeg_filename')
+#     snapshot_interval = camera_config.get('snapshot_interval')
+#     snapshot_filename = camera_config.get('snapshot_filename')
+#     
+#     if (output_all or output_normal) and jpeg_filename:
+#         filename = jpeg_filename
+#     
+#     elif snapshot_interval and snapshot_filename:
+#         filename = snapshot_filename
+#     
+#     else:
+#         return []
 
+    full_paths = _list_media_files(target_dir, exts=_PICTURE_EXTS)
+    picture_files = [p[len(target_dir):] for p in full_paths]
+    
+    # TODO files listed here may not belong to the given camera
+    
+    return picture_files
 
-def list_pictures(config):
-    pass
\ No newline at end of file
+
+def list_movies(camera_config):
+    target_dir = camera_config.get('target_dir')
+
+    full_paths = _list_media_files(target_dir, exts=_MOVIE_EXTS)
+    movie_files = [p[len(target_dir):] for p in full_paths]
+    
+    # TODO files listed here may not belong to the given camera
+    
+    return movie_files