Skip to content

Commit a8366de

Browse files
authored
Merge pull request video-db#31 from video-db/ankit/add-public-collection
feat: add public collection
2 parents 6b76849 + d26bd5c commit a8366de

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
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.8"
4+
__version__ = "0.2.9"
55
__title__ = "videodb"
66
__author__ = "videodb"
77
__email__ = "[email protected]"

videodb/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def get_collection(self, collection_id: Optional[str] = "default") -> Collection
3838
self.collection_id,
3939
collection_data.get("name"),
4040
collection_data.get("description"),
41+
collection_data.get("is_public", False),
4142
)
4243

4344
def get_collections(self) -> List[Collection]:
@@ -48,6 +49,7 @@ def get_collections(self) -> List[Collection]:
4849
collection.get("id"),
4950
collection.get("name"),
5051
collection.get("description"),
52+
collection.get("is_public", False),
5153
)
5254
for collection in collections_data.get("collections")
5355
]
@@ -66,6 +68,7 @@ def create_collection(self, name: str, description: str) -> Collection:
6668
collection_data.get("id"),
6769
collection_data.get("name"),
6870
collection_data.get("description"),
71+
collection_data.get("is_public", False),
6972
)
7073

7174
def update_collection(self, id: str, name: str, description: str) -> Collection:
@@ -82,6 +85,7 @@ def update_collection(self, id: str, name: str, description: str) -> Collection:
8285
collection_data.get("id"),
8386
collection_data.get("name"),
8487
collection_data.get("description"),
88+
collection_data.get("is_public", False),
8589
)
8690

8791
def check_usage(self) -> dict:

videodb/collection.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,27 @@
2424

2525

2626
class Collection:
27-
def __init__(self, _connection, id: str, name: str = None, description: str = None):
27+
def __init__(
28+
self,
29+
_connection,
30+
id: str,
31+
name: str = None,
32+
description: str = None,
33+
is_public: bool = False,
34+
):
2835
self._connection = _connection
2936
self.id = id
3037
self.name = name
3138
self.description = description
39+
self.is_public = is_public
3240

3341
def __repr__(self) -> str:
3442
return (
3543
f"Collection("
3644
f"id={self.id}, "
3745
f"name={self.name}, "
38-
f"description={self.description})"
46+
f"description={self.description}), "
47+
f"is_public={self.is_public})"
3948
)
4049

4150
def delete(self) -> None:
@@ -168,3 +177,15 @@ def upload(
168177
return Audio(self._connection, **upload_data)
169178
elif media_id.startswith("img-"):
170179
return Image(self._connection, **upload_data)
180+
181+
def make_public(self):
182+
self._connection.patch(
183+
path=f"{ApiPath.collection}/{self.id}", data={"is_public": True}
184+
)
185+
self.is_public = True
186+
187+
def make_private(self):
188+
self._connection.patch(
189+
path=f"{ApiPath.collection}/{self.id}", data={"is_public": False}
190+
)
191+
self.is_public = False

videodb/video.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,17 @@ def get_scene_collection(self, collection_id: str) -> Optional[SceneCollection]:
277277
if not collection_id:
278278
raise ValueError("collection_id is required")
279279
scenes_data = self._connection.get(
280-
path=f"{ApiPath.video}/{self.id}/{ApiPath.scenes}/{collection_id}"
280+
path=f"{ApiPath.video}/{self.id}/{ApiPath.scenes}/{collection_id}",
281+
params={"collection_id": self.collection_id},
281282
)
282283
if not scenes_data:
283284
return None
284285
return self._format_scene_collection(scenes_data.get("scene_collection"))
285286

286287
def list_scene_collection(self):
287288
scene_collections_data = self._connection.get(
288-
path=f"{ApiPath.video}/{self.id}/{ApiPath.scenes}"
289+
path=f"{ApiPath.video}/{self.id}/{ApiPath.scenes}",
290+
params={"collection_id": self.collection_id},
289291
)
290292
return scene_collections_data.get("scene_collections", [])
291293

@@ -328,13 +330,15 @@ def index_scenes(
328330

329331
def list_scene_index(self) -> List:
330332
index_data = self._connection.get(
331-
path=f"{ApiPath.video}/{self.id}/{ApiPath.index}/{ApiPath.scene}"
333+
path=f"{ApiPath.video}/{self.id}/{ApiPath.index}/{ApiPath.scene}",
334+
params={"collection_id": self.collection_id},
332335
)
333336
return index_data.get("scene_indexes", [])
334337

335338
def get_scene_index(self, scene_index_id: str) -> Optional[List]:
336339
index_data = self._connection.get(
337-
path=f"{ApiPath.video}/{self.id}/{ApiPath.index}/{ApiPath.scene}/{scene_index_id}"
340+
path=f"{ApiPath.video}/{self.id}/{ApiPath.index}/{ApiPath.scene}/{scene_index_id}",
341+
params={"collection_id": self.collection_id},
338342
)
339343
if not index_data:
340344
return None

0 commit comments

Comments
 (0)