2424
2525
2626class Connection (HttpClient ):
27- def __init__ (self , api_key : str , base_url : str ) -> None :
27+ """Connection class to interact with the VideoDB"""
28+
29+ def __init__ (self , api_key : str , base_url : str ) -> "Connection" :
30+ """Initializes a new instance of the Connection class with specified API credentials.
31+
32+ Note: Users should not initialize this class directly.
33+ Instead use :meth:`videodb.connect() <videodb.connect>`
34+
35+ :param str api_key: API key for authentication
36+ :param str base_url: Base URL of the VideoDB API
37+ :raise ValueError: If the API key is not provided
38+ :return: :class:`Connection <Connection>` object, to interact with the VideoDB
39+ :rtype: :class:`videodb.client.Connection`
40+ """
2841 self .api_key = api_key
2942 self .base_url = base_url
3043 self .collection_id = "default"
3144 super ().__init__ (api_key = api_key , base_url = base_url , version = __version__ )
3245
3346 def get_collection (self , collection_id : Optional [str ] = "default" ) -> Collection :
47+ """Get a collection object by its ID.
48+
49+ :param str collection_id: ID of the collection (optional, default: "default")
50+ :return: :class:`Collection <Collection>` object
51+ :rtype: :class:`videodb.collection.Collection`
52+ """
3453 collection_data = self .get (path = f"{ ApiPath .collection } /{ collection_id } " )
3554 self .collection_id = collection_data .get ("id" , "default" )
3655 return Collection (
3756 self ,
3857 self .collection_id ,
3958 collection_data .get ("name" ),
4059 collection_data .get ("description" ),
60+ collection_data .get ("is_public" , False ),
4161 )
4262
4363 def get_collections (self ) -> List [Collection ]:
64+ """Get a list of all collections.
65+
66+ :return: List of :class:`Collection <Collection>` objects
67+ :rtype: list[:class:`videodb.collection.Collection`]
68+ """
4469 collections_data = self .get (path = ApiPath .collection )
4570 return [
4671 Collection (
4772 self ,
4873 collection .get ("id" ),
4974 collection .get ("name" ),
5075 collection .get ("description" ),
76+ collection .get ("is_public" , False ),
5177 )
5278 for collection in collections_data .get ("collections" )
5379 ]
5480
55- def create_collection (self , name : str , description : str ) -> Collection :
81+ def create_collection (
82+ self , name : str , description : str , is_public : bool = False
83+ ) -> Collection :
84+ """Create a new collection.
85+
86+ :param str name: Name of the collection
87+ :param str description: Description of the collection
88+ :param bool is_public: Make collection public (optional, default: False)
89+ :return: :class:`Collection <Collection>` object
90+ :rtype: :class:`videodb.collection.Collection`
91+ """
5692 collection_data = self .post (
5793 path = ApiPath .collection ,
5894 data = {
5995 "name" : name ,
6096 "description" : description ,
97+ "is_public" : is_public ,
6198 },
6299 )
63100 self .collection_id = collection_data .get ("id" , "default" )
@@ -66,9 +103,18 @@ def create_collection(self, name: str, description: str) -> Collection:
66103 collection_data .get ("id" ),
67104 collection_data .get ("name" ),
68105 collection_data .get ("description" ),
106+ collection_data .get ("is_public" , False ),
69107 )
70108
71109 def update_collection (self , id : str , name : str , description : str ) -> Collection :
110+ """Update an existing collection.
111+
112+ :param str id: ID of the collection
113+ :param str name: Name of the collection
114+ :param str description: Description of the collection
115+ :return: :class:`Collection <Collection>` object
116+ :rtype: :class:`videodb.collection.Collection`
117+ """
72118 collection_data = self .patch (
73119 path = f"{ ApiPath .collection } /{ id } " ,
74120 data = {
@@ -82,12 +128,23 @@ def update_collection(self, id: str, name: str, description: str) -> Collection:
82128 collection_data .get ("id" ),
83129 collection_data .get ("name" ),
84130 collection_data .get ("description" ),
131+ collection_data .get ("is_public" , False ),
85132 )
86133
87134 def check_usage (self ) -> dict :
135+ """Check the usage.
136+
137+ :return: Usage data
138+ :rtype: dict
139+ """
88140 return self .get (path = f"{ ApiPath .billing } /{ ApiPath .usage } " )
89141
90142 def get_invoices (self ) -> List [dict ]:
143+ """Get a list of all invoices.
144+
145+ :return: List of invoices
146+ :rtype: list[dict]
147+ """
91148 return self .get (path = f"{ ApiPath .billing } /{ ApiPath .invoices } " )
92149
93150 def create_event (self , event_prompt : str , label : str ):
@@ -103,6 +160,13 @@ def list_events(self):
103160 return event_data .get ("events" , [])
104161
105162 def download (self , stream_link : str , name : str ) -> dict :
163+ """Download a file from a stream link.
164+
165+ :param stream_link: URL of the stream to download
166+ :param name: Name to save the downloaded file as
167+ :return: Download response data
168+ :rtype: dict
169+ """
106170 return self .post (
107171 path = f"{ ApiPath .download } " ,
108172 data = {
@@ -111,6 +175,31 @@ def download(self, stream_link: str, name: str) -> dict:
111175 },
112176 )
113177
178+ def youtube_search (
179+ self ,
180+ query : str ,
181+ result_threshold : Optional [int ] = 10 ,
182+ duration : str = "medium" ,
183+ ) -> List [dict ]:
184+ """Search for a query on YouTube.
185+
186+ :param str query: Query to search for
187+ :param int result_threshold: Number of results to return (optional)
188+ :param str duration: Duration of the video (optional)
189+ :return: List of YouTube search results
190+ :rtype: List[dict]
191+ """
192+ search_data = self .post (
193+ path = f"{ ApiPath .collection } /{ self .collection_id } /{ ApiPath .search } /{ ApiPath .web } " ,
194+ data = {
195+ "query" : query ,
196+ "result_threshold" : result_threshold ,
197+ "platform" : "youtube" ,
198+ "duration" : duration ,
199+ },
200+ )
201+ return search_data .get ("results" )
202+
114203 def upload (
115204 self ,
116205 file_path : str = None ,
@@ -120,6 +209,17 @@ def upload(
120209 description : Optional [str ] = None ,
121210 callback_url : Optional [str ] = None ,
122211 ) -> Union [Video , Audio , Image , None ]:
212+ """Upload a file.
213+
214+ :param str file_path: Path to the file to upload (optional)
215+ :param str url: URL of the file to upload (optional)
216+ :param MediaType media_type: MediaType object (optional)
217+ :param str name: Name of the file (optional)
218+ :param str description: Description of the file (optional)
219+ :param str callback_url: URL to receive the callback (optional)
220+ :return: :class:`Video <Video>`, or :class:`Audio <Audio>`, or :class:`Image <Image>` object
221+ :rtype: Union[ :class:`videodb.video.Video`, :class:`videodb.audio.Audio`, :class:`videodb.image.Image`]
222+ """
123223 upload_data = upload (
124224 self ,
125225 file_path ,
0 commit comments