Skip to content

Instantly share code, notes, and snippets.

@kapilraj2436
Created May 1, 2020 16:32
Show Gist options
  • Save kapilraj2436/4b95dce245db6d7f66f27fe7241b5a54 to your computer and use it in GitHub Desktop.
Save kapilraj2436/4b95dce245db6d7f66f27fe7241b5a54 to your computer and use it in GitHub Desktop.
import datetime
Delimiter = " --> "
def addSecs(tm, secs):
fulldate = datetime.datetime(100, 1, 1, tm.hour, tm.minute, tm.second)
fulldate = fulldate + datetime.timedelta(seconds=secs)
return fulldate.time()
with open("E:\TLOR2002.srt") as f:
with open("E:\The.Lord.of.the.Rings.The.Two.Towers.2002.Extended.BluRay.1080p.DTSES6.1.x264-CHD.srt", "a") as f1:
for line in zip(f):
values = str(line).split(Delimiter)
if len(values) > 1:
time = values[0].split(',')
time_str = datetime.datetime.strptime(time[0], '%H:%M:%S').time()
b = addSecs(time_str, 3)
values[0] = str(b)+','+time[1]
time = values[1].split(',')
time_str = datetime.datetime.strptime(time[0], '%H:%M:%S').time()
b = addSecs(time_str, 3)
values[1] = str(b)+','+time[1]
line = Delimiter.join(values)
f1.write(line)
else:
f1.write(str(line))
print('file written successfully')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment