Class: Appydave::Tools::SubtitleProcessor::Join::SRTMerger
- Inherits:
-
Object
- Object
- Appydave::Tools::SubtitleProcessor::Join::SRTMerger
- Defined in:
- lib/appydave/tools/subtitle_processor/join.rb
Overview
Merges multiple subtitle arrays while maintaining timing and adding buffers
Instance Method Summary collapse
-
#initialize(buffer_ms: 100) ⇒ SRTMerger
constructor
A new instance of SRTMerger.
- #merge(subtitle_arrays) ⇒ Object
Constructor Details
#initialize(buffer_ms: 100) ⇒ SRTMerger
Returns a new instance of SRTMerger.
139 140 141 |
# File 'lib/appydave/tools/subtitle_processor/join.rb', line 139 def initialize(buffer_ms: 100) @buffer_ms = buffer_ms.to_f end |
Instance Method Details
#merge(subtitle_arrays) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/appydave/tools/subtitle_processor/join.rb', line 143 def merge(subtitle_arrays) return [] if subtitle_arrays.empty? merged = [] current_end_time = 0.0 subtitle_arrays.each do |subtitles| next if subtitles.empty? # Calculate offset needed for this batch of subtitles first_subtitle = subtitles.first offset_seconds = calculate_offset(current_end_time, first_subtitle.start_time) # Add adjusted subtitles to merged array subtitles.each do |subtitle| adjusted_subtitle = adjust_subtitle_timing(subtitle, offset_seconds) merged << adjusted_subtitle end # Update current_end_time for next batch current_end_time = merged.last.end_time end # Renumber subtitles sequentially merged.each_with_index do |subtitle, index| subtitle.instance_variable_set(:@index, index + 1) end merged end |