How to regenerate the srt file.
Closed this issue · 2 comments
jp1017 commented
I have a requirement:
Here is a srt file.I want to make the sub's endtime equls the next sub's starttime. How to make it.
cdown commented
Sorry, but github issues is not a support forum. You don't need anything srt specific, just loop over the SRT files with an index and do:
sub[i].end = sub[i+1].start
With bounds checks for i
.
cdown commented
Completely untested, written directly here:
import srt
with open("input.srt", "r") as file:
srt_content = file.read()
subtitles = list(srt.parse(srt_content))
for i in range(len(subtitles) - 1):
subtitles[i].end = subtitles[i + 1].start
modified_srt_content = srt.compose(subtitles)
with open("output.srt", "w") as file:
file.write(modified_srt_content)