1+ from typing import Optional
2+ from videodb ._utils ._video import play_stream
13from videodb ._constants import (
24 ApiPath ,
35 SearchType ,
68)
79from videodb .search import SearchFactory , SearchResult
810from videodb .shot import Shot
9- from typing import Optional
1011
1112
1213class Video :
1314 def __init__ (self , _connection , id : str , collection_id : str , ** kwargs ) -> None :
1415 self ._connection = _connection
1516 self .id = id
1617 self .collection_id = collection_id
17- self .stream_link = kwargs .get ("stream_link" , None )
18+ self .stream_url = kwargs .get ("stream_url" , None )
19+ self .player_url = kwargs .get ("player_url" , None )
1820 self .name = kwargs .get ("name" , None )
1921 self .description = kwargs .get ("description" , None )
20- self .thumbnail = kwargs .get ("thumbnail " , None )
22+ self .thumbnail_url = kwargs .get ("thumbnail_url " , None )
2123 self .length = float (kwargs .get ("length" , 0.0 ))
2224 self .transcript = kwargs .get ("transcript" , None )
2325 self .transcript_text = kwargs .get ("transcript_text" , None )
@@ -27,10 +29,11 @@ def __repr__(self) -> str:
2729 f"Video("
2830 f"id={ self .id } , "
2931 f"collection_id={ self .collection_id } , "
30- f"stream_link={ self .stream_link } , "
32+ f"stream_url={ self .stream_url } , "
33+ f"player_url={ self .player_url } , "
3134 f"name={ self .name } , "
3235 f"description={ self .description } , "
33- f"thumbnail ={ self .thumbnail } , "
36+ f"thumbnail_url ={ self .thumbnail_url } , "
3437 f"length={ self .length } )"
3538 )
3639
@@ -63,16 +66,16 @@ def delete(self) -> None:
6366 """
6467 self ._connection .delete (path = f"{ ApiPath .video } /{ self .id } " )
6568
66- def get_stream (self , timeline : Optional [list [tuple [int , int ]]] = None ) -> str :
67- """Get the stream link of the video
69+ def generate_stream (self , timeline : Optional [list [tuple [int , int ]]] = None ) -> str :
70+ """Generate the stream url of the video
6871
6972 :param list timeline: The timeline of the video to be streamed. Defaults to None.
7073 :raises InvalidRequestError: If the get_stream fails
71- :return: The stream link of the video
74+ :return: The stream url of the video
7275 :rtype: str
7376 """
74- if not timeline and self .stream_link :
75- return self .stream_link
77+ if not timeline and self .stream_url :
78+ return self .stream_url
7679
7780 stream_data = self ._connection .post (
7881 path = f"{ ApiPath .video } /{ self .id } /{ ApiPath .stream } " ,
@@ -81,16 +84,16 @@ def get_stream(self, timeline: Optional[list[tuple[int, int]]] = None) -> str:
8184 "length" : self .length ,
8285 },
8386 )
84- return stream_data .get ("stream_link" )
87+ return stream_data .get ("stream_url" , None )
8588
86- def get_thumbnail (self ):
87- if self .thumbnail :
88- return self .thumbnail
89+ def generate_thumbnail (self ):
90+ if self .thumbnail_url :
91+ return self .thumbnail_url
8992 thumbnail_data = self ._connection .get (
9093 path = f"{ ApiPath .video } /{ self .id } /{ ApiPath .thumbnail } "
9194 )
92- self .thumbnail = thumbnail_data .get ("thumbnail " )
93- return self .thumbnail
95+ self .thumbnail_url = thumbnail_data .get ("thumbnail_url " )
96+ return self .thumbnail_url
9497
9598 def _fetch_transcript (self , force : bool = False ) -> None :
9699 if self .transcript and not force :
@@ -111,7 +114,7 @@ def get_transcript_text(self, force: bool = False) -> str:
111114 return self .transcript_text
112115
113116 def index_spoken_words (self ) -> None :
114- """Symantic indexing of spoken words in the video
117+ """Semantic indexing of spoken words in the video
115118
116119 :raises InvalidRequestError: If the video is already indexed
117120 :return: None if the indexing is successful
@@ -132,15 +135,15 @@ def add_subtitle(self) -> str:
132135 "type" : Workflows .add_subtitles ,
133136 },
134137 )
135- return subtitle_data .get ("stream_link" )
138+ return subtitle_data .get ("stream_url" , None )
136139
137140 def insert_video (self , video , timestamp : float ) -> str :
138141 """Insert a video into another video
139142
140143 :param Video video: The video to be inserted
141144 :param float timestamp: The timestamp where the video should be inserted
142145 :raises InvalidRequestError: If the insert fails
143- :return: The stream link of the inserted video
146+ :return: The stream url of the inserted video
144147 :rtype: str
145148 """
146149 if timestamp > float (self .length ):
@@ -171,5 +174,12 @@ def insert_video(self, video, timestamp: float) -> str:
171174 for shot in all_shots
172175 ],
173176 )
174- stream_link = compile_data .get ("stream_link" )
175- return stream_link
177+ return compile_data .get ("stream_url" , None )
178+
179+ def play (self ) -> str :
180+ """Open the player url in the browser/iframe and return the stream url
181+
182+ :return: The stream url
183+ :rtype: str
184+ """
185+ return play_stream (self .stream_url )
0 commit comments