Platinum Partner

Convert Smil To Srt


lines = IO.readlines("captions2.txt")

File.open("peepcode-009-rails.srt", "w") do |f|
  n = 0
  lines.each do |line|
    if (line != "\n")
      if line =~ /\[..:..:..\...\]/
        n = n + 1
        matches = /\[(..):(..):(..)\.(..)\]/.match(line)
        hour, min, sec, usec = matches[1], matches[2], matches[3], matches[4]
        time = Time.local(2000, "jan", 1, hour.to_i, min.to_i, sec.to_i, usec.to_i)
        time2 = time + 3 # sec
        f.puts "\n"
        f.puts n
        f.puts "#{time.strftime("%H:%M:%S")},#{usec} --> #{time2.strftime("%H:%M:%S")},#{usec}" # 00:00:06,088 --> 00:00:09,282
      else
        f.puts line
      end
    end
  end
end

puts "done"
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}