secret
anonymous / akshaygupta.rb
Last active

  • Download Gist
akshaygupta.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.