Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adjust timestamps in an SRT file
adjust_by = 48 # seconds
srt = File.read(File.expand_path("~/Downloads/EN.srt"))
new_srt = srt.
split("\r\n\r\n").
map {|s| s.split("\r\n")}.
map do |i, times, *values|
new_times = times.split(" --> ").map {|t| (Time.strptime(t, "%H:%M:%S,%L") + adjust_by).strftime("%H:%M:%S,%L")}.join(" --> ")
[i, new_times, values.join("\r\n")].join("\r\n")
end.join("\r\n\r\n")
File.write(File.expand_path("~/Downloads/EN-adjusted.srt"), new_srt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.