1+ import webbrowser as web
12from videodb ._constants import (
23 ApiPath ,
34 SearchType ,
@@ -14,10 +15,11 @@ 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_link" , None )
19+ self .player_url = kwargs .get ("player_link" , 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" , 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,18 @@ 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+ self .stream_url = stream_data .get ("stream_link" )
88+ self .player_url = stream_data .get ("player_link" )
89+ return self .stream_url
8590
86- def get_thumbnail (self ):
87- if self .thumbnail :
88- return self .thumbnail
91+ def generate_thumbnail (self ):
92+ if self .thumbnail_url :
93+ return self .thumbnail_url
8994 thumbnail_data = self ._connection .get (
9095 path = f"{ ApiPath .video } /{ self .id } /{ ApiPath .thumbnail } "
9196 )
92- self .thumbnail = thumbnail_data .get ("thumbnail" )
93- return self .thumbnail
97+ self .thumbnail_url = thumbnail_data .get ("thumbnail" )
98+ return self .thumbnail_url
9499
95100 def _fetch_transcript (self , force : bool = False ) -> None :
96101 if self .transcript and not force :
@@ -132,15 +137,17 @@ def add_subtitle(self) -> str:
132137 "type" : Workflows .add_subtitles ,
133138 },
134139 )
135- return subtitle_data .get ("stream_link" )
140+ self .stream_url = subtitle_data .get ("stream_link" )
141+ self .player_url = subtitle_data .get ("player_link" )
142+ return self .stream_url
136143
137144 def insert_video (self , video , timestamp : float ) -> str :
138145 """Insert a video into another video
139146
140147 :param Video video: The video to be inserted
141148 :param float timestamp: The timestamp where the video should be inserted
142149 :raises InvalidRequestError: If the insert fails
143- :return: The stream link of the inserted video
150+ :return: The stream url of the inserted video
144151 :rtype: str
145152 """
146153 if timestamp > float (self .length ):
@@ -171,5 +178,16 @@ def insert_video(self, video, timestamp: float) -> str:
171178 for shot in all_shots
172179 ],
173180 )
174- stream_link = compile_data .get ("stream_link" )
175- return stream_link
181+ self .stream_url = compile_data .get ("stream_link" )
182+ self .player_url = compile_data .get ("player_link" )
183+ return self .stream_url
184+
185+ def play (self ) -> str :
186+ """Generate a stream url for the shot and open it in the default browser
187+
188+ :return: The stream url
189+ :rtype: str
190+ """
191+ self .generate_stream ()
192+ web .open (self .player_url )
193+ return self .player_url
0 commit comments