Skip to content

Commit 2bcd7e3

Browse files
committed
feat: add thumbnail timestamp
1 parent bb5ad25 commit 2bcd7e3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

videodb/_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ApiPath:
3939
image = "image"
4040
stream = "stream"
4141
thumbnail = "thumbnail"
42+
thumbnails = "thumbnails"
4243
upload_url = "upload_url"
4344
transcription = "transcription"
4445
index = "index"

videodb/image.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ def __init__(self, _connection, id: str, collection_id: str, **kwargs) -> None:
99
self.id = id
1010
self.collection_id = collection_id
1111
self.name = kwargs.get("name", None)
12+
self.url = kwargs.get("url", None)
1213

1314
def __repr__(self) -> str:
1415
return (
1516
f"Image("
1617
f"id={self.id}, "
1718
f"collection_id={self.collection_id}, "
18-
f"name={self.name})"
19+
f"name={self.name}), "
20+
f"url={self.url}"
1921
)
2022

2123
def delete(self) -> None:

videodb/video.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
SubtitleStyle,
88
Workflows,
99
)
10+
from videodb.image import Image
1011
from videodb.search import SearchFactory, SearchResult
1112
from videodb.shot import Shot
1213

@@ -88,15 +89,31 @@ def generate_stream(self, timeline: Optional[List[Tuple[int, int]]] = None) -> s
8889
)
8990
return stream_data.get("stream_url", None)
9091

91-
def generate_thumbnail(self):
92-
if self.thumbnail_url:
92+
def generate_thumbnail(self, time: Optional[float] = None) -> Union[str, Image]:
93+
if self.thumbnail_url and not time:
9394
return self.thumbnail_url
95+
96+
if time:
97+
thumbnail_data = self._connection.post(
98+
path=f"{ApiPath.video}/{self.id}/{ApiPath.thumbnail}",
99+
data={
100+
"time": time,
101+
},
102+
)
103+
return Image(self._connection, **thumbnail_data)
104+
94105
thumbnail_data = self._connection.get(
95106
path=f"{ApiPath.video}/{self.id}/{ApiPath.thumbnail}"
96107
)
97108
self.thumbnail_url = thumbnail_data.get("thumbnail_url")
98109
return self.thumbnail_url
99110

111+
def get_thumbnails(self) -> List[Image]:
112+
thumbnails_data = self._connection.get(
113+
path=f"{ApiPath.video}/{self.id}/{ApiPath.thumbnails}"
114+
)
115+
return [Image(self._connection, **thumbnail) for thumbnail in thumbnails_data]
116+
100117
def _fetch_transcript(self, force: bool = False) -> None:
101118
if self.transcript and not force:
102119
return

0 commit comments

Comments
 (0)