webvtt-ruby 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/webvtt/parser.rb +6 -3
- data/tests/parser.rb +9 -6
- data/tests/subtitles/withstyle.vtt +20 -0
- data/webvtt-ruby.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbbc04b66c5f332c450a62d17b3729774c89ddcc1b6bf7b20f5a694316640b18
|
4
|
+
data.tar.gz: f6c00383830d0715036c276e5b22d349616f60f6b736ad071097708ad68324c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd7899626ea01d17e7137652c5cc08c9b86b153df31ee2b631dcd3d7991e759fa7a3d4e73f25b6e919942c6d685555a779e56dade82bb5a93d6e4087dd222deb
|
7
|
+
data.tar.gz: 37713680a2fe91450ca63198f48423eb7cb6805d66ebe02963457ec4ebfbf928c04632f3c4526473317652839961f1f1d96667dcafa1902a317f8b3defce77b7
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# WebVTT Ruby parser and segmenter
|
2
2
|
|
3
|
-
The [WebVTT format](
|
3
|
+
The [WebVTT format](https://www.w3.org/TR/webvtt1/) is a standard captionning format used for HTML5 videos and HTTP Live Streaming (HLS).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -30,6 +30,7 @@ webvtt.cues.each do |cue|
|
|
30
30
|
puts "End: #{cue.end}"
|
31
31
|
puts "Style: #{cue.style.inspect}"
|
32
32
|
puts "Text: #{cue.text}"
|
33
|
+
puts "Plain text: #{cue.plain_text}" # text without style tags if any
|
33
34
|
puts "--"
|
34
35
|
end
|
35
36
|
```
|
data/lib/webvtt/parser.rb
CHANGED
@@ -104,7 +104,7 @@ module WebVTT
|
|
104
104
|
end
|
105
105
|
|
106
106
|
class Cue
|
107
|
-
attr_accessor :identifier, :start, :end, :style, :text
|
107
|
+
attr_accessor :identifier, :start, :end, :style, :text, :plain_text
|
108
108
|
|
109
109
|
def initialize(cue = nil)
|
110
110
|
@content = cue
|
@@ -156,8 +156,8 @@ module WebVTT
|
|
156
156
|
def parse
|
157
157
|
lines = @content.split("\n").map(&:strip)
|
158
158
|
|
159
|
-
# it's a note, ignore
|
160
|
-
return if lines[0] =~ /NOTE/
|
159
|
+
# it's a note or style section, ignore
|
160
|
+
return if lines[0] =~ /NOTE|STYLE/
|
161
161
|
|
162
162
|
if !lines[0].include?("-->")
|
163
163
|
@identifier = lines[0]
|
@@ -175,7 +175,10 @@ module WebVTT
|
|
175
175
|
else
|
176
176
|
raise WebVTT::MalformedFile
|
177
177
|
end
|
178
|
+
|
179
|
+
|
178
180
|
@text = lines[1..-1].join("\n")
|
181
|
+
@plain_text = @text.gsub(/<.+?>/, '').strip # remove style tags from text
|
179
182
|
end
|
180
183
|
end
|
181
184
|
|
data/tests/parser.rb
CHANGED
@@ -82,6 +82,15 @@ class ParserTest < Minitest::Test
|
|
82
82
|
assert_equal "1", webvtt.cues[0].identifier
|
83
83
|
end
|
84
84
|
|
85
|
+
def test_ignore_style_and_remove_style_tag_from_cue_text
|
86
|
+
webvtt = WebVTT.read("tests/subtitles/withstyle.vtt")
|
87
|
+
assert_equal 1, webvtt.cues.size
|
88
|
+
# ignoring the first cue which is a NOTE
|
89
|
+
assert_equal "hello", webvtt.cues[0].identifier
|
90
|
+
assert_equal "Hello world.", webvtt.cues[0].plain_text
|
91
|
+
assert_equal "Hello <b>world</b>.", webvtt.cues[0].text
|
92
|
+
end
|
93
|
+
|
85
94
|
def test_timestamp_in_sec
|
86
95
|
assert_equal 60.0, WebVTT::Cue.timestamp_in_sec("00:01:00.000")
|
87
96
|
assert_equal 126.23, WebVTT::Cue.timestamp_in_sec("00:02:06.230")
|
@@ -250,10 +259,4 @@ The text should change)
|
|
250
259
|
assert_instance_of WebVTT::Cue, webvtt.cues[0]
|
251
260
|
assert_equal 15, webvtt.cues.size
|
252
261
|
end
|
253
|
-
|
254
|
-
def test_invalid_vtt_without_milliseconds
|
255
|
-
assert_raises WebVTT::MalformedFile do
|
256
|
-
vtt = WebVTT::File.new('tests/subtitles/no_milliseconds.vtt')
|
257
|
-
end
|
258
|
-
end
|
259
262
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
WEBVTT
|
2
|
+
|
3
|
+
NOTE This example is from https://www.w3.org/TR/webvtt1/#styling
|
4
|
+
|
5
|
+
STYLE
|
6
|
+
::cue {
|
7
|
+
background-image: linear-gradient(to bottom, dimgray, lightgray);
|
8
|
+
color: papayawhip;
|
9
|
+
}
|
10
|
+
|
11
|
+
NOTE comment blocks can be used between style blocks.
|
12
|
+
|
13
|
+
STYLE
|
14
|
+
::cue(b) {
|
15
|
+
color: peachpuff;
|
16
|
+
}
|
17
|
+
|
18
|
+
hello
|
19
|
+
00:00:00.000 --> 00:00:10.000
|
20
|
+
Hello <b>world</b>.
|
data/webvtt-ruby.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'webvtt-ruby'
|
3
|
-
s.version = '0.4.
|
3
|
+
s.version = '0.4.3'
|
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.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Celeste
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-11 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).
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- tests/subtitles/weird_format.vtt
|
46
46
|
- tests/subtitles/weird_format_corrected.vtt
|
47
47
|
- tests/subtitles/withnote.vtt
|
48
|
+
- tests/subtitles/withstyle.vtt
|
48
49
|
- webvtt-ruby.gemspec
|
49
50
|
homepage: https://github.com/HeyWatch/webvtt-ruby
|
50
51
|
licenses:
|