Spaces:
Running
Running
Macrodove
commited on
Commit
·
1a7e1ee
1
Parent(s):
0362dd5
Bilingual srt read function implemented
Browse filesFormer-commit-id: 2ad5fe60da1e9dee426fc948b1de5628cac7fba5
- src/srt_util/srt.py +13 -4
src/srt_util/srt.py
CHANGED
@@ -50,7 +50,10 @@ class SrtSegment(object):
|
|
50 |
self.start = int(start_list[0]) * 3600 + int(start_list[1]) * 60 + int(start_list[2]) + self.start_ms / 100
|
51 |
end_list = self.end_time_str.split(',')[0].split(':')
|
52 |
self.end = int(end_list[0]) * 3600 + int(end_list[1]) * 60 + int(end_list[2]) + self.end_ms / 100
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
def merge_seg(self, seg):
|
56 |
"""
|
@@ -105,10 +108,16 @@ class SrtScript(object):
|
|
105 |
def parse_from_srt_file(cls, path: str):
|
106 |
with open(path, 'r', encoding="utf-8") as f:
|
107 |
script_lines = [line.rstrip() for line in f.readlines()]
|
108 |
-
|
|
|
|
|
109 |
segments = []
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
112 |
|
113 |
return cls(segments)
|
114 |
|
|
|
50 |
self.start = int(start_list[0]) * 3600 + int(start_list[1]) * 60 + int(start_list[2]) + self.start_ms / 100
|
51 |
end_list = self.end_time_str.split(',')[0].split(':')
|
52 |
self.end = int(end_list[0]) * 3600 + int(end_list[1]) * 60 + int(end_list[2]) + self.end_ms / 100
|
53 |
+
if len(args[0]) < 5:
|
54 |
+
self.translation = ""
|
55 |
+
else:
|
56 |
+
self.translation = args[0][3]
|
57 |
|
58 |
def merge_seg(self, seg):
|
59 |
"""
|
|
|
108 |
def parse_from_srt_file(cls, path: str):
|
109 |
with open(path, 'r', encoding="utf-8") as f:
|
110 |
script_lines = [line.rstrip() for line in f.readlines()]
|
111 |
+
bilingual = False
|
112 |
+
if script_lines[2] != '' and script_lines[3] != '':
|
113 |
+
bilingual = True
|
114 |
segments = []
|
115 |
+
if bilingual:
|
116 |
+
for i in range(0, len(script_lines), 5):
|
117 |
+
segments.append(list(script_lines[i:i + 5]))
|
118 |
+
else:
|
119 |
+
for i in range(0, len(script_lines), 4):
|
120 |
+
segments.append(list(script_lines[i:i + 4]))
|
121 |
|
122 |
return cls(segments)
|
123 |
|