Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add getters for scenevideo and gazedata urls
  • Loading branch information
osode authored and m4reko committed Aug 22, 2022
commit 974b17da9c7c27ed79ccc4bf15cedd12e6bc8374
35 changes: 35 additions & 0 deletions src/g3pylib/recordings/recording.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
from datetime import datetime, timedelta
from typing import List, Optional, cast

import aiohttp

from g3pylib._utils import APIComponent, EndpointKind
from g3pylib.g3typing import URI
from g3pylib.websocket import G3WebSocketClientProtocol
Expand Down Expand Up @@ -159,3 +162,35 @@ async def move(self, folder: str) -> bool:
def uuid(self) -> str:
"""The uuid of the recording."""
return self._uuid

async def get_scenevideo_url(self) -> str:
"""Returns a URL to the recording's video file."""
host_address = self._connection.remote_address[0]
data_url = f"http://{host_address}{await self.get_http_path()}"
async with aiohttp.ClientSession() as session:
async with session.get(data_url) as response:
data = json.loads(await response.text())
try:
scenevideo_file_name = data["scenecamera"]["file"]
except KeyError:
print(
"Could not retrieve file name for recording from recording data."
) # TODO: sufficient error handling?
raise
return f"{data_url}/{scenevideo_file_name}"

async def get_gazedata_url(self) -> str:
"""Returns a URL to the recording's decompressed gaze data file."""
host_address = self._connection.remote_address[0]
data_url = f"http://{host_address}{await self.get_http_path()}"
async with aiohttp.ClientSession() as session:
async with session.get(data_url) as response:
data = json.loads(await response.text())
try:
gaze_file_name = data["gaze"]["file"]
except KeyError:
print(
"Could not retrieve file name for gaze data from recording data."
) # TODO: sufficient error handling?
raise
return f"{data_url}/{gaze_file_name}?use-content-encoding=true"