srt 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'srt'
3
+
4
+ describe SRT::Line do
5
+ describe "#new" do
6
+ let(:line) { SRT::Line.new }
7
+
8
+ it "should create an empty subtitle" do
9
+ line.should be_empty
10
+ end
11
+ end
12
+
13
+ describe "#time_str" do
14
+ let(:line) { SRT::Line.new }
15
+
16
+ before do
17
+ line.start_time = 224.2
18
+ line.end_time = 244.578
19
+ end
20
+
21
+ it "should produce timecodes that match the internal float values" do
22
+ line.time_str.should eq("00:03:44,200 --> 00:04:04,578")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'srt'
3
+
4
+ describe SRT::Parser do
5
+ subject { described_class }
6
+
7
+ describe ".id" do
8
+ it "should convert the id string (#[id]) to an int representing the sequence number" do
9
+ subject.id("#317").should eq(317)
10
+ end
11
+ end
12
+
13
+ describe ".timecode" do
14
+ it "should convert the SRT timecode format to a float representing seconds" do
15
+ subject.timecode("01:03:44,200").should eq(3824.2)
16
+ end
17
+ end
18
+
19
+ describe ".timespan" do
20
+ it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
21
+ subject.timespan("-3.5m").should eq(-210)
22
+ end
23
+
24
+ it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
25
+ subject.timespan("-1s").should eq(-1)
26
+ end
27
+
28
+ it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
29
+ subject.timespan("100ms").should eq(0.1)
30
+ end
31
+ end
32
+
33
+ describe ".parse_framerate" do
34
+ it "should convert a framerate string ([number]fps) to a float representing seconds" do
35
+ subject.framerate("23.976fps").should eq(23.976)
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Christopher Petersen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
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
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
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
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: coveralls
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -76,53 +69,51 @@ files:
76
69
  - lib/srt.rb
77
70
  - lib/srt/file.rb
78
71
  - lib/srt/line.rb
72
+ - lib/srt/parser.rb
79
73
  - lib/srt/version.rb
80
- - spec/blackswan-part1.srt
81
- - spec/blackswan-part2.srt
82
- - spec/bsg-s01e01.srt
83
- - spec/coordinates-dummy.srt
84
- - spec/invalid.srt
74
+ - spec/file_spec.rb
75
+ - spec/fixtures/blackswan-part1.srt
76
+ - spec/fixtures/blackswan-part2.srt
77
+ - spec/fixtures/bsg-s01e01.srt
78
+ - spec/fixtures/coordinates-dummy.srt
79
+ - spec/fixtures/invalid.srt
80
+ - spec/fixtures/wotw-dubious.srt
81
+ - spec/line_spec.rb
82
+ - spec/parser_spec.rb
85
83
  - spec/spec_helper.rb
86
- - spec/srt_spec.rb
87
- - spec/wotw-dubious.srt
88
84
  - srt.gemspec
89
85
  homepage: https://github.com/cpetersen/srt
90
86
  licenses:
91
87
  - MIT
88
+ metadata: {}
92
89
  post_install_message:
93
90
  rdoc_options: []
94
91
  require_paths:
95
92
  - lib
96
93
  required_ruby_version: !ruby/object:Gem::Requirement
97
- none: false
98
94
  requirements:
99
95
  - - ! '>='
100
96
  - !ruby/object:Gem::Version
101
97
  version: '0'
102
- segments:
103
- - 0
104
- hash: -409618731676582618
105
98
  required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
99
  requirements:
108
100
  - - ! '>='
109
101
  - !ruby/object:Gem::Version
110
102
  version: '0'
111
- segments:
112
- - 0
113
- hash: -409618731676582618
114
103
  requirements: []
115
104
  rubyforge_project:
116
- rubygems_version: 1.8.23
105
+ rubygems_version: 2.2.1
117
106
  signing_key:
118
- specification_version: 3
107
+ specification_version: 4
119
108
  summary: Ruby gem for parsing subtitle files.
120
109
  test_files:
121
- - spec/blackswan-part1.srt
122
- - spec/blackswan-part2.srt
123
- - spec/bsg-s01e01.srt
124
- - spec/coordinates-dummy.srt
125
- - spec/invalid.srt
110
+ - spec/file_spec.rb
111
+ - spec/fixtures/blackswan-part1.srt
112
+ - spec/fixtures/blackswan-part2.srt
113
+ - spec/fixtures/bsg-s01e01.srt
114
+ - spec/fixtures/coordinates-dummy.srt
115
+ - spec/fixtures/invalid.srt
116
+ - spec/fixtures/wotw-dubious.srt
117
+ - spec/line_spec.rb
118
+ - spec/parser_spec.rb
126
119
  - spec/spec_helper.rb
127
- - spec/srt_spec.rb
128
- - spec/wotw-dubious.srt
@@ -1,498 +0,0 @@
1
- require 'spec_helper'
2
- require 'srt'
3
-
4
- describe SRT do
5
- describe SRT::Line do
6
- describe "#new" do
7
- let(:line) { SRT::Line.new }
8
-
9
- it "should create an empty subtitle" do
10
- line.should be_empty
11
- end
12
- end
13
-
14
- describe "#time_str" do
15
- let(:line) { SRT::Line.new }
16
-
17
- before do
18
- line.start_time = 224.2
19
- line.end_time = 244.578
20
- end
21
-
22
- it "should produce timecodes that match the internal float values" do
23
- line.time_str.should eq("00:03:44,200 --> 00:04:04,578")
24
- end
25
- end
26
- end
27
-
28
- describe SRT::File do
29
- describe '#parse' do
30
- context "parsing with debug true" do
31
- it "should be verbose when failing" do
32
- $stderr.should_receive(:puts).once
33
- SRT::File.parse(File.open("./spec/invalid.srt"), debug: true).errors.should_not be_empty
34
- end
35
- end
36
- context "parsing with debug false" do
37
- it "should raise exception silently" do
38
- $stderr.should_not_receive(:puts)
39
- SRT::File.parse(File.open("./spec/invalid.srt")).errors.should_not be_empty
40
- end
41
- end
42
- end
43
-
44
- describe ".parse_id" do
45
- it "should convert the id string (#[id]) to an int representing the sequence number" do
46
- SRT::File.parse_id("#317").should eq(317)
47
- end
48
- end
49
-
50
- describe ".parse_timecode" do
51
- it "should convert the SRT timecode format to a float representing seconds" do
52
- SRT::File.parse_timecode("01:03:44,200").should eq(3824.2)
53
- end
54
- end
55
-
56
- describe ".parse_timespan" do
57
- it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
58
- SRT::File.parse_timespan("-3.5m").should eq(-210)
59
- end
60
-
61
- it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
62
- SRT::File.parse_timespan("-1s").should eq(-1)
63
- end
64
-
65
- it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
66
- SRT::File.parse_timespan("100ms").should eq(0.1)
67
- end
68
- end
69
-
70
- describe ".parse_framerate" do
71
- it "should convert a framerate string ([number]fps) to a float representing seconds" do
72
- SRT::File.parse_framerate("23.976fps").should eq(23.976)
73
- end
74
- end
75
-
76
- shared_examples_for "an SRT file" do
77
- context "when parsing a properly formatted BSG SRT file" do
78
- it "should return an SRT::File" do
79
- subject.class.should eq(SRT::File)
80
- end
81
-
82
- it "should have 600 lines" do
83
- subject.lines.size.should eq(600)
84
- end
85
-
86
- it "should have no errors" do
87
- subject.errors.should be_empty
88
- end
89
-
90
- it "should have the expected sequence number on the first subtitle" do
91
- subject.lines.first.sequence.should eq(1)
92
- end
93
-
94
- it "should have the expected timecodes on the first subtitle" do
95
- subject.lines.first.time_str.should eq("00:00:02,110 --> 00:00:04,578")
96
- end
97
-
98
- it "should have the expected text on the first subtitle" do
99
- subject.lines.first.text.should eq(["<i>(male narrator) Previously", "on Battlestar Galactica.</i>"])
100
- end
101
-
102
- it "should have the expected sequence number on the last subtitle" do
103
- subject.lines.last.sequence.should eq(600)
104
- end
105
-
106
- it "should have the expected timecodes on the last subtitle" do
107
- subject.lines.last.time_str.should eq("00:43:26,808 --> 00:43:28,139")
108
- end
109
-
110
- it "should have the expected text on the last subtitle" do
111
- subject.lines.last.text.should eq(["Thank you."])
112
- end
113
- end
114
- end
115
-
116
- describe ".parse with uncommon formats" do
117
- context "when parsing a spanish language WOTW SRT file with unknown encoding" do
118
- let(:file) { SRT::File.parse(File.open("./spec/wotw-dubious.srt")) }
119
-
120
- it "should parse" do
121
- file.class.should eq(SRT::File)
122
- end
123
-
124
- it "should have 1123 lines" do
125
- file.lines.size.should eq(1123)
126
- end
127
-
128
- it "should have no errors" do
129
- file.errors.should be_empty
130
- end
131
- end
132
-
133
- context "when parsing a dummy SRT file containing display coordinates" do
134
- let(:file) { SRT::File.parse(File.open("./spec/coordinates-dummy.srt")) }
135
-
136
- it "should return an SRT::File" do
137
- file.class.should eq(SRT::File)
138
- end
139
-
140
- it "should have 3 lines" do
141
- file.lines.size.should eq(3)
142
- end
143
-
144
- it "should have no errors" do
145
- file.errors.should be_empty
146
- end
147
-
148
- it "should have the expected display coordinates on the first subtitle" do
149
- file.lines.first.display_coordinates.should eq("X1:100 X2:600 Y1:1 Y2:4")
150
- end
151
-
152
- it "should have the expected display coordinates on the last subtitle" do
153
- file.lines.last.display_coordinates.should eq("X1:1 X2:333 Y1:50 Y2:29")
154
- end
155
- end
156
- end
157
-
158
- describe SRT::File, "when initialized with a valid BSG SRT string" do
159
- subject { SRT::File.parse(File.read("./spec/bsg-s01e01.srt")) }
160
- it_should_behave_like "an SRT file"
161
- end
162
-
163
- describe SRT::File, "when initialized with a valid BSG SRT File" do
164
- subject { SRT::File.parse(File.open("./spec/bsg-s01e01.srt")) }
165
- it_should_behave_like "an SRT file"
166
- end
167
-
168
- describe "#append" do
169
- context "when calling it on the first (part1) of two seperate SRT files for Black Swan" do
170
- let(:part1) { SRT::File.parse(File.open("./spec/blackswan-part1.srt")) }
171
- let(:part2) { SRT::File.parse(File.open("./spec/blackswan-part2.srt")) }
172
-
173
- context "when passing { \"00:53:57,241\" => part2 }" do
174
- before { part1.append({ "00:53:57,241" => part2 }) }
175
-
176
- it "should have grown to 808 subtitles" do
177
- part1.lines.length.should eq(808)
178
- end
179
-
180
- it "should have appended subtitles starting with sequence number 448" do
181
- part1.lines[447].sequence.should eq(448)
182
- end
183
-
184
- it "should have appended subtitles ending with sequence number 808" do
185
- part1.lines.last.sequence.should eq(808)
186
- end
187
-
188
- it "should have appended subtitles relatively from 00:53:57,241" do
189
- part1.lines[447].time_str.should eq("00:54:02,152 --> 00:54:04,204")
190
- end
191
- end
192
-
193
- context "when passing { \"+7.241s\" => part2 }" do
194
- before { part1.append({ "+7.241s" => part2 }) }
195
-
196
- it "should have appended subtitles relatively from +7.241s after the previously last subtitle" do
197
- part1.lines[447].time_str.should eq("00:54:02,283 --> 00:54:04,335")
198
- end
199
- end
200
- end
201
- end
202
-
203
- describe "#split" do
204
- context "when calling it on a properly formatted BSG SRT file" do
205
- let(:file) { SRT::File.parse(File.open("./spec/bsg-s01e01.srt")) }
206
-
207
- context "when passing { :at => \"00:19:24,500\" }" do
208
- let(:result) { file.split( :at => "00:19:24,500" ) }
209
-
210
- it "should return an array containing two SRT::File instances" do
211
- result.length.should eq(2)
212
- result[0].class.should eq(SRT::File)
213
- result[1].class.should eq(SRT::File)
214
- end
215
-
216
- it "should include a subtitle that overlaps a splitting point in the first file" do
217
- result[0].lines.last.text.should eq(["I'll see you guys in combat."])
218
- end
219
-
220
- it "should make an overlapping subtitle end at the splitting point in the first file" do
221
- result[0].lines.last.time_str.should eq("00:19:23,901 --> 00:19:24,500")
222
- end
223
-
224
- it "should include a subtitle that overlaps a splitting point in the second file as well" do
225
- result[1].lines.first.text.should eq(["I'll see you guys in combat."])
226
- end
227
-
228
- it "should make an overlapping subtitle remain at the beginning in the second file" do
229
- result[1].lines.first.time_str.should eq("00:00:00,000 --> 00:00:01,528")
230
- end
231
-
232
- it "should shift back all timecodes of the second file relative to the new file beginning" do
233
- result[1].lines[1].time_str.should eq("00:00:01,737 --> 00:00:03,466")
234
- end
235
- end
236
-
237
- context "when passing { :at => \"00:19:24,500\", :timeshift => false }" do
238
- let(:result) { file.split( :at => "00:19:24,500", :timeshift => false ) }
239
-
240
- it "should return an array containing two SRT::File instances" do
241
- result.length.should eq(2)
242
- result[0].class.should eq(SRT::File)
243
- result[1].class.should eq(SRT::File)
244
- end
245
-
246
- it "should include a subtitle that overlaps a splitting point in the first file" do
247
- result[0].lines.last.text.should eq(["I'll see you guys in combat."])
248
- end
249
-
250
- it "should not make an overlapping subtitle end at the splitting point in the first file" do
251
- result[0].lines.last.time_str.should eq("00:19:23,901 --> 00:19:26,028")
252
- end
253
-
254
- it "should include a subtitle that overlaps a splitting point in the second file as well" do
255
- result[1].lines.first.text.should eq(["I'll see you guys in combat."])
256
- end
257
-
258
- it "should not make an overlapping subtitle remain at the beginning in the second file" do
259
- result[1].lines.first.time_str.should eq("00:19:23,901 --> 00:19:26,028")
260
- end
261
-
262
- it "should not shift back timecodes of the second file relative to the new file beginning" do
263
- result[1].lines[1].time_str.should eq("00:19:26,237 --> 00:19:27,966")
264
- end
265
- end
266
-
267
- context "when passing { :at => [\"00:15:00,000\", \"00:30:00,000\"] }" do
268
- let(:result) { file.split( :at => ["00:15:00,000", "00:30:00,000"] ) }
269
-
270
- it "should return an array containing three SRT::File instances" do
271
- result.length.should eq(3)
272
- result[0].class.should eq(SRT::File)
273
- result[1].class.should eq(SRT::File)
274
- result[2].class.should eq(SRT::File)
275
- end
276
-
277
- it "should let subtitles start at sequence number #1 in all three files" do
278
- result[0].lines.first.sequence.should eq(1)
279
- result[1].lines.first.sequence.should eq(1)
280
- result[2].lines.first.sequence.should eq(1)
281
- end
282
-
283
- it "should put 176 subtitles in the first file" do
284
- result[0].lines.length.should eq(176)
285
- result[0].lines.last.sequence.should eq(176)
286
- end
287
-
288
- it "should put 213 subtitles in the second file" do
289
- result[1].lines.length.should eq(213)
290
- result[1].lines.last.sequence.should eq(213)
291
- end
292
-
293
- it "should put 212 subtitles in the third file" do
294
- result[2].lines.length.should eq(212)
295
- result[2].lines.last.sequence.should eq(212)
296
- end
297
- end
298
-
299
- context "when passing { :at => \"00:19:24,500\", :every => \"00:00:01,000\" }" do
300
- let(:result) { file.split( :at => "00:19:24,500", :every => "00:00:01,000" ) }
301
-
302
- it "should return an array containing two SRT::File instances, ignoring :every" do
303
- result.length.should eq(2)
304
- result[0].class.should eq(SRT::File)
305
- result[1].class.should eq(SRT::File)
306
- end
307
- end
308
-
309
- context "when passing { :every => \"00:05:00,000\" }" do
310
- let(:result) { file.split( :every => "00:05:00,000" ) }
311
-
312
- it "should return an array containing nine SRT::File instances" do
313
- result.length.should eq(9)
314
- (0...result.count).each do |n|
315
- result[n].class.should eq(SRT::File)
316
- end
317
- end
318
- end
319
-
320
- context "when passing { :at => \"00:19:24,500\", :renumber => false }" do
321
- let(:result) { file.split( :at => "00:19:24,500", :renumber => false ) }
322
-
323
- it "sequence for the last line of first part should be the sequence for the first line of second part" do
324
- result[0].lines.last.text.should == result[1].lines.first.text
325
- result[0].lines.last.sequence.should == result[1].lines.first.sequence
326
- end
327
- end
328
-
329
- context "when passing { :at => \"00:19:24,500\", :renumber => true }" do
330
- let(:result) { file.split( :at => "00:19:24,500", :renumber => true ) }
331
-
332
- it "first line of second part's number should be one" do
333
- result[1].lines.first.sequence.should == 1
334
- end
335
-
336
- it "sequence for the last line of first part should have different number than the sequence for the first line of second part" do
337
- result[0].lines.last.text.should == result[1].lines.first.text
338
- result[0].lines.last.sequence.should_not == result[1].lines.first.sequence
339
- end
340
- end
341
-
342
- context "when passing { :at => \"00:19:24,500\", :timeshift => false }" do
343
- let(:result) { file.split( :at => "00:19:24,500", :timeshift => false ) }
344
-
345
- it "time for last line of first part should be the time for first line of second part" do
346
- result[0].lines.last.text.should == result[1].lines.first.text
347
- result[0].lines.last.time_str.should == result[1].lines.first.time_str
348
- end
349
- end
350
-
351
- context "when passing { :at => \"00:19:24,500\", :timeshift => true }" do
352
- let(:result) { file.split( :at => "00:19:24,500", :timeshift => true ) }
353
-
354
- it "start_time of first line in second part should be 0" do
355
- result[1].lines.first.start_time.should == 0
356
- end
357
-
358
- it "time for last line of first part should not be the time for first line of second part" do
359
- result[0].lines.last.text.should == result[1].lines.first.text
360
- result[0].lines.last.time_str.should_not == result[1].lines.first.time_str
361
- end
362
- end
363
- end
364
- end
365
-
366
- describe "#timeshift" do
367
- context "when calling it on a properly formatted BSG SRT file" do
368
- let(:file) { SRT::File.parse(File.open("./spec/bsg-s01e01.srt")) }
369
-
370
- context "when passing { :all => \"+2.5s\" }" do
371
- before { file.timeshift({ :all => "+2.5s" }) }
372
-
373
- it "should have timecodes shifted forward by 2.5s for subtitle #24" do
374
- file.lines[23].time_str.should eq("00:01:59,291 --> 00:02:00,815")
375
- end
376
-
377
- it "should have timecodes shifted forward by 2.5s for subtitle #43" do
378
- file.lines[42].time_str.should eq("00:03:46,164 --> 00:03:47,631")
379
- end
380
- end
381
-
382
- context "when passing { \"25fps\" => \"23.976fps\" }" do
383
- before { file.timeshift({ "25fps" => "23.976fps" }) }
384
-
385
- it "should have correctly scaled timecodes for subtitle #24" do
386
- file.lines[23].time_str.should eq("00:01:52,007 --> 00:01:53,469")
387
- end
388
-
389
- it "should have correctly scaled timecodes for subtitle #43" do
390
- file.lines[42].time_str.should eq("00:03:34,503 --> 00:03:35,910")
391
- end
392
- end
393
-
394
- context "when passing { \"#24\" => \"00:03:53,582\", \"#42\" => \"00:04:24,656\" }" do
395
- before { file.timeshift({ "#24" => "00:03:53,582", "#42" => "00:04:24,656" }) }
396
-
397
- it "should have shifted timecodes for subtitle #24" do
398
- file.lines[23].time_str.should eq("00:03:53,582 --> 00:03:54,042")
399
- end
400
-
401
- it "should have differently shifted timecodes for subtitle #43" do
402
- file.lines[41].time_str.should eq("00:04:24,656 --> 00:04:25,298")
403
- end
404
- end
405
-
406
- context "when passing { 180 => \"+1s\", 264 => \"+1.5s\" }" do
407
- before { file.timeshift({ 180 => "+1s", 264 => "+1.5s" }) }
408
-
409
- it "should have shifted by +1s at 180 seconds" do
410
- file.lines[23].time_str.should eq("00:01:57,415 --> 00:01:58,948")
411
- end
412
-
413
- it "should have shifted by +1.5s at 264 seconds" do
414
- file.lines[41].time_str.should eq("00:03:40,997 --> 00:03:43,136")
415
- end
416
- end
417
- end
418
-
419
- context "when calling it on a spanish language WOTW SRT file with unknown encoding" do
420
- let(:file) { SRT::File.parse(File.open("./spec/wotw-dubious.srt")) }
421
-
422
- context "when passing { :all => \"-2.7m\" }" do
423
- before { file.timeshift({ :all => "-2.7m" }) }
424
-
425
- it "should have dumped 16 lines with now negative timecodes, leaving 1107" do
426
- file.lines.size.should eq(1107)
427
- end
428
- end
429
-
430
- context "when passing { \"00:03:25,430\" => \"00:00:44,200\", \"01:49:29,980\" => \"01:46:35,600\" }" do
431
- before { file.timeshift({ "00:03:25,430" => "00:00:44,200", "01:49:29,980" => "01:46:35,600" }) }
432
-
433
- it "should have dumped 16 lines with now negative timecodes, leaving 1107" do
434
- file.lines.size.should eq(1107)
435
- end
436
- end
437
- end
438
-
439
- describe "#to_s" do
440
- context "when calling it on a short SRT file" do
441
- let(:file) { SRT::File.parse(File.open("./spec/bsg-s01e01.srt")) }
442
-
443
- before { file.lines = file.lines[0..2] }
444
-
445
- it "should produce the exactly correct output" do
446
- OUTPUT =<<END
447
- 1
448
- 00:00:02,110 --> 00:00:04,578
449
- <i>(male narrator) Previously
450
- on Battlestar Galactica.</i>
451
-
452
- 2
453
- 00:00:05,313 --> 00:00:06,871
454
- Now you're telling me
455
- you're a machine.
456
-
457
- 3
458
- 00:00:07,014 --> 00:00:08,003
459
- The robot.
460
- END
461
- file.to_s.should eq(OUTPUT)
462
- end
463
- end
464
- end
465
-
466
- describe "#to_webvtt" do
467
- context "when calling it on a short SRT file" do
468
- let(:file) { SRT::File.parse(File.open("./spec/bsg-s01e01.srt")) }
469
-
470
- before { file.lines = file.lines[0..2] }
471
-
472
- it "should produce the exactly correct output" do
473
- OUTPUT_WEBVTT =<<END
474
- WEBVTT
475
- X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000
476
-
477
- 1
478
- 00:00:02.110 --> 00:00:04.578
479
- <i>(male narrator) Previously
480
- on Battlestar Galactica.</i>
481
-
482
- 2
483
- 00:00:05.313 --> 00:00:06.871
484
- Now you're telling me
485
- you're a machine.
486
-
487
- 3
488
- 00:00:07.014 --> 00:00:08.003
489
- The robot.
490
- END
491
- file.to_webvtt.should eq(OUTPUT_WEBVTT)
492
- end
493
- end
494
- end
495
-
496
- end
497
- end
498
- end