Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create_srt_from_snippets
- @snippets = Snippet.all
- @srt_file = open("#{@subsdir}/#{PLAYLISTNAME}/srt_file.srt", "w")
- emptycounter = ""
- emptyline = '00:00:00,000 --> 00:00:00,001'
- @srt_file.puts(emptycounter)
- @srt_file.puts(emptyline)
- @srt_file.puts("")
- @start_ms = 1
- @counter = 2
- @snippets.each do |snippet|
- sentence = Sentence.find_by("id=#{snippet.sentence_id}")
- text = sentence.full_sentence
- duration = snippet.sentence_duration
- @start_srt = convert_ms_to_srt(@start_ms)
- @end_srt = convert_ms_to_srt(@start_ms+duration )
- # 1
- @srt_file.puts(@counter.to_s)
- # 00:00:14,000 –> 00:00:20,500
- time_string = "#{@start_srt} –-> #{@end_srt}"
- @srt_file.puts(time_string)
- # "Lost Corners consists of charcoal paintings."
- @srt_file.puts(text)
- # new line
- @srt_file.puts("")
- @start_ms += duration
- @start_srt = @end_srt
- @counter += 1
- end
- @srt_file.close
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement