]> www.vanbest.org Git - motioneye-debian/commitdiff
the time interval used when gathering email attachment pictures is now
authorCalin Crisan <ccrisan@gmail.com>
Sun, 8 Feb 2015 12:17:37 +0000 (14:17 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 8 Feb 2015 12:17:37 +0000 (14:17 +0200)
configurable

motioneye.py
sendmail.py
settings_default.py
src/config.py
static/js/main.js
templates/main.html

index b4d4383e60acfefc0c6c1dcfd676b8bf8caff725..c290b4b05aa743d73679a386024bfb0ed818f01e 100755 (executable)
@@ -63,7 +63,6 @@ def _configure_settings():
     set_default_setting('LOCAL_TIME_FILE', None)
     set_default_setting('ENABLE_REBOOT', False)
     set_default_setting('SMTP_TIMEOUT', 60)
-    set_default_setting('NOTIFY_MEDIA_TIMESPAN', 5)
     set_default_setting('ZIP_TIMEOUT', 500)
 
     length = len(sys.argv) - 1
index 1ac1e25fb4741bb9a683e7d382d5757fae5f8216..a720758f6de6509c0b4393d79d40a33994f65ae6 100755 (executable)
@@ -85,13 +85,13 @@ def send_mail(server, port, account, password, tls, to, subject, message, files)
     conn.quit()
 
 
-def make_message(subject, message, camera_id, moment, callback):
+def make_message(subject, message, camera_id, moment, timespan, callback):
     camera_config = config.get_camera(camera_id)
     
     def on_media_files(media_files):
         timestamp = time.mktime(moment.timetuple())
 
-        media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < settings.NOTIFY_MEDIA_TIMESPAN] # filter out non-recent media files
+        media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < timespan] # filter out non-recent media files
         media_files.sort(key=lambda m: m['timestamp'], reverse=True)
         media_files = [os.path.join(camera_config['target_dir'], re.sub('^/', '', m['path'])) for m in media_files]
 
@@ -116,12 +116,15 @@ def make_message(subject, message, camera_id, moment, callback):
         
         callback(s, m, media_files)
 
-    time.sleep(settings.NOTIFY_MEDIA_TIMESPAN)
+    if not timespan:
+        return on_media_files([])
+        
+    time.sleep(timespan) # give motion some time to create motion pictures
     mediafiles.list_media(camera_config, media_type='picture', callback=on_media_files)
 
 
 def print_usage():
-    print 'Usage: sendmail.py <server> <port> <account> <password> <tls> <to> <msg_id> <camera_id> <moment> <frames>'
+    print 'Usage: sendmail.py <server> <port> <account> <password> <tls> <to> <msg_id> <camera_id> <moment> <frames> [timespan]'
 
 
 if __name__ == '__main__':
@@ -138,6 +141,11 @@ if __name__ == '__main__':
     msg_id = sys.argv[7]
     camera_id = sys.argv[8]
     moment = sys.argv[9]
+    try:
+        timespan = int(sys.argv[10])
+
+    except:
+        timespan = 5
 
     message = messages.get(msg_id)
     subject = subjects.get(msg_id)
@@ -158,6 +166,7 @@ if __name__ == '__main__':
     logging.debug('camera_id = %s' % camera_id)
     logging.debug('moment = %s' % moment.strftime('%Y-%m-%d %H:%M:%S'))
     logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT)
+    logging.debug('timespan = %d' % timespan)
     
     if not to:
         logging.info('no email address specified')
@@ -181,7 +190,7 @@ if __name__ == '__main__':
     def ioloop_timeout():
         io_loop.stop()
     
-    make_message(subject, message, camera_id, moment, on_message)
+    make_message(subject, message, camera_id, moment, timespan, on_message)
 
     io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT), ioloop_timeout)
     io_loop.start()
index 253893e09ed3120d3c7c9bcb75adfc003c808c40..948a33775ce563ffccdceda91305e76584b995a5 100644 (file)
@@ -77,8 +77,5 @@ ENABLE_REBOOT = False
 # the timeout in seconds to use when talking to a SMTP server
 SMTP_TIMEOUT = 60
 
-# the interval in seconds to consider around the moment of the event when attaching media files to notifications 
-NOTIFY_MEDIA_TIMESPAN = 5
-
 # the time to wait for zip file creation
 ZIP_TIMEOUT = 500
index 09215a64e5cd25f47563292174425b991937f051..1a636a1f8defa0feefdfbc01837987c3242d9248 100644 (file)
@@ -19,6 +19,7 @@ import errno
 import logging
 import os.path
 import re
+import shlex
 
 from collections import OrderedDict
 
@@ -730,14 +731,15 @@ def camera_ui_to_dict(ui):
         send_mail_path = os.path.abspath(send_mail_path)
         emails = re.sub('\\s', '', ui['email_notifications_addresses'])
         
-        on_event_start.append('%(script)s "%(server)s" "%(port)s" "%(account)s" "%(password)s" "%(tls)s" "%(to)s" "motion_start" "%%t" "%%Y-%%m-%%dT%%H:%%M:%%S"' % {
+        on_event_start.append('%(script)s "%(server)s" "%(port)s" "%(account)s" "%(password)s" "%(tls)s" "%(to)s" "motion_start" "%%t" "%%Y-%%m-%%dT%%H:%%M:%%S" "%(timespan)s"' % {
                 'script': send_mail_path,
                 'server': ui['email_notifications_smtp_server'],
                 'port': ui['email_notifications_smtp_port'],
                 'account': ui['email_notifications_smtp_account'],
                 'password': ui['email_notifications_smtp_password'],
                 'tls': ui['email_notifications_smtp_tls'],
-                'to': emails})
+                'to': emails,
+                'timespan': ui['email_notifications_picture_time_span']})
 
     if ui['web_hook_notifications_enabled']:
         web_hook_path = os.path.join(settings.PROJECT_PATH, 'webhook.py')
@@ -1033,8 +1035,8 @@ def camera_dict_to_ui(data):
     command_notifications = []
     for e in on_event_start:
         if e.count('sendmail.py') and e.count('motion_start'):
-            e = e.replace('"', '').split(' ')
-            if len(e) != 10:
+            e = shlex.split(e)
+            if len(e) < 10:
                 continue
 
             ui['email_notifications_enabled'] = True 
@@ -1044,9 +1046,14 @@ def camera_dict_to_ui(data):
             ui['email_notifications_smtp_password'] = e[4]
             ui['email_notifications_smtp_tls'] = e[5].lower() == 'true'
             ui['email_notifications_addresses'] = e[6]
+            try:
+                ui['email_notifications_picture_time_span'] = int(e[10])
+                
+            except:
+                ui['email_notifications_picture_time_span'] = 5
 
         elif e.count('webhook.py'):
-            e = e.replace('"', '').split(' ')
+            e = shlex.split(e)
             if len(e) != 3:
                 continue
 
index 5ecfe6faf3f730a3c88722b379bd9ccacfb1ec4b..0695ca805021e9090247f2382b17eda69bdfd855 100644 (file)
@@ -494,6 +494,7 @@ function initUI() {
     makeNumberValidator($('#postCaptureEntry'), 0, 100, false, false, true);
     makeNumberValidator($('#minimumMotionFramesEntry'), 1, 1000, false, false, true);
     makeNumberValidator($('#smtpPortEntry'), 1, 65535, false, false, true);
+    makeNumberValidator($('#emailPictureTimeSpan'), 0, 60, false, false, true);
     
     /* time validators */
     makeTimeValidator($('#mondayFromEntry'));
@@ -811,6 +812,7 @@ function updateConfigUi() {
         $('#smtpAccountEntry').parents('tr:eq(0)').each(markHide);
         $('#smtpPasswordEntry').parents('tr:eq(0)').each(markHide);
         $('#smtpTlsSwitch').parents('tr:eq(0)').each(markHide);
+        $('#emailPictureTimeSpan').parents('tr:eq(0)').each(markHide);
     }
     
     if (!$('#webHookNotificationsSwitch').get(0).checked) {
@@ -995,6 +997,7 @@ function cameraUi2Dict() {
         'email_notifications_smtp_account': $('#smtpAccountEntry').val(),
         'email_notifications_smtp_password': $('#smtpPasswordEntry').val(),
         'email_notifications_smtp_tls': $('#smtpTlsSwitch')[0].checked,
+        'email_notifications_picture_time_span': $('#emailPictureTimeSpan').val(),
         'web_hook_notifications_enabled': $('#webHookNotificationsSwitch')[0].checked,
         'web_hook_notifications_url': $('#webHookUrlEntry').val(),
         'web_hook_notifications_http_method': $('#webHookHttpMethodSelect').val(),
@@ -1235,6 +1238,7 @@ function dict2CameraUi(dict) {
     $('#smtpAccountEntry').val(dict['email_notifications_smtp_account']);
     $('#smtpPasswordEntry').val(dict['email_notifications_smtp_password']);
     $('#smtpTlsSwitch')[0].checked = dict['email_notifications_smtp_tls'];
+    $('#emailPictureTimeSpan').val(dict['email_notifications_picture_time_span']);
     $('#webHookNotificationsSwitch')[0].checked = dict['web_hook_notifications_enabled'];
     $('#webHookUrlEntry').val(dict['web_hook_notifications_url']);
     $('#webHookHttpMethodSelect').val(dict['web_hook_notifications_http_method']);
index 3a24ecb4f37a8ea03a380f8e8523e41b4394668c..0d5a47aee8a1a55fef743850117a0161022bc189 100644 (file)
                         <td class="settings-item-value"><input type="checkbox" class="styled notifications" id="smtpTlsSwitch"></td>
                         <td><span class="help-mark" title="enable this if your SMTP server requires TLS (Gmail needs this to be enabled)">?</span></td>
                     </tr>
+                    <tr class="settings-item advanced-setting">
+                        <td class="settings-item-label"><span class="settings-item-label">Attached Pictures Time Span</span></td>
+                        <td class="settings-item-value"><input type="text" class="number styled notifications" id="emailPictureTimeSpan"><span class="settings-item-unit">seconds</span></td>
+                        <td><span class="help-mark" title="defines the picture search time interval to use when creating email attachments (higher values generate emails with more pictures at the cost of an increased notification delay)">?</span></td>
+                    </tr>
                     <tr class="settings-item advanced-setting">
                         <td colspan="100"><div class="settings-item-separator"></div></td>
                     </tr>