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
|
# File 'lib/tx_translate/sbv_process.rb', line 5
def self.run(filename)
file = File.open(filename, 'r')
basename = File.basename(filename, "sbv")
contents = file.read + "\n\n"
contents.gsub!("\r\n", "\n")
subbed = ''
original_content_array = []
timeline_content_array = []
context_content_array = []
contents.gsub(/(\d:\d{2}:\d{2}.\d{3}),(\d:\d{2}:\d{2}\.\d{3})\n((?:^.*$\n)*?)\n/).with_index do |m, i|
original_content_array[i] = m
timeline_content_array[i] = "#{Regexp.last_match(1)},#{Regexp.last_match(2)}"
context_content_array[i] = Regexp.last_match(3).to_s
end
context_content_array = TxTranslate::ParallelArray.new(context_content_array).parallel_process
original_content_array.each_with_index do |_item, i|
subbed += timeline_content_array[i] + "\n" + context_content_array[i] + "\n\n"
end
file = File.open("#{basename}zh-si.sbv", 'w') { |f| f.write(subbed) }
end
|