From: Calin Crisan Date: Sat, 23 Aug 2014 13:34:30 +0000 (+0300) Subject: various netcam fixes and improvements X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=3fb5a610d32f71b78dd925b25acf0a05b3a83bbe;p=motioneye-debian various netcam fixes and improvements --- diff --git a/src/config.py b/src/config.py index 95c723f..32b9aa0 100644 --- a/src/config.py +++ b/src/config.py @@ -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, '' diff --git a/src/handlers.py b/src/handlers.py index 5f5722f..d36f3d0 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -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] diff --git a/src/utils.py b/src/utils.py index 7c76f03..62d496a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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)