]> www.vanbest.org Git - motioneye-debian/commitdiff
various netcam fixes and improvements
authorCalin Crisan <ccrisan@gmail.com>
Sat, 23 Aug 2014 13:34:30 +0000 (16:34 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 23 Aug 2014 13:34:30 +0000 (16:34 +0300)
src/config.py
src/handlers.py
src/utils.py

index 95c723f1d10c42b47c74028a3e1f9dd7a5554526..32b9aa066af72fde786917ccf38c45ef3f36036a 100644 (file)
@@ -613,7 +613,7 @@ def camera_ui_to_dict(ui):
         data['netcam_url'] += ui['uri']
         
         if ui['username'] or ui['password']:
-            data['necam_userpass'] = (ui['username'] or '') + ':' + (ui['password'] or '')
+            data['netcam_userpass'] = (ui['username'] or '') + ':' + (ui['password'] or '')
 
         data['netcam_http'] = '1.1'
         
@@ -818,6 +818,7 @@ def camera_dict_to_ui(data):
         parts = rest.split('/', 1)
         if len(parts) > 1:
             host_port, uri = parts[:2]
+            uri = '/' + uri
         
         else:
             host_port, uri = rest, ''
index 5f5722f9024bc339ddf3648f0a9e25d1f3765d6a..d36f3d0bea5316219f1bd7073d10d7ea4392ba33 100644 (file)
@@ -551,7 +551,7 @@ class ConfigHandler(BaseHandler):
                 
         else:
             # adjust uri format
-            if device_details['uri'] and device_details['uri'].startswith('/'):
+            if device_details['uri'] and not device_details['uri'].startswith('/'):
                 device_details['uri'] = '/' + device_details['uri']
             while device_details['uri'] and device_details['uri'].endswith('/'):
                 device_details['uri'] = device_details['uri'][:-1]
index 7c76f03182eb14f8ee65c54c3f41cdca2e0ce342..62d496a36d73b5620beefaa33fbe2e810d8cf5a4 100644 (file)
@@ -19,6 +19,10 @@ import datetime
 import logging
 import os
 
+from tornado.httpclient import AsyncHTTPClient, HTTPRequest
+
+import settings
+
 
 def pretty_date_time(date_time, tzinfo=None):
     if date_time is None:
@@ -233,12 +237,35 @@ def test_netcam_url(data, callback):
     
     logging.debug('testing netcam at %s' % url)
     
-    import time
-    time.sleep(1)
+    http_client = AsyncHTTPClient()
     
-    username = data['username']
-    password = data['password']
-
-    # TODO implement me
-    #callback(error='General failure')
-    callback([{'id': 1, 'name': 'Network Camera'}])
+    called = [False]
+    
+    def on_header(header):
+        header = header.lower()
+        if header.startswith('content-type'):
+            content_type = header.split(':')[1].strip()
+            if content_type in ['image/jpg', 'image/jpeg', 'image/pjpg']:
+                callback([{'id': 1, 'name': 'JPEG Network Camera'}])
+            
+            elif content_type.startswith('multipart/x-mixed-replace'):
+                callback([{'id': 1, 'name': 'MJPEG Network Camera'}])
+            
+            else:
+                callback(error='not a network camera')
+            
+            called[0] = True
+
+    def on_response(response):
+        if not called[0]:
+            called[0] = True
+            callback(error=unicode(response.error) if response.error else 'not a network camera')
+    
+    username = data['username'] or None
+    password = data['password'] or None
+    
+    request = HTTPRequest(url, auth_username=username, auth_password=password,
+            connect_timeout=settings.REMOTE_REQUEST_TIMEOUT, request_timeout=settings.REMOTE_REQUEST_TIMEOUT,
+            header_callback=on_header)
+    
+    http_client.fetch(request, on_response)