Merge a388f1c3ba4a94ed5b9f5aece23d43a7beed1cc4 into 90db0de1896c23cbfaf0c58bc2d30665f709f170

This commit is contained in:
Matteo Fasulo 2024-12-02 18:22:09 +00:00 committed by GitHub
commit 63fdf0a058
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -129,12 +129,16 @@ class SubtitlesWriter(ResultWriter):
max_line_count: Optional[int] = None, max_line_count: Optional[int] = None,
highlight_words: bool = False, highlight_words: bool = False,
max_words_per_line: Optional[int] = None, max_words_per_line: Optional[int] = None,
subtitle_format: Optional[str] = None,
font_color: Optional[str] = None,
): ):
options = options or {} options = options or {}
max_line_width = max_line_width or options.get("max_line_width") max_line_width = max_line_width or options.get("max_line_width")
max_line_count = max_line_count or options.get("max_line_count") max_line_count = max_line_count or options.get("max_line_count")
highlight_words = highlight_words or options.get("highlight_words", False) highlight_words = highlight_words or options.get("highlight_words", False)
max_words_per_line = max_words_per_line or options.get("max_words_per_line") max_words_per_line = max_words_per_line or options.get("max_words_per_line")
subtitle_format = subtitle_format or options.get("subtitle_format", None)
font_color = font_color or options.get("font_color", "#ffffff")
preserve_segments = max_line_count is None or max_line_width is None preserve_segments = max_line_count is None or max_line_width is None
max_line_width = max_line_width or 1000 max_line_width = max_line_width or 1000
max_words_per_line = max_words_per_line or 1000 max_words_per_line = max_words_per_line or 1000
@ -209,7 +213,7 @@ class SubtitlesWriter(ResultWriter):
yield start, end, "".join( yield start, end, "".join(
[ [
re.sub(r"^(\s*)(.*)$", r"\1<u>\2</u>", word) re.sub(r"^(\s*)(.*)$", fr"\1<font color={font_color}><{subtitle_format}>\2</{subtitle_format}></font>", word)
if j == i if j == i
else word else word
for j, word in enumerate(all_words) for j, word in enumerate(all_words)