diff --git a/python/lib/sift_py/file_attachment/__init__.py b/python/lib/sift_py/file_attachment/__init__.py index 58f5da54..9b889a1e 100644 --- a/python/lib/sift_py/file_attachment/__init__.py +++ b/python/lib/sift_py/file_attachment/__init__.py @@ -63,12 +63,12 @@ entity_type=EntityType.RUN, ) - # uploading the file attachment and attaching it to a run of `run_id` + # uploading the file attachment and attaching it to a run of `run_id`. remote_file = file_attachment_service.upload_attachment( path="path/to/foo.mp4", entity=run, # Metatadata.. optional but recommended for optimal viewing in the application - metadata=VideoMetadata(height=2160, width=3840, duration_seconds=5.5), + metadata=VideoMetadata(height=2160, width=3840, duration_seconds=5.5, timestamp=datetime(2024, 10, 19, 2, 22, 22), description="thrusters getting too hot" , ) diff --git a/python/lib/sift_py/file_attachment/metadata.py b/python/lib/sift_py/file_attachment/metadata.py index fc5a761c..ec64a66c 100644 --- a/python/lib/sift_py/file_attachment/metadata.py +++ b/python/lib/sift_py/file_attachment/metadata.py @@ -5,8 +5,10 @@ from __future__ import annotations -from typing import Any, Type +from datetime import datetime +from typing import Any, Optional, Type +from google.protobuf.timestamp_pb2 import Timestamp from sift.remote_files.v1.remote_files_pb2 import ( ImageMetadata as ImageMetadataPb, ) @@ -30,17 +32,28 @@ class VideoMetadata(AsProtobuf, Metadata): width: int height: int duration_seconds: float + timestamp: Optional[datetime] - def __init__(self, width: int, height: int, duration_seconds: float): + def __init__( + self, width: int, height: int, duration_seconds: float, timestamp: Optional[datetime] = None + ): self.width = width self.height = height self.duration_seconds = duration_seconds + self.timestamp = timestamp def as_pb(self, klass: Type[VideoMetadataPb]) -> VideoMetadataPb: + if self.timestamp is not None: + timestamp_pb = Timestamp() + timestamp_pb.FromDatetime(self.timestamp) + else: + timestamp_pb = None + return klass( width=self.width, height=self.height, duration_seconds=self.duration_seconds, + timestamp=timestamp_pb, ) @classmethod @@ -49,13 +62,16 @@ def from_pb(cls, message: VideoMetadataPb) -> Self: width=message.width, height=message.height, duration_seconds=message.duration_seconds, + timestamp=message.timestamp.ToDateTime(), # type: ignore ) def as_json(self) -> Any: + timestamp = None if self.timestamp is None else self.timestamp.isoformat() return { "height": self.height, "width": self.width, "duration_seconds": self.duration_seconds, + "timestamp": timestamp, }