added ability to save_video_to_file, deployed as 0.0.22
parent
9706e5d559
commit
cad32f0e8f
|
@ -1,5 +1,5 @@
|
||||||
""" Python client for Eagle Eye Networks APIv3 """
|
""" Python client for Eagle Eye Networks APIv3 """
|
||||||
version = "0.0.21"
|
version = "0.0.22"
|
||||||
__version__ = version
|
__version__ = version
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +72,8 @@ class EagleEyev3():
|
||||||
'logout': (5, 15),
|
'logout': (5, 15),
|
||||||
'list_of_events': (6, 20),
|
'list_of_events': (6, 20),
|
||||||
'live_preview': (3, 5),
|
'live_preview': (3, 5),
|
||||||
'switch_account': (5, 30)
|
'switch_account': (5, 30),
|
||||||
|
'recorded_video': (20, 200) # giving it the best possible chance to succeed
|
||||||
}
|
}
|
||||||
|
|
||||||
def _load_vars_from_settings(self, config={}):
|
def _load_vars_from_settings(self, config={}):
|
||||||
|
@ -1066,3 +1067,53 @@ class Camera(Device):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def save_video_to_file(self, url=None, filename=None):
|
||||||
|
|
||||||
|
success = False
|
||||||
|
status_code = None
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
if url == None or filename == None:
|
||||||
|
logging.warn("save_video_to_file called without url and/or filename")
|
||||||
|
|
||||||
|
data = { 'message': 'save_video_to_file called without url and/or filename' }
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": success,
|
||||||
|
"response_http_status": status_code,
|
||||||
|
"data": data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {self.een_instance.access_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with requests.get(url, stream=True, headers=headers, timeout=self.een_instance._get_timeout_values('recorded_video')) as response:
|
||||||
|
logging.info(f"{response.status_code} in save_video_to_file")
|
||||||
|
with open(filename, 'wb') as fname:
|
||||||
|
for chunk in response.iter_content(chunk_size=8192):
|
||||||
|
fname.write(chunk)
|
||||||
|
|
||||||
|
success = True
|
||||||
|
data = { 'message': f"video saved as {fname}" }
|
||||||
|
|
||||||
|
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
logging.warn(f"timeout expired for {url} save_video_to_file")
|
||||||
|
data = { 'message': f"timeout expired for {url} save_video_to_file" }
|
||||||
|
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
logging.warn(e)
|
||||||
|
data = { 'message': "Exception {e} in save_video_to_file" }
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": success,
|
||||||
|
"response_http_status": status_code,
|
||||||
|
"data": data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue