webvtt 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 33346cca4ae0f29174876b0c91317cc90dc0276acfe13f1cd864ed337aceacee
4
+ data.tar.gz: 2f8f94c67ef2975a1a81411fee61566bae61fe783c49dbb2277222be44bbdb8e
5
+ SHA512:
6
+ metadata.gz: 2edea0396a20e84836eba4a68f30f97c8bd4f535cc0fcd5dc5b7f9d04501c61136e0ae2e4e0c3b445df0e67c42ebe9e0487f4192ea6fe4d40a9dcaed95d40771
7
+ data.tar.gz: 58ab94b4e640f4b2dd7ec7dedc52e8fadb7f7b0665e8af708d9fb7314f34dafcdf22f2fc273d4c800bff0cb35bbe3d818ad91176c1a68c1e6dc862d98514f5fd
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .byebug*
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ - "2.1.10"
5
+ - "2.2.10"
6
+ - "2.3.8"
7
+ - "2.4.9"
8
+ - "2.5.7"
9
+ - "2.6.5"
10
+ - "2.7.0"
11
+
12
+ # uncomment this line if your project needs to run something other than `rake`:
13
+ script: rake test
data/README.md CHANGED
@@ -4,6 +4,7 @@ Parse WebVTT files with Ruby.
4
4
  The main goal is just to extract the text out with start and end times.
5
5
  The parsing does not conform the [WebVTT specification](http://dev.w3.org/html5/webvtt/) at this point.
6
6
 
7
+ [![Build Status](https://travis-ci.org/jronallo/webvtt.png)](https://travis-ci.org/jronallo/webvtt)
7
8
 
8
9
  # Story
9
10
 
@@ -25,7 +26,7 @@ Based on this WebVTT:
25
26
  WEBVTT
26
27
 
27
28
  1
28
- 00:00:00 --> 00:00:03.000 D:vertical A:start
29
+ 00:00:00.000 --> 00:00:03.000 D:vertical A:start
29
30
  I grew up in Eastern North Carolina, <b>Edgecombe</b> County
30
31
 
31
32
  2
@@ -40,7 +41,7 @@ You can do the following:
40
41
  require 'webvtt'
41
42
  vtt = Webvtt::File.new('path/to/file.vtt')
42
43
  vtt.cues.class #=> Webvtt::Cue
43
- vtt.cues[0].start #=> '00:00:00'
44
+ vtt.cues[0].start #=> '00:00:00.000'
44
45
  vtt.cues[0].end #=> '00:00:03.000'
45
46
  vtt.cues[0].identifier #=> '1'
46
47
  vtt.cues[0].settings #=> 'D:vertical A:start'
data/lib/webvtt/file.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module Webvtt
3
3
  class File
4
4
 
5
- attr_accessor :file, :cues
5
+ attr_accessor :file, :cues, :header_lines
6
6
 
7
7
  def initialize(input_file)
8
8
  if input_file.is_a?(String)
@@ -18,6 +18,7 @@ module Webvtt
18
18
  raise
19
19
  end
20
20
  @cues = []
21
+ @header_lines = []
21
22
  parse
22
23
  end
23
24
 
@@ -26,24 +27,34 @@ module Webvtt
26
27
  if !webvtt_line?(file.lines.first)
27
28
  raise Webvtt::MalformedError
28
29
  end
30
+ in_header = true
29
31
  collected_lines = []
30
32
  file_lines = file.dup.lines.to_a
31
33
 
32
34
  file_lines.each_with_index do |line,index|
33
35
  line.chomp!
34
-
35
- next if webvtt_line?(line)
36
+
37
+ if webvtt_line?(line)
38
+ next
39
+ end
36
40
  if line.empty?
37
- if !collected_lines.empty? and !notes?(collected_lines)
38
- add_a_cue(collected_lines)
41
+ # If the line is empty then we can't be in the header anymore.
42
+ if in_header
43
+ in_header = false
44
+ else
45
+ if !collected_lines.empty? and !notes?(collected_lines)
46
+ add_a_cue(collected_lines)
47
+ end
48
+ collected_lines = []
39
49
  end
40
- collected_lines = []
41
- elsif !line.empty? and file_lines.length == (index + 1)
50
+ elsif !line.empty? and file_lines.length == (index + 1) # add our last cue
42
51
  collected_lines << line
43
52
  add_a_cue(collected_lines)
53
+ elsif in_header
54
+ header_lines << line
44
55
  else
45
- collected_lines << line
46
- end
56
+ collected_lines << line
57
+ end
47
58
  end
48
59
  end
49
60
 
@@ -62,16 +73,17 @@ private
62
73
  if collected_lines.first.include?('-->')
63
74
  cue_opts[:identifier] = nil
64
75
  cue_opts[:cue_line] = collected_lines.first
76
+ cue_opts[:text] = collected_lines[1..-1].join("\n")
65
77
  elsif collected_lines[1].include?('-->')
66
78
  cue_opts[:identifier] = collected_lines.first
67
79
  cue_opts[:cue_line] = collected_lines[1]
80
+ cue_opts[:text] = collected_lines[2..-1].join("\n")
68
81
  end
69
- cue_opts[:text] = collected_lines[2..-1].join('')
70
82
  cues << Cue.new(cue_opts)
71
83
  end
72
84
 
73
85
  def notes?(collected_lines)
74
- if collected_lines.first.match(/^NOTES/)
86
+ if collected_lines.first.match(/^NOTE/)
75
87
  true
76
88
  else
77
89
  false
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Webvtt
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
data/test/cue_test.rb CHANGED
@@ -16,12 +16,12 @@ class WebvttCueTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  test "parses an individual cue" do
19
- cue = Webvtt::Cue.new(:identifier => "1", :cue_line => "00:00:00 --> 00:00:03.000 D:vertical A:start", :text => "I grew up in Eastern North Carolina, <b>Edgecombe</b> County")
19
+ cue = Webvtt::Cue.new(:identifier => "1", :cue_line => "00:00:00.000 --> 00:00:03.000 D:vertical A:start", :text => "I grew up in Eastern North Carolina, <b>Edgecombe</b> County")
20
20
  assert_equal '1', cue.identifier
21
- assert_equal '00:00:00', cue.start
21
+ assert_equal '00:00:00.000', cue.start
22
22
  assert_equal '00:00:03.000', cue.end
23
23
  assert_equal 'D:vertical A:start', cue.settings
24
24
  assert_equal 'I grew up in Eastern North Carolina, <b>Edgecombe</b> County', cue.text
25
- end
25
+ end
26
26
 
27
27
  end
@@ -0,0 +1,15 @@
1
+ WEBVTT
2
+ editor: Brian Dietz
3
+
4
+ NOTE This is a note.
5
+
6
+ 00:00:00.000 --> 00:00:03.000 D:vertical A:start
7
+ I grew up in Eastern North Carolina, <b>Edgecombe</b> County
8
+
9
+ NOTE
10
+ This is also
11
+ a note.
12
+
13
+ 00:00:03.300 --> 00:00:07.800
14
+ on a tobacco and dairy farm outside of
15
+ Tarboro.
@@ -1,16 +1,17 @@
1
1
  WEBVTT
2
+ editor: Brian Dietz
2
3
 
3
- NOTES This is a note.
4
+ NOTE This is a note.
4
5
 
5
6
  1
6
- 00:00:00 --> 00:00:03.000 D:vertical A:start
7
+ 00:00:00.000 --> 00:00:03.000 D:vertical A:start
7
8
  I grew up in Eastern North Carolina, <b>Edgecombe</b> County
8
9
 
9
- NOTES
10
+ NOTE
10
11
  This is also
11
12
  a note.
12
13
 
13
14
  2
14
15
  00:00:03.300 --> 00:00:07.800 A:start
15
- on a tobacco and dairy farm outside of
16
- Tarboro.
16
+ on a tobacco and dairy farm outside of
17
+ Tarboro.
data/test/file_test.rb CHANGED
@@ -23,12 +23,12 @@ class WebvttFileTest < Test::Unit::TestCase
23
23
 
24
24
  test "should create a new File with a String as the contents of the WEBVTT file" do
25
25
  file = "WEBVTT FILE\n\n1\n00:00:00 --> 00:00:05\nIt was a frightening time but it also was a time of great student intrigue"
26
- assert Webvtt::File.new(file)
26
+ assert Webvtt::File.new(file)
27
27
  end
28
28
 
29
29
  test "should handle files with a BOM and different line endings" do
30
30
  file = "\uFEFFWEBVTT FILE\r\n\r\n1\r\n00:00:00 --> 00:00:05\r\nIt was a frightening time but it also was a time of great student intrigue"
31
- assert Webvtt::File.new(file)
31
+ assert Webvtt::File.new(file)
32
32
  end
33
33
 
34
34
  test "should have a file method" do
@@ -39,7 +39,7 @@ class WebvttFileTest < Test::Unit::TestCase
39
39
  assert @vtt.file.include?('WEBVTT')
40
40
  end
41
41
 
42
- test "should have a list of cues" do
42
+ test "should have a list of cues" do
43
43
  assert @vtt.respond_to?(:cues)
44
44
  assert @vtt.cues.is_a?(Array)
45
45
  end
@@ -51,14 +51,14 @@ class WebvttFileTest < Test::Unit::TestCase
51
51
  test "first cue should be correct" do
52
52
  first_cue = @vtt.cues.first
53
53
  assert_equal "1", first_cue.identifier
54
- assert_equal "00:00:00", first_cue.start
54
+ assert_equal "00:00:00.000", first_cue.start
55
55
  assert_equal "00:00:03.000", first_cue.end
56
56
  assert_equal "D:vertical A:start", first_cue.settings
57
57
  assert_equal "I grew up in Eastern North Carolina, <b>Edgecombe</b> County", first_cue.text
58
58
  end
59
59
 
60
60
  test "multiline cue text should be correct" do
61
- assert_equal "on a tobacco and dairy farm outside of Tarboro.", @vtt.cues.last.text
61
+ assert_equal "on a tobacco and dairy farm outside of\nTarboro.", @vtt.cues.last.text
62
62
  end
63
63
 
64
- end
64
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class WebvttNoIdentifierFileTest < Test::Unit::TestCase
4
+
5
+ setup do
6
+ path = File.expand_path(File.dirname(__FILE__))
7
+ @file_path = File.join(path, 'examples', 'no-identifier.vtt')
8
+ @vtt = Webvtt::File.new(@file_path)
9
+ end
10
+
11
+ test "first cue with no identifier should be correct" do
12
+ first_cue = @vtt.cues.first
13
+ assert_equal nil, first_cue.identifier
14
+ assert_equal "00:00:00.000", first_cue.start
15
+ assert_equal "00:00:03.000", first_cue.end
16
+ assert_equal "D:vertical A:start", first_cue.settings
17
+ assert_equal "I grew up in Eastern North Carolina, <b>Edgecombe</b> County", first_cue.text
18
+ end
19
+
20
+ test "second cue with no identifier and no settings should be correct" do
21
+ last_cue = @vtt.cues.last
22
+ assert_equal nil, last_cue.identifier
23
+ assert_equal "00:00:03.300", last_cue.start
24
+ assert_equal "00:00:07.800", last_cue.end
25
+ assert_equal "", last_cue.settings
26
+ assert_equal "on a tobacco and dairy farm outside of\nTarboro.", last_cue.text
27
+ end
28
+
29
+ end
data/test/test_helper.rb CHANGED
@@ -2,4 +2,4 @@
2
2
  require 'rubygems'
3
3
  require 'test-unit'
4
4
  require 'webvtt'
5
-
5
+ require 'byebug'
data/webvtt.gemspec CHANGED
@@ -5,9 +5,10 @@ require "webvtt/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "webvtt"
7
7
  s.version = Webvtt::VERSION
8
+ s.licenses = ['MIT']
8
9
  s.authors = ["Jason Ronallo"]
9
10
  s.email = ["jronallo@gmail.com"]
10
- s.homepage = ""
11
+ s.homepage = "https://github.com/jronallo/webvtt"
11
12
  s.summary = %q{WEBVTT file parser in Ruby}
12
13
  s.description = %q{WEBVTT file parser in Ruby}
13
14
 
@@ -19,4 +20,5 @@ Gem::Specification.new do |s|
19
20
  s.require_paths = ["lib"]
20
21
  s.add_development_dependency "test-unit", [">= 2.5.0"]
21
22
  s.add_development_dependency "guard-test", [">= 0.5.0"]
23
+ s.add_development_dependency "byebug"
22
24
  end
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webvtt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jason Ronallo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-17 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: test-unit
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.5.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.5.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: guard-test
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.5.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
46
55
  description: WEBVTT file parser in Ruby
47
56
  email:
48
57
  - jronallo@gmail.com
@@ -50,7 +59,8 @@ executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - .gitignore
62
+ - ".gitignore"
63
+ - ".travis.yml"
54
64
  - Gemfile
55
65
  - Guardfile
56
66
  - LICENSE
@@ -61,38 +71,33 @@ files:
61
71
  - lib/webvtt/file.rb
62
72
  - lib/webvtt/version.rb
63
73
  - test/cue_test.rb
74
+ - test/examples/no-identifier.vtt
64
75
  - test/examples/tolson.vtt
65
76
  - test/file_test.rb
77
+ - test/no_identifier_test.rb
66
78
  - test/test_helper.rb
67
79
  - webvtt.gemspec
68
- homepage: ''
69
- licenses: []
80
+ homepage: https://github.com/jronallo/webvtt
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
70
84
  post_install_message:
71
85
  rdoc_options: []
72
86
  require_paths:
73
87
  - lib
74
88
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
89
  requirements:
77
- - - ! '>='
90
+ - - ">="
78
91
  - !ruby/object:Gem::Version
79
92
  version: '0'
80
- segments:
81
- - 0
82
- hash: 3014810322973854166
83
93
  required_rubygems_version: !ruby/object:Gem::Requirement
84
- none: false
85
94
  requirements:
86
- - - ! '>='
95
+ - - ">="
87
96
  - !ruby/object:Gem::Version
88
97
  version: '0'
89
- segments:
90
- - 0
91
- hash: 3014810322973854166
92
98
  requirements: []
93
- rubyforge_project: webvtt
94
- rubygems_version: 1.8.24
99
+ rubygems_version: 3.0.8
95
100
  signing_key:
96
- specification_version: 3
101
+ specification_version: 4
97
102
  summary: WEBVTT file parser in Ruby
98
103
  test_files: []