1
+ import webbrowser as web
1
2
from videodb ._constants import (
2
3
ApiPath ,
3
4
SearchType ,
@@ -14,10 +15,11 @@ def __init__(self, _connection, id: str, collection_id: str, **kwargs) -> None:
14
15
self ._connection = _connection
15
16
self .id = id
16
17
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 )
18
20
self .name = kwargs .get ("name" , None )
19
21
self .description = kwargs .get ("description" , None )
20
- self .thumbnail = kwargs .get ("thumbnail" , None )
22
+ self .thumbnail_url = kwargs .get ("thumbnail" , None )
21
23
self .length = float (kwargs .get ("length" , 0.0 ))
22
24
self .transcript = kwargs .get ("transcript" , None )
23
25
self .transcript_text = kwargs .get ("transcript_text" , None )
@@ -27,10 +29,11 @@ def __repr__(self) -> str:
27
29
f"Video("
28
30
f"id={ self .id } , "
29
31
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 } , "
31
34
f"name={ self .name } , "
32
35
f"description={ self .description } , "
33
- f"thumbnail ={ self .thumbnail } , "
36
+ f"thumbnail_url ={ self .thumbnail_url } , "
34
37
f"length={ self .length } )"
35
38
)
36
39
@@ -63,16 +66,16 @@ def delete(self) -> None:
63
66
"""
64
67
self ._connection .delete (path = f"{ ApiPath .video } /{ self .id } " )
65
68
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
68
71
69
72
:param list timeline: The timeline of the video to be streamed. Defaults to None.
70
73
:raises InvalidRequestError: If the get_stream fails
71
- :return: The stream link of the video
74
+ :return: The stream url of the video
72
75
:rtype: str
73
76
"""
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
76
79
77
80
stream_data = self ._connection .post (
78
81
path = f"{ ApiPath .video } /{ self .id } /{ ApiPath .stream } " ,
@@ -81,16 +84,18 @@ def get_stream(self, timeline: Optional[list[tuple[int, int]]] = None) -> str:
81
84
"length" : self .length ,
82
85
},
83
86
)
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
85
90
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
89
94
thumbnail_data = self ._connection .get (
90
95
path = f"{ ApiPath .video } /{ self .id } /{ ApiPath .thumbnail } "
91
96
)
92
- self .thumbnail = thumbnail_data .get ("thumbnail" )
93
- return self .thumbnail
97
+ self .thumbnail_url = thumbnail_data .get ("thumbnail" )
98
+ return self .thumbnail_url
94
99
95
100
def _fetch_transcript (self , force : bool = False ) -> None :
96
101
if self .transcript and not force :
@@ -132,15 +137,17 @@ def add_subtitle(self) -> str:
132
137
"type" : Workflows .add_subtitles ,
133
138
},
134
139
)
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
136
143
137
144
def insert_video (self , video , timestamp : float ) -> str :
138
145
"""Insert a video into another video
139
146
140
147
:param Video video: The video to be inserted
141
148
:param float timestamp: The timestamp where the video should be inserted
142
149
:raises InvalidRequestError: If the insert fails
143
- :return: The stream link of the inserted video
150
+ :return: The stream url of the inserted video
144
151
:rtype: str
145
152
"""
146
153
if timestamp > float (self .length ):
@@ -171,5 +178,16 @@ def insert_video(self, video, timestamp: float) -> str:
171
178
for shot in all_shots
172
179
],
173
180
)
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