Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python(feat): Add timestamp arg to VideoMetadata #110

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
marcsiftstack marked this conversation as resolved.
Show resolved Hide resolved
)

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
Loading