8000 feat: add url player. · bazooka720/videodb-python@4f4b7fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f4b7fa

Browse files
committed
feat: add url player.
1 parent 30e4a74 commit 4f4b7fa

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

videodb/_utils/_http_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _handle_request_error(self, e: requests.exceptions.RequestException) -> None
120120
f"Invalid request: {str(e)}", e.response
121121
) from None
122122

123-
@backoff.on_exception(backoff.expo, Exception, max_time=500)
123+
@backoff.on_exception(backoff.expo, Exception, max_time=500, logger=None)
124124
def _get_output(self, url: str):
125125
"""Get the output from an async request"""
126126
response_json = self.session.get(url).json()

videodb/_utils/video.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import webbrowser as web
2+
3+
4+
def play_url(url: str) -> bool:
5+
opend = web.open(url)
6+
if not opend:
7+
try:
8+
from IPython.display import IFrame
9+
10+
player_width = 800
11+
player_height = 400
12+
IFrame(url, player_width, player_height)
13+
except ImportError:
14+
return False
15+
return True

videodb/search.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import webbrowser as web
2-
31
from abc import ABC, abstractmethod
2+
from videodb._utils.video import play_url
43
from videodb._constants import (
54
SearchType,
65
ApiPath,
@@ -73,8 +72,8 @@ def compile(self) -> str:
7372
for shot in self.shots
7473
],
7574
)
76-
self.stream_url = compile_data.get("stream_link")
77-
self.player_url = compile_data.get("player_link")
75+
self.stream_url = compile_data.get("stream_url")
76+
self.player_url = compile_data.get("player_url")
7877
return self.stream_url
7978

8079
else:
@@ -87,7 +86,7 @@ def play(self) -> str:
8786
:rtype: str
8887
"""
8988
self.compile()
90-
web.open(self.player_url)
89+
play_url(self.player_url)
9190
return self.player_url
9291

9392

videodb/shot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""This module contains the shot class"""
22

3-
import webbrowser as web
3+
44
from typing import Optional
5+
from videodb._utils.video import play_url
56
from videodb._constants import (
67
ApiPath,
78
)
@@ -66,8 +67,8 @@ def generate_stream(self) -> str:
6667
"length": self.video_length,
6768
},
6869
)
69-
self.stream_url = stream_data.get("stream_link")
70-
self.player_url = stream_data.get("player_link")
70+
self.stream_url = stream_data.get("stream_url")
71+
self.player_url = stream_data.get("player_url")
7172
return self.stream_url
7273

7374
def play(self) -> str:
@@ -77,5 +78,5 @@ def play(self) -> str:
7778
:rtype: str
7879
"""
7980
self.generate_stream()
80-
web.open(self.player_url)
81+
play_url(self.player_url)
8182
return self.player_url

videodb/video.py

Lines changed: 14 additions & 15 deletions
< ACBE tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import webbrowser as web
1+
from typing import Optional
2+
from videodb._utils.video import play_url
23
from videodb._constants import (
34
ApiPath,
45
SearchType,
@@ -7,19 +8,18 @@
78
)
89
from videodb.search import SearchFactory, SearchResult
910
from videodb.shot import Shot
10-
from typing import Optional
1111

1212

1313
class Video:
1414
def __init__(self, _connection, id: str, collection_id: str, **kwargs) -> None:
1515
self._connection = _connection
1616
self.id = id
1717
self.collection_id = collection_id
18-
self.stream_url = kwargs.get("stream_link", None)
19-
self.player_url = kwargs.get("player_link", None)
18+
self.stream_url = kwargs.get("stream_url", None)
19+
self.player_url = kwargs.get("player_url", None)
2020
self.name = kwargs.get("name", None)
2121
self.description = kwargs.get("description", None)
22-
self.thumbnail_url = kwargs.get("thumbnail", None)
22+
self.thumbnail_url = kwargs.get("thumbnail_url", None)
2323
self.length = float(kwargs.get("length", 0.0))
2424
self.transcript = kwargs.get("transcript", None)
2525
self.transcript_text = kwargs.get("transcript_text", None)
@@ -84,8 +84,8 @@ def generate_stream(self, timeline: Optional[list[tuple[int, int]]] = None) -> s
8484
"length": self.length,
8585
},
8686
)
87-
self.stream_url = stream_data.get("stream_link")
88-
self.player_url = stream_data.get("player_link")
87+
self.stream_url = stream_data.get("stream_url")
88+
self.player_url = stream_data.get("player_url")
8989
return self.stream_url
9090

9191
def generate_thumbnail(self):
@@ -94,7 +94,7 @@ def generate_thumbnail(self):
9494
thumbnail_data = self._connection.get(
9595
path=f"{ApiPath.video}/{self.id}/{ApiPath.thumbnail}"
9696
)
97-
self.thumbnail_url = thumbnail_data.get("thumbnail")
97+
self.thumbnail_url = thumbnail_data.get("thumbnail_url")
9898
return self.thumbnail_url
9999

100100
def _fetch_transcript(self, force: bool = False) -> None:
@@ -137,8 +137,8 @@ def add_subtitle(self) -> str:
137137
"type": Workflows.add_subtitles,
138138
},
139139
)
140-
self.stream_url = subtitle_data.get("stream_link")
141-
self.player_url = subtitle_data.get("player_link")
140+
self.stream_url = subtitle_data.get("stream_url")
141+
self.player_url = subtitle_data.get("player_url")
142142
return self.stream_url
143143

144144
def insert_video(self, video, timestamp: float) -> str:
@@ -178,16 +178,15 @@ def insert_video(self, video, timestamp: float) -> str:
178178
for shot in all_shots
179179
],
180180
)
181-
self.stream_url = compile_data.get("stream_link")
182-
self.player_url = compile_data.get("player_link")
181+
self.stream_url = compile_data.get("stream_url")
182+
self.player_url = compile_data.get("player_url")
183183
return self.stream_url
184184

185185
def play(self) -> str:
186-
"""Generate a stream url for the shot and open it in the default browser
186+
"""Open the player url in the browser/iframe and return the stream url
187187
188188
:return: The stream url
189189
:rtype: str
190190
"""
191-
self.generate_stream()
192-
web.open(self.player_url)
191+
play_url(self.player_url)
193192
return self.player_url

0 commit comments

Comments
 (0)
0