Created
February 20, 2018 14:53
-
-
Save H2NCH2COOH/849a5bcf70653ad874ffde1d0a755213 to your computer and use it in GitHub Desktop.
srt Subtitle file time move
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/lua | |
local MOVEMS = 1500 | |
local line = io.read('*l') | |
while line do | |
--local m = {string.match(line, '^([0-9][0-9]):([0-9][0-9]):([0-9][0-9]),([0-9]+) %-%-> ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]),([0-9]+)$')} | |
local mat = {string.match(line, "^(%d%d):(%d%d):(%d%d),(%d+) %-%-> (%d%d):(%d%d):(%d%d),(%d+)\r$")} | |
if mat[1] then | |
local d = {} | |
local h, m, s, ms | |
h = tonumber(mat[1]) | |
m = tonumber(mat[2]) | |
s = tonumber(mat[3]) | |
ms = tonumber(mat[4]) | |
ms = ms + MOVEMS | |
while ms >= 1000 do | |
ms = ms - 1000 | |
s = s + 1 | |
end | |
while s >= 60 do | |
s = s - 60 | |
m = m + 1 | |
end | |
while m >= 60 do | |
m = m - 60 | |
h = h + 1 | |
end | |
table.insert(d, string.format('%02d:%02d:%02d,%d', h, m, s, ms)) | |
table.insert(d, ' --> ') | |
h = tonumber(mat[5]) | |
m = tonumber(mat[6]) | |
s = tonumber(mat[7]) | |
ms = tonumber(mat[8]) | |
ms = ms + MOVEMS | |
while ms >= 1000 do | |
ms = ms - 1000 | |
s = s + 1 | |
end | |
while s >= 60 do | |
s = s - 60 | |
m = m + 1 | |
end | |
while m >= 60 do | |
m = m - 60 | |
h = h + 1 | |
end | |
table.insert(d, string.format('%02d:%02d:%02d,%d', h, m, s, ms)) | |
table.insert(d, "\r") | |
print(table.concat(d, '')) | |
else | |
print(line) | |
end | |
line = io.read('*l') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment