Wrote a program because the subtitles I got for GochiUsa are from a TVRIP but the raws are from Blu-ray so they didn’t line up
dumb python code
the file input is passed in as an argument and everything else will be prompted, creates filename_treated.ass in the same directory as the input file because why not
import re
import datetime
import sys
filename = sys.argv[1]
intvStartString = input('enter starting timecode(H:M:S.mS): ')
intvStartTime = datetime.datetime.strptime(intvStartString, "%H:%M:%S.%f")
intvEndString = input('enter ending timecode(H:M:S.mS): ')
intvEndTime = datetime.datetime.strptime(intvEndString, "%H:%M:%S.%f")
changeInTime = input('enter your timecode offset(S.mS): ')
matchingTime = "00:00.00"
filedata = open(filename, 'r', encoding="utf-8").read()
with open(filename, 'r', encoding="utf-8") as file:
for line in file:
for i in re.finditer('[0-9]{1}:[0-9]{2}:[0-9]{2}.[0-9]{2}', line):
matchingTime = re.search('[0-9]{1}:[0-9]{2}:[0-9]{2}.[0-9]{2}', line)
if matchingTime == None:
break
interpretedMatchingTime = datetime.datetime.strptime(matchingTime.group(0), "%H:%M:%S.%f")
if interpretedMatchingTime < intvStartTime or interpretedMatchingTime > intvEndTime:
break
interpretedAdjustedMatchingTime = datetime.datetime.strptime(matchingTime.group(0), "%H:%M:%S.%f") + datetime.timedelta( seconds=int( changeInTime[:changeInTime.find('.')] ) , microseconds=int( changeInTime[changeInTime.find('.')+1:] ))
convertedInterpretedMatchingTime = interpretedAdjustedMatchingTime.strftime("%H:%M:%S.%f")
treatedConvertedInterpretedMatchingTime = convertedInterpretedMatchingTime[1:-4]
filedata = filedata.replace(matchingTime.group(0),treatedConvertedInterpretedMatchingTime)
line = line.replace(matchingTime.group(0),"")
destFilename = filename[:-4] + "_treated.ass"
with open(destFilename, 'x', encoding="utf-8") as file:
file.write(filedata)