1+ import json
2+ import logging
13from datetime import datetime , timedelta
24from typing import List , Optional , cast
35
6+ import aiohttp
7+
48from g3pylib ._utils import APIComponent , EndpointKind
9+ from g3pylib .exceptions import InvalidResponseError
510from g3pylib .g3typing import URI
611from g3pylib .websocket import G3WebSocketClientProtocol
712
@@ -12,6 +17,7 @@ def __init__(
1217 ):
1318 self ._connection = connection
1419 self ._uuid = uuid
20+ self .logger : logging .Logger = logging .getLogger (__name__ )
1521 super ().__init__ (URI (f"{ api_base_uri } /{ uuid } " ))
1622
1723 async def get_created (self ) -> datetime :
@@ -159,3 +165,35 @@ async def move(self, folder: str) -> bool:
159165 def uuid (self ) -> str :
160166 """The uuid of the recording."""
161167 return self ._uuid
168+
169+ async def get_scenevideo_url (self ) -> str :
170+ """Returns a URL to the recording's video file."""
171+ host_address = self ._connection .remote_address [0 ]
172+ data_url = f"http://{ host_address } { await self .get_http_path ()} "
173+ async with aiohttp .ClientSession () as session :
174+ async with session .get (data_url ) as response :
175+ data = json .loads (await response .text ())
176+ try :
177+ scenevideo_file_name = data ["scenecamera" ]["file" ]
178+ except KeyError :
179+ self .logger .warning (
180+ f"Could not retrieve file name for recording from recording data collected from { data_url } ."
181+ )
182+ raise InvalidResponseError
183+ return f"{ data_url } /{ scenevideo_file_name } "
184+
185+ async def get_gazedata_url (self ) -> str :
186+ """Returns a URL to the recording's decompressed gaze data file."""
187+ host_address = self ._connection .remote_address [0 ]
188+ data_url = f"http://{ host_address } { await self .get_http_path ()} "
189+ async with aiohttp .ClientSession () as session :
190+ async with session .get (data_url ) as response :
191+ data = json .loads (await response .text ())
192+ try :
193+ gaze_file_name = data ["gaze" ]["file" ]
194+ except KeyError :
195+ self .logger .warning (
196+ f"Could not retrieve file name for gaze data from recording data collected from { data_url } ."
197+ )
198+ raise InvalidResponseError
199+ return f"{ data_url } /{ gaze_file_name } ?use-content-encoding=true"
0 commit comments