WIP barely working but want to get some other people testing it
parent
5c9018b09b
commit
e4326d5879
|
@ -1,5 +1,5 @@
|
||||||
""" Python client for Eagle Eye Networks APIv3 """
|
""" Python client for Eagle Eye Networks APIv3 """
|
||||||
version = "0.0.15"
|
version = "0.0.16"
|
||||||
__version__ = version
|
__version__ = version
|
||||||
|
|
||||||
|
|
||||||
|
@ -876,7 +876,7 @@ class Camera(Device):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if start_timestamp == None or end_timestamp == None:
|
if start_timestamp == None or end_timestamp == None:
|
||||||
logging.debug(f"get_list_of_events called without timestamp")
|
logging.warn(f"get_list_of_events called without timestamp")
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"response_http_status": None,
|
"response_http_status": None,
|
||||||
|
@ -970,3 +970,89 @@ class Camera(Device):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_list_of_videos(self, start_timestamp=None, end_timestamp=None, stream_type='main', media_type='video', coalesce='true', include=['mp4Url']):
|
||||||
|
"""
|
||||||
|
Obtains the list of videos.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Dictionary containing the success status, response HTTP status code, and data.
|
||||||
|
"""
|
||||||
|
nextPageToken = None
|
||||||
|
include_str = ','.join(include)
|
||||||
|
|
||||||
|
if start_timestamp == None or end_timestamp == None:
|
||||||
|
logging.warn(f"get_list_of_videos called without timestamps")
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"response_http_status": None,
|
||||||
|
"data": { 'msg': 'get_list_of_videos called without required args, needs start_timestamp, end_timestamp' }
|
||||||
|
}
|
||||||
|
|
||||||
|
# emulating a do while toop in order to handle pagination, remember to break out of this loop
|
||||||
|
while True:
|
||||||
|
|
||||||
|
if nextPageToken:
|
||||||
|
url = f"https://{self.user_base_url}/api/v3.0/media?deviceId={self.id}&type={stream_type}&mediaType={media_type}&startTimestamp__gte={start_timestamp}&coalesce={coalesce}&include={include_str}&pageToken={nextPageToken}"
|
||||||
|
else:
|
||||||
|
url = f"https://{self.user_base_url}/api/v3.0/media?deviceId={self.id}&type={stream_type}&mediaType={media_type}&startTimestamp__gte={start_timestamp}&coalesce={coalesce}&include={include_str}"
|
||||||
|
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"Bearer {self.een_instance.access_token}",
|
||||||
|
"Accept": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.een_instance._make_get_request(url=url, headers=headers, timeout='list_of_videos')
|
||||||
|
|
||||||
|
if response:
|
||||||
|
response_json = response.json()
|
||||||
|
|
||||||
|
logging.info(f"{response.status_code} in get_list_of_videos")
|
||||||
|
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"response_http_status": 0,
|
||||||
|
"data": None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
success = True
|
||||||
|
self.videos = [i for i in response_json['results'] if i['startTimestamp'] not in [j['startTimestamp'] for j in self.videos]] + self.videos
|
||||||
|
|
||||||
|
# sort by event startTimestamp descending
|
||||||
|
self.videos = sorted(self.videos, key=lambda x: x['startTimestamp'], reverse=True)
|
||||||
|
|
||||||
|
if 'nextPageToken' in response_json and len(response_json['nextPageToken']) > 0:
|
||||||
|
nextPageToken = response_json['nextPageToken']
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
success = False
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
dups = {}
|
||||||
|
for video in self.videos:
|
||||||
|
if video['endTimestamp'] in dups:
|
||||||
|
dups[video['endTimestamp']] = dups[video['endTimestamp']] + 1
|
||||||
|
logging.debug(f"found duplicate endTimestamp: { video['endTimestamp'] }")
|
||||||
|
else:
|
||||||
|
dups[video['endTimestamp']] = 1
|
||||||
|
|
||||||
|
logging.debug(dups)
|
||||||
|
|
||||||
|
self.videos = [i for i in self.videos if dups[i['endTimestamp']] == 1]
|
||||||
|
self.videos = sorted(self.videos, key=lambda x: x['startTimestamp'], reverse=True)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": success,
|
||||||
|
"response_http_status": response.status_code,
|
||||||
|
"data": self.videos
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue