async def make_timelapse_movie(local_config, framerate, interval, group) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) msg = 'making timelapse movie for group "%(group)s" of remote camera %(id)s ' \ 'with rate %(framerate)s/%(int)s on %(url)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'framerate': framerate, 'int': interval, 'url': pretty_camera_url(local_config)} logging.debug(msg) path += '/picture/%(id)s/timelapse/%(group)s/?interval=%(int)s&framerate=%(framerate)s' % { 'id': camera_id, 'int': interval, 'framerate': framerate, 'group': group } request = _make_request(scheme, host, port, username, password, path, timeout=100 * settings.REMOTE_REQUEST_TIMEOUT) response = await _send_request(request) if response.error: msg = 'failed to make timelapse movie for group "%(group)s" of remote camera %(id)s ' \ 'with rate %(framerate)s/%(int)s on %(url)s: %(msg)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config), 'int': interval, 'framerate': framerate, 'msg': utils.pretty_http_error(response)} logging.error(msg) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error('failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': str(e) }) return utils.CommonExternalResponse(error=str(e)) else: return utils.CommonExternalResponse(result=response)
async def make_zipped_content(local_config, media_type, group) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'preparing zip file for group "%(group)s" of remote camera %(id)s on %(url)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config) }) prepare_path = path + '/%(media_type)s/%(id)s/zipped/%(group)s/' % { 'media_type': media_type, 'id': camera_id, 'group': group } # timeout here is 100 times larger than usual - we expect a big delay request = _make_request(scheme, host, port, username, password, prepare_path, timeout=100 * settings.REMOTE_REQUEST_TIMEOUT) response = await _send_request(request) if response.error: msg = 'failed to prepare zip file for group "%(group)s" ' \ 'of remote camera %(id)s on %(url)s: %(msg)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response)} logging.error(msg) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) try: key = json.loads(response.body)['key'] except Exception as e: logging.error('failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': str(e) }) return utils.CommonExternalResponse(error=str(e)) else: return utils.CommonExternalResponse(result={'key': key})
async def get_media_preview(local_config, filename, media_type, width, height) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'getting file preview for %(filename)s of remote camera %(id)s on %(url)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/%(media_type)s/%(id)s/preview/%(filename)s' % { 'media_type': media_type, 'id': camera_id, 'filename': filename } query = {} if width: query['width'] = str(width) if height: query['height'] = str(height) request = _make_request(scheme, host, port, username, password, path, query=query) response = await _send_request(request) if response.error: logging.error( 'failed to get file preview for %(filename)s of remote camera %(id)s on %(url)s: %(msg)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) return utils.CommonExternalResponse(result=response.body)
async def check_timelapse_movie(local_config, group) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'checking timelapse movie status for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) p = path + '/picture/%(id)s/timelapse/%(group)s/?check=true' % { 'id': camera_id, 'group': group } request = _make_request(scheme, host, port, username, password, p) response = await _send_request(request) if response.error: logging.error( 'failed to check timelapse movie status for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) try: response = json.loads(response.body) except Exception as e: logging.error('failed to decode json answer from %(url)s: %(msg)s' % { 'url': pretty_camera_url(local_config), 'msg': str(e) }) return utils.CommonExternalResponse(error=str(e)) else: return utils.CommonExternalResponse(result=response)
async def get_zipped_content(local_config, media_type, key, group) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug('downloading zip file for remote camera %(id)s on %(url)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config) }) p = path + '/%(media_type)s/%(id)s/zipped/%(group)s/?key=%(key)s' % { 'media_type': media_type, 'group': group, 'id': camera_id, 'key': key } request = _make_request(scheme, host, port, username, password, p, timeout=10 * settings.REMOTE_REQUEST_TIMEOUT) response = await _send_request(request) if response.error: logging.error( 'failed to download zip file for remote camera %(id)s on %(url)s: %(msg)s' % { 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) return utils.CommonExternalResponse( result={ 'data': response.body, 'content_type': response.headers.get('Content-Type'), 'content_disposition': response.headers.get('Content-Disposition') })
async def del_media_group(local_config, group, media_type) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'deleting group "%(group)s" of remote camera %(id)s on %(url)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/%(media_type)s/%(id)s/delete_all/%(group)s/' % { 'media_type': media_type, 'id': camera_id, 'group': group } request = _make_request(scheme, host, port, username, password, path, method='POST', data='{}', timeout=settings.REMOTE_REQUEST_TIMEOUT, content_type='application/json') response = await _send_request(request) if response.error: logging.error( 'failed to delete group "%(group)s" of remote camera %(id)s on %(url)s: %(msg)s' % { 'group': group or 'ungrouped', 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) return utils.CommonExternalResponse()
async def get_media_content(local_config, filename, media_type) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'downloading file %(filename)s of remote camera %(id)s on %(url)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/%(media_type)s/%(id)s/download/%(filename)s' % { 'media_type': media_type, 'id': camera_id, 'filename': filename } # timeout here is 10 times larger than usual - we expect a big delay when fetching the media list request = _make_request(scheme, host, port, username, password, path, timeout=10 * settings.REMOTE_REQUEST_TIMEOUT) response = await _send_request(request) if response.error: logging.error( 'failed to download file %(filename)s of remote camera %(id)s on %(url)s: %(msg)s' % { 'filename': filename, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) return utils.CommonExternalResponse(result=response.body)
async def exec_action(local_config, action) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) logging.debug( 'executing action "%(action)s" of remote camera %(id)s on %(url)s' % { 'action': action, 'id': camera_id, 'url': pretty_camera_url(local_config) }) path += '/action/%(id)s/%(action)s/' % {'action': action, 'id': camera_id} request = _make_request(scheme, host, port, username, password, path, method='POST', data='{}', timeout=settings.REMOTE_REQUEST_TIMEOUT, content_type='application/json') response = await _send_request(request) if response.error: logging.error( 'failed to execute action "%(action)s" of remote camera %(id)s on %(url)s: %(msg)s' % { 'action': action, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( error=utils.pretty_http_error(response)) return utils.CommonExternalResponse()
async def test(local_config, data) -> utils.CommonExternalResponse: scheme, host, port, username, password, path, camera_id = _remote_params( local_config) what = data['what'] logging.debug('testing %(what)s on remote camera %(id)s, on %(url)s' % { 'what': what, 'id': camera_id, 'url': pretty_camera_url(local_config) }) data = json.dumps(data) p = path + '/config/%(id)s/test/' % {'id': camera_id} request = _make_request(scheme, host, port, username, password, p, method='POST', data=data, content_type='application/json') response = await _send_request(request) if response.error: logging.error( 'failed to test %(what)s on remote camera %(id)s, on %(url)s: %(msg)s' % { 'what': what, 'id': camera_id, 'url': pretty_camera_url(local_config), 'msg': utils.pretty_http_error(response) }) return utils.CommonExternalResponse( None, error=utils.pretty_http_error(response)) return utils.CommonExternalResponse( None, None) # it will never return result = True, what the point?