Skip to content

Commit 48ee29d

Browse files
authored
Merge pull request #43 from video-db/ankit/add-rtstream
feat: add rtstream
2 parents d185e9a + 3a2b8fa commit 48ee29d

File tree

5 files changed

+378
-1
lines changed

5 files changed

+378
-1
lines changed

videodb/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" About information for videodb sdk"""
22

33

4-
__version__ = "0.2.13"
4+
__version__ = "0.2.14"
55
__title__ = "videodb"
66
__author__ = "videodb"
77
__email__ = "[email protected]"

videodb/_constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class ApiPath:
7171
storage = "storage"
7272
download = "download"
7373
title = "title"
74+
rtstream = "rtstream"
75+
status = "status"
76+
event = "event"
77+
alert = "alert"
7478
generate_url = "generate_url"
7579
generate = "generate"
7680
web = "web"

videodb/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ def get_invoices(self) -> List[dict]:
147147
"""
148148
return self.get(path=f"{ApiPath.billing}/{ApiPath.invoices}")
149149

150+
def create_event(self, event_prompt: str, label: str):
151+
"""Create an rtstream event.
152+
153+
:param str event_prompt: Prompt for the event
154+
:param str label: Label for the event
155+
:return: Event ID
156+
:rtype: str
157+
"""
158+
event_data = self.post(
159+
f"{ApiPath.rtstream}/{ApiPath.event}",
160+
data={"event_prompt": event_prompt, "label": label},
161+
)
162+
163+
return event_data.get("event_id")
164+
165+
def list_events(self):
166+
"""List all rtstream events.
167+
168+
:return: List of events
169+
:rtype: list[dict]
170+
"""
171+
event_data = self.get(f"{ApiPath.rtstream}/{ApiPath.event}")
172+
return event_data.get("events", [])
173+
150174
def download(self, stream_link: str, name: str) -> dict:
151175
"""Download a file from a stream link.
152176

videodb/collection.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from videodb.video import Video
1313
from videodb.audio import Audio
1414
from videodb.image import Image
15+
from videodb.rtstream import RTStream
1516
from videodb.search import SearchFactory, SearchResult
1617

1718
logger = logging.getLogger(__name__)
@@ -164,6 +165,53 @@ def delete_image(self, image_id: str) -> None:
164165
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
165166
)
166167

168+
def connect_rtstream(
169+
self, url: str, name: str, sample_rate: int = None
170+
) -> RTStream:
171+
"""Connect to an rtstream.
172+
173+
:param str url: URL of the rtstream
174+
:param str name: Name of the rtstream
175+
:param int sample_rate: Sample rate of the rtstream (optional)
176+
:return: :class:`RTStream <RTStream>` object
177+
"""
178+
rtstream_data = self._connection.post(
179+
path=f"{ApiPath.rtstream}",
180+
data={
181+
"collection_id": self.id,
182+
"url": url,
183+
"name": name,
184+
"sample_rate": sample_rate,
185+
},
186+
)
187+
return RTStream(self._connection, **rtstream_data)
188+
189+
def get_rtstream(self, id: str) -> RTStream:
190+
"""Get an rtstream by its ID.
191+
192+
:param str id: ID of the rtstream
193+
:return: :class:`RTStream <RTStream>` object
194+
:rtype: :class:`videodb.rtstream.RTStream`
195+
"""
196+
rtstream_data = self._connection.get(
197+
path=f"{ApiPath.rtstream}/{id}",
198+
)
199+
return RTStream(self._connection, **rtstream_data)
200+
201+
def list_rtstreams(self) -> List[RTStream]:
202+
"""List all rtstreams in the collection.
203+
204+
:return: List of :class:`RTStream <RTStream>` objects
205+
:rtype: List[:class:`videodb.rtstream.RTStream`]
206+
"""
207+
rtstreams_data = self._connection.get(
208+
path=f"{ApiPath.rtstream}",
209+
)
210+
return [
211+
RTStream(self._connection, **rtstream)
212+
for rtstream in rtstreams_data.get("results")
213+
]
214+
167215
def generate_image(
168216
self,
169217
prompt: str,

0 commit comments

Comments
 (0)