Skip to content

Commit 15bd184

Browse files
committed
feat: add subtitle style
1 parent 2ab473e commit 15bd184

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

videodb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
logger: logging.Logger = logging.getLogger("videodb")
1818

19-
__version__ = "0.0.3"
19+
__version__ = "0.0.4"
2020
__author__ = "videodb"
2121

2222
__all__ = [

videodb/_constants.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,45 @@ class HttpClientDefaultValues:
5858

5959
class MaxSupported:
6060
fade_duration = 5
61+
62+
63+
class SubtitleBorderStyle:
64+
no_border = 1
65+
opaque_box = 3
66+
outline = 4
67+
68+
69+
class SubtitleAlignment:
70+
bottom_left = 1
71+
bottom_center = 2
72+
bottom_right = 3
73+
middle_left = 4
74+
middle_center = 5
75+
middle_right = 6
76+
top_left = 7
77+
top_center = 8
78+
top_right = 9
79+
80+
81+
class SubtitleStyleDefaultValues:
82+
font_name: str = "Arial"
83+
font_size: float = 18
84+
primary_colour: str = "&H00FFFFFF" # white
85+
secondary_colour: str = "&H000000FF" # blue
86+
outline_colour: str = "&H00000000" # black
87+
back_colour: str = "&H00000000" # black
88+
bold: bool = False
89+
italic: bool = False
90+
underline: bool = False
91+
strike_out: bool = False
92+
scale_x: float = 1.0
93+
scale_y: float = 1.0
94+
spacing: float = 0
95+
angle: float = 0
96+
border_style: int = SubtitleBorderStyle.outline
97+
outline: float = 1.0
98+
shadow: float = 0.0
99+
alignment: int = SubtitleAlignment.bottom_center
100+
margin_l: int = 10
101+
margin_r: int = 10
102+
margin_v: int = 10

videodb/video.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
SearchType,
66
IndexType,
77
Workflows,
8+
SubtitleStyleDefaultValues,
89
)
910
from videodb.search import SearchFactory, SearchResult
1011
from videodb.shot import Shot
@@ -129,11 +130,57 @@ def index_spoken_words(self) -> None:
129130
},
130131
)
131132

132-
def add_subtitle(self) -> str:
133+
def add_subtitle(
134+
self,
135+
font_name: str = SubtitleStyleDefaultValues.font_name,
136+
font_size: float = SubtitleStyleDefaultValues.font_size,
137+
primary_colour: str = SubtitleStyleDefaultValues.primary_colour,
138+
secondary_colour: str = SubtitleStyleDefaultValues.secondary_colour,
139+
outline_colour: str = SubtitleStyleDefaultValues.outline_colour,
140+
back_colour: str = SubtitleStyleDefaultValues.back_colour,
141+
bold: bool = SubtitleStyleDefaultValues.bold,
142+
italic: bool = SubtitleStyleDefaultValues.italic,
143+
underline: bool = SubtitleStyleDefaultValues.underline,
144+
strike_out: bool = SubtitleStyleDefaultValues.strike_out,
145+
scale_x: float = SubtitleStyleDefaultValues.scale_x,
146+
scale_y: float = SubtitleStyleDefaultValues.scale_x,
147+
spacing: float = SubtitleStyleDefaultValues.spacing,
148+
angle: float = SubtitleStyleDefaultValues.angle,
149+
border_style: int = SubtitleStyleDefaultValues.border_style,
150+
outline: float = SubtitleStyleDefaultValues.outline,
151+
shadow: float = SubtitleStyleDefaultValues.shadow,
152+
alignment: int = SubtitleStyleDefaultValues.alignment,
153+
margin_l: int = SubtitleStyleDefaultValues.margin_l,
154+
margin_r: int = SubtitleStyleDefaultValues.margin_r,
155+
margin_v: int = SubtitleStyleDefaultValues.margin_v,
156+
) -> str:
133157
subtitle_data = self._connection.post(
134158
path=f"{ApiPath.video}/{self.id}/{ApiPath.workflow}",
135159
data={
136160
"type": Workflows.add_subtitles,
161+
"subtitle_style": {
162+
"font_name": font_name,
163+
"font_size": font_size,
164+
"primary_colour": primary_colour,
165+
"secondary_colour": secondary_colour,
166+
"outline_colour": outline_colour,
167+
"back_colour": back_colour,
168+
"bold": bold,
169+
"italic": italic,
170+
"underline": underline,
171+
"strike_out": strike_out,
172+
"scale_x": scale_x,
173+
"scale_y": scale_y,
174+
"spacing": spacing,
175+
"angle": angle,
176+
"border_style": border_style,
177+
"outline": outline,
178+
"shadow": shadow,
179+
"alignment": alignment,
180+
"margin_l": margin_l,
181+
"margin_r": margin_r,
182+
"margin_v": margin_v,
183+
},
137184
},
138185
)
139186
return subtitle_data.get("stream_url", None)

0 commit comments

Comments
 (0)