-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathgenerate_subtitle.py
More file actions
26 lines (24 loc) · 881 Bytes
/
Copy pathgenerate_subtitle.py
File metadata and controls
26 lines (24 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import time
def generate_subtitle_file(timepoints, mark_array, filename="subtitle.txt"):
count = 0
current = 0
dir_path = os.environ["BASE_DIR_PATH"]
filepath = f"{dir_path}/{filename}"
for i in range(len(timepoints)):
count += 1
current += 1
with open(filepath, "a", encoding="utf-8") as out:
out.write(mark_array[int(timepoints[i].mark_name)] + " ")
if i != len(timepoints) - 1:
total_time = timepoints[i + 1].time_seconds
time.sleep(total_time - timepoints[i].time_seconds)
if current == 25:
open(filepath, "w", encoding="utf-8").close()
current = 0
count = 0
elif count % 7 == 0:
with open(filepath, "a", encoding="utf-8") as out:
out.write("\n")
time.sleep(2)
open(filepath, "w").close()