Skip to content

Commit

Permalink
python(feat): Add timestamp arg to VideoMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
marcsiftstack committed Oct 30, 2024
1 parent bb0736b commit c403dc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/lib/sift_py/file_attachment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" ,
)
Expand Down
20 changes: 18 additions & 2 deletions python/lib/sift_py/file_attachment/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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
Expand All @@ -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,
}


Expand Down

0 comments on commit c403dc7

Please sign in to comment.