Spaces:
Running
Running
Update subtitle_manager.py
Browse files
modules/utils/subtitle_manager.py
CHANGED
@@ -34,7 +34,7 @@ def get_srt(segments):
|
|
34 |
|
35 |
|
36 |
def get_vtt(segments):
|
37 |
-
output = "
|
38 |
for i, segment in enumerate(segments):
|
39 |
output += f"{timeformat_vtt(segment['start'])} --> {timeformat_vtt(segment['end'])}\n"
|
40 |
if segment['text'].startswith(' '):
|
@@ -76,7 +76,7 @@ def parse_srt(file_path):
|
|
76 |
|
77 |
|
78 |
def parse_vtt(file_path):
|
79 |
-
"""Reads
|
80 |
with open(file_path, 'r', encoding='utf-8') as file:
|
81 |
webvtt_data = file.read()
|
82 |
|
@@ -84,7 +84,7 @@ def parse_vtt(file_path):
|
|
84 |
blocks = webvtt_data.split('\n\n')
|
85 |
|
86 |
for block in blocks:
|
87 |
-
if block.strip() != '' and not block.strip().startswith("
|
88 |
lines = block.strip().split('\n')
|
89 |
timestamp = lines[0]
|
90 |
sentence = ' '.join(lines[1:])
|
@@ -107,7 +107,7 @@ def get_serialized_srt(dicts):
|
|
107 |
|
108 |
|
109 |
def get_serialized_vtt(dicts):
|
110 |
-
output = "
|
111 |
for dic in dicts:
|
112 |
output += f'{dic["timestamp"]}\n'
|
113 |
output += f'{dic["sentence"]}\n\n'
|
|
|
34 |
|
35 |
|
36 |
def get_vtt(segments):
|
37 |
+
output = "WEBVTT\n\n"
|
38 |
for i, segment in enumerate(segments):
|
39 |
output += f"{timeformat_vtt(segment['start'])} --> {timeformat_vtt(segment['end'])}\n"
|
40 |
if segment['text'].startswith(' '):
|
|
|
76 |
|
77 |
|
78 |
def parse_vtt(file_path):
|
79 |
+
"""Reads WEBVTT file and returns as dict"""
|
80 |
with open(file_path, 'r', encoding='utf-8') as file:
|
81 |
webvtt_data = file.read()
|
82 |
|
|
|
84 |
blocks = webvtt_data.split('\n\n')
|
85 |
|
86 |
for block in blocks:
|
87 |
+
if block.strip() != '' and not block.strip().startswith("WEBVTT"):
|
88 |
lines = block.strip().split('\n')
|
89 |
timestamp = lines[0]
|
90 |
sentence = ' '.join(lines[1:])
|
|
|
107 |
|
108 |
|
109 |
def get_serialized_vtt(dicts):
|
110 |
+
output = "WEBVTT\n\n"
|
111 |
for dic in dicts:
|
112 |
output += f'{dic["timestamp"]}\n'
|
113 |
output += f'{dic["sentence"]}\n\n'
|