webvtt-ruby 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 750601959beae93666af734645757e22a9f8fe2d
4
- data.tar.gz: ce85964a436d8459dc409503ff61e8ae12ba33b3
3
+ metadata.gz: e0ecae0ceefe5452aa14107dcb45c892ff9d02a6
4
+ data.tar.gz: 173216b97d99db10103bc59207916ac5474748d8
5
5
  SHA512:
6
- metadata.gz: 9d4c6238c8c843bb83955db872f2b7ad51281e64074e8c1beecb30e9fb1ef930e4f0344d1db7e4243c63f5625b6c575d3d55947d8c8555887a2fcf19ea380081
7
- data.tar.gz: f250cac70bf7c1a534f518ca013fe04c8a7d422686d8cb7439ff3621b4410d35b2aab69f7ed3456c2ed7a8db25c8ca2c0e0dd4ce032297e2eedfeddde48680f4
6
+ metadata.gz: 252d353160e8055adf98277d1c581cec2d13d975be165a8ec7108b10574606173e71946f670242c71def21e7f5a8eab7487834c0bcd06612f4f4b1c95d1b8c77
7
+ data.tar.gz: dcb306b34ac391d51bcdec9ad9677a7cef97c6aa699a3b4cbf620b699d213f05f1960f839bc811752d96fd25784960f7291633dbd02cdf0d43683834ee277b16
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webvtt-ruby (0.2.5)
4
+ webvtt-ruby (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,5 +9,5 @@ module WebVTT
9
9
  class InputError < RuntimeError; end
10
10
  end
11
11
 
12
- require "parser"
13
- require "segmenter"
12
+ require "webvtt/parser"
13
+ require "webvtt/segmenter"
@@ -72,7 +72,7 @@ module WebVTT
72
72
 
73
73
  @cues = []
74
74
  cues.each do |cue|
75
- cue_parsed = Cue.new(cue.strip)
75
+ cue_parsed = Cue.parse(cue.strip)
76
76
  if !cue_parsed.text.nil?
77
77
  @cues << cue_parsed
78
78
  end
@@ -84,9 +84,15 @@ module WebVTT
84
84
  class Cue
85
85
  attr_accessor :identifier, :start, :end, :style, :text
86
86
 
87
- def initialize(cue)
87
+ def initialize(cue = nil)
88
88
  @content = cue
89
- parse
89
+ @style = {}
90
+ end
91
+
92
+ def self.parse(cue)
93
+ cue = Cue.new(cue)
94
+ cue.parse
95
+ return cue
90
96
  end
91
97
 
92
98
  def to_webvtt
@@ -136,6 +142,10 @@ module WebVTT
136
142
  lines.shift
137
143
  end
138
144
 
145
+ if lines.empty?
146
+ return
147
+ end
148
+
139
149
  if lines[0].match(/([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}) -+> ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3})(.*)/)
140
150
  @start = Timestamp.new $1
141
151
  @end = Timestamp.new $2
@@ -156,7 +156,7 @@ The text should change)
156
156
  end
157
157
 
158
158
  def test_cue_offset_by
159
- cue = WebVTT::Cue.new <<-CUE
159
+ cue = WebVTT::Cue.parse <<-CUE
160
160
  00:00:01.000 --> 00:00:25.432
161
161
  Test Cue
162
162
  CUE
@@ -195,4 +195,19 @@ The text should change)
195
195
  assert_equal "03:39:34.008", ts3.to_s
196
196
  end
197
197
 
198
+ def test_build_cue
199
+ cue = WebVTT::Cue.new
200
+ cue.start = WebVTT::Timestamp.new 0
201
+ cue.end = WebVTT::Timestamp.new 12
202
+ cue.text = "Built from scratch"
203
+ output = ""
204
+ output << "00:00:00.000 --> 00:00:12.000\n"
205
+ output << "Built from scratch"
206
+ assert_equal output, cue.to_webvtt
207
+ end
208
+
209
+ def test_invalid_cue
210
+ webvtt = WebVTT.convert_from_srt("tests/subtitles/invalid_cue.srt")
211
+ assert_equal 1, webvtt.cues.size
212
+ end
198
213
  end
@@ -0,0 +1,5 @@
1
+ 1
2
+ 00:00:30,828 --> 00:00:34,894
3
+
4
+ Captain Phillips (2013)
5
+
@@ -0,0 +1,6 @@
1
+ WEBVTT
2
+
3
+ 1
4
+ 00:00:30.828 --> 00:00:34.894
5
+
6
+ Captain Phillips (2013)
@@ -6,4 +6,4 @@ Elephant's Dream
6
6
 
7
7
  2
8
8
  00:00:15.000 --> 00:00:18.000
9
- At the left we can see...
9
+ At the left we can see...
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'webvtt-ruby'
3
- s.version = '0.3.0'
3
+ s.version = '0.3.2'
4
4
  s.summary = "WebVTT parser and segmenter in ruby"
5
5
  s.description = "WebVTT parser and segmenter in ruby for HTML5 and HTTP Live Streaming (HLS)."
6
6
  s.authors = ["Bruno Celeste"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webvtt-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Celeste
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-15 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: WebVTT parser and segmenter in ruby for HTML5 and HTTP Live Streaming
14
14
  (HLS).
@@ -24,13 +24,15 @@ files:
24
24
  - LICENSE
25
25
  - README.md
26
26
  - bin/webvtt-segmenter
27
- - lib/parser.rb
28
- - lib/segmenter.rb
29
27
  - lib/webvtt.rb
28
+ - lib/webvtt/parser.rb
29
+ - lib/webvtt/segmenter.rb
30
30
  - tests/parser.rb
31
31
  - tests/segmenter.rb
32
32
  - tests/subtitles/big_srt.srt
33
33
  - tests/subtitles/big_srt.vtt
34
+ - tests/subtitles/invalid_cue.srt
35
+ - tests/subtitles/invalid_cue.vtt
34
36
  - tests/subtitles/no_text.vtt
35
37
  - tests/subtitles/notvalid.vtt
36
38
  - tests/subtitles/test.vtt