Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.93 KB | None | 0 0
  1. def create_srt_from_snippets
  2.     @snippets = Snippet.all
  3.    
  4.     @srt_file = open("#{@subsdir}/#{PLAYLISTNAME}/srt_file.srt", "w")
  5.  
  6.     emptycounter =  ""
  7.     emptyline = '00:00:00,000 --> 00:00:00,001'
  8.  
  9.     @srt_file.puts(emptycounter)
  10.     @srt_file.puts(emptyline)
  11.     @srt_file.puts("")
  12.  
  13.     @start_ms = 1
  14.     @counter = 2
  15.  
  16.     @snippets.each do |snippet|
  17.         sentence = Sentence.find_by("id=#{snippet.sentence_id}")
  18.         text = sentence.full_sentence
  19.         duration = snippet.sentence_duration
  20.  
  21.         @start_srt = convert_ms_to_srt(@start_ms)
  22.         @end_srt = convert_ms_to_srt(@start_ms+duration )
  23.  
  24.         # 1
  25.         @srt_file.puts(@counter.to_s)
  26.  
  27.         # 00:00:14,000 –> 00:00:20,500
  28.         time_string = "#{@start_srt} –-> #{@end_srt}"
  29.         @srt_file.puts(time_string)
  30.  
  31.         # "Lost Corners consists of charcoal paintings."
  32.         @srt_file.puts(text)
  33.  
  34.         # new line
  35.         @srt_file.puts("")
  36.  
  37.         @start_ms += duration
  38.         @start_srt = @end_srt
  39.         @counter += 1
  40.     end
  41.  
  42.     @srt_file.close
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement