Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/captions/formats/vtt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class VTT < Base
# VTT file comments/style section
VTT_METADATA = /^NOTE|^STYLE/

# The identifier is a name that identifies the cue.
CUE_IDENTIFIER = /^\d+((?!-->).)*$/

# Auto Keyword used in Alignment
AUTO_KEYWORD = "auto"

Expand All @@ -23,7 +26,6 @@ class VTT < Base
# Parse VTT file and update CueList
def parse
base_parser do
count = 1
cue_count = 0
meta_data_section = false
cue = nil
Expand All @@ -32,6 +34,8 @@ def parse
line = line.strip
if line.empty?
meta_data_section = false
elsif !meta_data_section and is_cue_identifier?(line)
next
elsif is_meta_data?(line)
meta_data_section = true
elsif is_time?(line)
Expand Down Expand Up @@ -85,6 +89,10 @@ def is_text?(text)
!text.empty? and text.is_a?(String) and text != VTT_HEADER
end

def is_cue_identifier?(text)
text.match?(CUE_IDENTIFIER)
end

def set_properties(cue, properties)
properties.each do |prop|
prop, value = prop.split(":")
Expand Down
4 changes: 4 additions & 0 deletions spec/sample/test.vtt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ not be 100% accurate
- I didn’t pay too close attention to
when the cues should start or end.

1
00:00:04.080 --> 00:06.320 align:start position:21% line:90%,end
I'm going to flip through this deck.

STYLE
::cue(#\31) { color: lime; }
::cue(#crédit\ de\ transcription) { color: red; }

2
00:06.400 --> 00:07.880 align:middle position:10% line:-1
And I want you to see one card.
32

NOTE Comments

3
00:00:08.300 --> 00:00:09.400 align:middle line:90%,end
Not this one. That's too obvious.

Expand Down