Create a gist now

Instantly share code, notes, and snippets.

anonymous /akshaygupta.rb Secret
Created Oct 5, 2009

What would you like to do?
require 'optparse'
require 'time'
opts = {}
optp = 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}
opts[:operation]=="add"? op = "+": op = "-"[1], 'w') do |f|
f.puts([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] } * ' --> '})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment