-
-
Save anonymous/b0822d661c735cd3c161 to your computer and use it in GitHub Desktop.
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
require 'optparse' | |
require 'time' | |
opts = {} | |
optp = OptionParser.new do |o| | |
o.banner = "Usage: shift.rb --operation (add/sub) --time (seconds,milliseconds) input_file output_file" | |
opts[:operation] = nil;o.on( '-o', '--operation ADD/SUB', 'Add/subtract time in the .srt file' ){|v|opts[:operation] = v} | |
opts[:time] = 0.0;o.on( '-t', '--time TIME', 'Specify time in "seconds, milliseconds" form (11,222)'){|t|opts[:time] = t} | |
o.on( '-h', '--help', 'Display this screen' ){puts o; exit} | |
end | |
optp.parse! | |
opts[:operation]=="add"? op = "+": op = "-" | |
File.open(ARGV[1], 'w') do |f| | |
f.puts(File.read(ARGV[0]).gsub(/^(.*) --> (.*)$/){[$1,$2].map{|i|(t=(Time.parse(i)).send(op,opts[:time].tr(',','.').to_f)).strftime("%H:%M:%S,#{t.usec}00")[0,12] } * ' --> '}) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment