long time reader first time asker.
I am working on some vtt (closed caption) files that I need to edit the timestamps for. The format of the file is as follows:
177
00:07:37.450 --> 00:07:39.690
- [Liz] How would you suggest an organization devise
178
00:07:39.690 --> 00:07:41.719
the accountabilities for culture?
179
00:07:41.719 --> 00:07:43.690
- [Tamara] It is a shared accountability
I have written the following code to read the file, calculate the new timestamps (5% slower) and spit out the new timestamps:
from sys import argv
script, filename = argv
adjustment = input("Adjustment multiplier: ")
video = open(filename, "r+")
lines = video.readlines()
video.seek(0)
for l in lines:
if l[:2] == "00":
#here I've omitted a lot of calculations to turn the timestamps
#into milliseconds, apply the adjustment multiplier, and turn them back into
#minutes, seconds, and milliseconds.
new_line = str(#concatenation of new values into timestamp format)
video.write(new_line)
video.close()
The calculations work great, but the problem is that it dumps all the new lines into the start of the file instead of writing over each timestamp line and skipping the rest.
I would love to hear what you guys think! I've been wrestling with this for a while and have tried a bunch of things but haven't quite been able to make it work.
Thank you!