From e2f12566dd0478b9ce49db302ebba2b456c2ed66 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Tue, 28 Jul 2015 13:21:27 -0700 Subject: [PATCH 1/2] check for a blank caption line Sometimes the caption line is blank. This fix checks to see if the caption is there at all and if not it doesn't bail. --- lib/webvtt/file.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/webvtt/file.rb b/lib/webvtt/file.rb index 636fc7d..1a6e31f 100644 --- a/lib/webvtt/file.rb +++ b/lib/webvtt/file.rb @@ -66,7 +66,9 @@ def add_a_cue(collected_lines) cue_opts[:identifier] = collected_lines.first cue_opts[:cue_line] = collected_lines[1] end - cue_opts[:text] = collected_lines[2..-1].join("\n") + if collected_lines[2..-1] + cue_opts[:text] = collected_lines[2..-1].join("\n") + end cues << Cue.new(cue_opts) end From 14b8b3b38133df4820ef66f88b5cffd1b722cd0c Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Tue, 28 Jul 2015 13:37:16 -0700 Subject: [PATCH 2/2] just shift the array instead --- lib/webvtt/file.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/webvtt/file.rb b/lib/webvtt/file.rb index 1a6e31f..43dcec9 100644 --- a/lib/webvtt/file.rb +++ b/lib/webvtt/file.rb @@ -61,14 +61,12 @@ def add_a_cue(collected_lines) cue_opts = {} if collected_lines.first.include?('-->') cue_opts[:identifier] = nil - cue_opts[:cue_line] = collected_lines.first + cue_opts[:cue_line] = collected_lines.shift elsif collected_lines[1].include?('-->') - cue_opts[:identifier] = collected_lines.first - cue_opts[:cue_line] = collected_lines[1] - end - if collected_lines[2..-1] - cue_opts[:text] = collected_lines[2..-1].join("\n") + cue_opts[:identifier] = collected_lines.shift + cue_opts[:cue_line] = collected_lines.shift end + cue_opts[:text] = collected_lines.join(' ') cues << Cue.new(cue_opts) end