Created
April 19, 2017 20:37
-
-
Save tpitale/aaad1c19f88cc67e21aaf274de953bd3 to your computer and use it in GitHub Desktop.
Adjust timestamps in an SRT file
This file contains 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
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