caption_crunch 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0f8b1d9f147b877698a20702ade0b5d093ae848
4
- data.tar.gz: 0c0f9b15655691f52a43f2eb8052abf64dd7c900
3
+ metadata.gz: ae3a295af13db4cba6334779f26b3a7311ea5f77
4
+ data.tar.gz: 1d137d6113eb2685e51a68ccfdda4807a8e86dd9
5
5
  SHA512:
6
- metadata.gz: 12a21b0bf104e69e3301373bc235eaa11c3665157d60c571bf300927e461d60792b87facc8e60732620006d3ba429cfd20dd3f8bccf751f9cb26f79a5c80e22d
7
- data.tar.gz: 6d4fd6420d85d7edd4261f1eae7f1cf3eaaaa7aacd527d85d35c59cb3fba37c34ded0d96a4a27c34cc078df9861ce857858b7d97719a6f99376a2ccd8affdbc0
6
+ metadata.gz: 065b3720596520b1c56d075b596521c085b9a5bb8ad1e9c0e1cae0f27c95a79b3e60817bc8cd89d8115f43a5e486ba103b0da034711cf6c992f062d47dbd281b
7
+ data.tar.gz: e20f1506f05d54ee96b5facb6b8f2df7c88e892fd27c3f42b4470d8c7b175e62cf831c5557f61b5b73e17d4a549f5dc7f5c208567a0e373408ff4bb8f99da85d
@@ -1,7 +1,7 @@
1
1
  module CaptionCrunch
2
2
  module Adapters
3
3
  class VTT
4
- SIGNATURE_REGEX = /\AWEBVTT\Z|\AWEBVTT[ \t]/.freeze
4
+ SIGNATURE_REGEX = /\AWEBVTT\Z|\AWEBVTT[ \t\n]/.freeze
5
5
  COMMENT_REGEX = /\ANOTE\Z|\ANOTE[ \t\n]/.freeze
6
6
  ARROW_REGEX = /-->/.freeze
7
7
  # Format: hour:minute:second.milliseconds
@@ -35,11 +35,15 @@ module CaptionCrunch
35
35
  # Returns a string corresponding to the contents of a File instance.
36
36
  # Alternatively, if the argument is not a File, simply calls `.to_s`.
37
37
  def read_file(file)
38
- if file.respond_to?(:read)
38
+ contents = if file.respond_to?(:read)
39
39
  file.read
40
40
  else
41
41
  file.to_s
42
- end.strip
42
+ end
43
+
44
+ raise ParseError, "Invalid encoding" unless contents.valid_encoding?
45
+
46
+ contents.strip
43
47
  end
44
48
 
45
49
  def remove_bom(string)
@@ -1,3 +1,3 @@
1
1
  module CaptionCrunch
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -38,6 +38,15 @@ describe 'CaptionCrunch' do
38
38
  end
39
39
  end
40
40
 
41
+ describe 'parsing a binary file' do
42
+ it 'should raise a ParseError' do
43
+ error = ->{
44
+ CaptionCrunch.parse(fixture('binary.jpg'))
45
+ }.must_raise CaptionCrunch::ParseError
46
+ error.message.must_match /Invalid encoding/
47
+ end
48
+ end
49
+
41
50
  describe 'parsing a track with three cues' do
42
51
  subject { CaptionCrunch.parse(fixture('three_cues.vtt')) }
43
52
  it 'should return an object with three cues' do
@@ -139,5 +148,14 @@ describe 'CaptionCrunch' do
139
148
  end
140
149
  end
141
150
 
151
+ describe 'parsing with metadata headers' do
152
+ subject{ CaptionCrunch.parse(fixture('metadata_headers.vtt')) }
153
+
154
+ it 'should ignore them for now and parse cues' do
155
+ subject.cues.count.must_equal 1
156
+ subject.cues.first.payload.must_equal "Hey. I have metadata headers."
157
+ end
158
+ end
159
+
142
160
  end
143
161
  end
Binary file
@@ -0,0 +1,6 @@
1
+ WEBVTT
2
+ Kind: captions
3
+ Language: en
4
+
5
+ 00:00:06.000 --> 00:00:08.921
6
+ Hey. I have metadata headers.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caption_crunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Peter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-13 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,6 +87,8 @@ files:
87
87
  - lib/caption_crunch/track.rb
88
88
  - lib/caption_crunch/version.rb
89
89
  - spec/caption_crunch_spec.rb
90
+ - spec/fixtures/binary.jpg
91
+ - spec/fixtures/metadata_headers.vtt
90
92
  - spec/fixtures/three_cues.vtt
91
93
  - spec/spec_helper.rb
92
94
  homepage: ''
@@ -115,5 +117,7 @@ specification_version: 4
115
117
  summary: A collection of parsers for various caption/subtitle files
116
118
  test_files:
117
119
  - spec/caption_crunch_spec.rb
120
+ - spec/fixtures/binary.jpg
121
+ - spec/fixtures/metadata_headers.vtt
118
122
  - spec/fixtures/three_cues.vtt
119
123
  - spec/spec_helper.rb