Devide
Devide
merged_lines = []
i = 0
while i < len(lines):
if lines[i].strip().isdigit():
if i + 2 < len(lines):
current_num = lines[i].strip()
current_time = lines[i + 1].strip()
current_text = lines[i + 2].strip()
if not ends_with_punct:
start_time = current_time.split(' --> ')[0]
end_time = next_time.split(' --> ')[1]
merged_time = f"{start_time} --> {end_time}"
return merged_lines
keep_lines = set()
for i in range(len(lines)):
line = lines[i]
if any(sep in line for sep in ['.', '...', '?', '!']):
for j in range(max(0, i-2), min(len(lines), i+5)):
keep_lines.add(j)
merged_subtitles = merge_subtitles(filtered_lines)
with open(output_path, 'w', encoding='utf-8') as file:
new_index = 1
for i, subtitle in enumerate(merged_subtitles):
if len(subtitle) == 3: # 完整的字幕块
file.write(f"{new_index}\n")
file.write(f"{subtitle[1]}\n")
file.write(f"{subtitle[2]}")
if i < len(merged_subtitles) - 1:
file.write("\n\n")
else:
file.write("\n")
new_index += 1