secret
anonymous / paragshah.rb
Last active

  • Download Gist
paragshah.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
def calc(h,m,s,ms,op,t1,t2)
ts = t1
tms = t2
if op==1
total_s =s+ts
total_m= 0
total_h= 0
total_ms = ms+tms
if total_ms > 999
total_s = total_s+1
total_ms = total_ms - 1000
if total_s > 59
total_m = total_m+1+m
total_s = total_s - 60
if total_m > 59
total_h = total_h+1+h
total_m = total_m - 60
end
end
end
if total_h < 9
total_h = "0"+total_h.to_s
else
total_h = total_h.to_s
end
if total_m < 9
total_m = "0"+total_m.to_s
else
total_m = total_m.to_s
end
if total_s < 9
total_s = "0"+total_s.to_s
else
total_s = total_s.to_s
end
if total_ms < 9
total_ms = "00"+total_ms.to_s
elsif total_ms =tms
total_ms = ms-tms
else
tmp = tms-ms
total_ms = 1000-tmp
total_s = total_s-1
end
newt = ts+total_s
if s>= newt
if newt 59
total_m = total_m-1-m
total_s = total_s - 60
if total_m > 59
total_h = total_h-1-h
total_m = total_m - 60
end
end
if total_h < 9
total_h = "0"+total_h.to_s
else
total_h = total_h.to_s
end
if total_m < 9
total_m = "0"+total_m.to_s
else
total_m = total_m.to_s
end
if total_s < 9
total_s = "0"+total_s.to_s
else
total_s = total_s.to_s
end
if total_ms < 9
total_ms = "00"+total_ms.to_s
elsif total_ms ')
st = temp[0].strip
et = temp[1].strip
temp = st.split(':')
hh1 = temp[0].strip
mm1 = temp[1].strip
ss1 = temp[2].strip
temp = ss1.split(',')
ss1 = temp[0].strip
ms1 = temp[1].strip
 
temp = et.split(':')
hh2 = temp[0].strip
mm2 = temp[1].strip
ss2 = temp[2].strip
temp = ss2.split(',')
ss2 = temp[0].strip
ms2 = temp[1].strip
if options.operation == :add
op=1
else
op=0
end
 
final1 = calc(hh1.to_i, mm1.to_i, ss1.to_i, ms1.to_i,op,ts.to_i,tms.to_i)
final2 = calc(hh2.to_i, mm2.to_i, ss2.to_i, ms2.to_i,op,ts.to_i,tms.to_i)
otext = final1+' --> '+final2
end
end
File.open(output_file, 'w') do |f2|
f2.puts otext
end
 
end
 
end
 
options = ShiftSubtitle.parse(ARGV)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.