Method: Titlekit::ASS.export
- Defined in:
- lib/titlekit/parsers/ass.rb
.export(subtitles) ⇒ String
Exports the supplied subtitles to ASS format
133 134 135 136 137 138 139 140 141 142 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 |
# File 'lib/titlekit/parsers/ass.rb', line 133 def self.export(subtitles) result = '' result << "[Script Info]\nScriptType: v4.00+\n\n" result << "[V4+ Styles]\nFormat: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n" result << "Style: Default,Arial,16,&H00FFFFFF,&H00FFFFFF,&H40000000,&H40000000,0,0,0,0,100,100,0,0.00,1,3,0,2,20,20,20,1\n" result << "Style: Top,Arial,16,&H00FFFFFF,&H00FFFFFF,&H40000000,&H40000000,0,0,0,0,100,100,0,0.00,1,3,0,8,20,20,20,1\n" result << "Style: Middle,Arial,16,&H00FFFFFF,&H00FFFFFF,&H40000000,&H40000000,0,0,0,0,100,100,0,0.00,1,3,0,5,20,20,20,1\n" DEFAULT_PALETTE.each do |color| processed_color = '&H00' + (color[4..5] + color[2..3] + color[0..1]) result << "Style: #{color},Arial,16,#{processed_color},#{processed_color},&H40000000,&H40000000,0,0,0,0,100,100,0,0.00,1,3,0,2,20,20,20,1\n" end result << "\n" # Close styles section result << "[Events]\nFormat: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text\n" subtitles.each do |subtitle| fields = [ 'Dialogue: 0', # Format: Marked SSA.build_timecode(subtitle[:start]), # Start SSA.build_timecode(subtitle[:end]), # End subtitle[:style] || 'Default', # Style '', # Name '0000', # MarginL '0000', # MarginR '0000', # MarginV '', # Effect subtitle[:lines].gsub("\n", '\N') # Text ] result << fields.join(',') + "\n" end result end |