Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created April 19, 2017 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/aaad1c19f88cc67e21aaf274de953bd3 to your computer and use it in GitHub Desktop.
Save tpitale/aaad1c19f88cc67e21aaf274de953bd3 to your computer and use it in GitHub Desktop.
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