subtitle-library 0.0.1
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.
- data/bin/subtitle-library +113 -0
- data/lib/subtitle-library.rb +3 -0
- data/lib/subtitle-library/changer.rb +117 -0
- data/lib/subtitle-library/cue.rb +16 -0
- data/lib/subtitle-library/reader.rb +357 -0
- data/lib/subtitle-library/regex-patterns.rb +8 -0
- data/lib/subtitle-library/writer.rb +93 -0
- data/test/integration/command-line-spec.rb +626 -0
- data/test/unit/changer-spec.rb +891 -0
- data/test/unit/reader-spec.rb +1053 -0
- data/test/unit/writer-spec.rb +830 -0
- metadata +84 -0
@@ -0,0 +1,1053 @@
|
|
1
|
+
require 'subtitle-library'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
|
4
|
+
describe SubsReader do
|
5
|
+
include FakeFS
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.before(:each) do
|
9
|
+
FakeFS.activate!
|
10
|
+
FileSystem.clear
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.after(:each) do
|
16
|
+
FakeFS.deactivate!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def new_reader(path)
|
21
|
+
SubsReader.new path
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'type finding' do
|
25
|
+
path = 'subs.sub'
|
26
|
+
|
27
|
+
it 'validates the type correctly' do
|
28
|
+
FakeFS do
|
29
|
+
File.open(path, 'w') do |subs|
|
30
|
+
subs.write(<<-eos
|
31
|
+
12
|
32
|
+
00:02:04,240 --> 00:02:05,593
|
33
|
+
It was funny, huh?
|
34
|
+
|
35
|
+
13
|
36
|
+
00:02:06,320 --> 00:02:07,639
|
37
|
+
Yes, but I have to go.
|
38
|
+
|
39
|
+
14
|
40
|
+
00:02:07,840 --> 00:02:09,831
|
41
|
+
That'll teach you to excite yourself like this.
|
42
|
+
|
43
|
+
15
|
44
|
+
00:02:10,040 --> 00:02:12,508
|
45
|
+
Stop somewhere if you can.
|
46
|
+
|
47
|
+
16
|
48
|
+
00:02:43,560 --> 00:02:46,028
|
49
|
+
Honey, you're not at school.
|
50
|
+
Don't bother poor Elly.
|
51
|
+
eos
|
52
|
+
)
|
53
|
+
end
|
54
|
+
new_reader(path).type.should eq 'sr'
|
55
|
+
|
56
|
+
File.open(path, 'w') do |subs|
|
57
|
+
subs.write(<<-eos
|
58
|
+
{5277}{5309}You want some water with that?
|
59
|
+
{5311}{5345}No, no. No, I don't.
|
60
|
+
{5362}{5396}Looks like you had a night.
|
61
|
+
{5529}{5562}They look perfect.
|
62
|
+
eos
|
63
|
+
)
|
64
|
+
end
|
65
|
+
new_reader(path).type.should eq 'md'
|
66
|
+
|
67
|
+
File.open(path, 'w') do |subs|
|
68
|
+
subs.write(<<-eos
|
69
|
+
00:02:04.240,00:2:5.593
|
70
|
+
It was funny, huh?
|
71
|
+
|
72
|
+
00:02:06.20,00:02:07.639
|
73
|
+
Yes, but I have to go.
|
74
|
+
|
75
|
+
00:2:07.840,00:02:09.831
|
76
|
+
That'll teach you to excite yourself like this.
|
77
|
+
|
78
|
+
00:02:10.00,00:02:12.5
|
79
|
+
Stop somewhere if you can.
|
80
|
+
eos
|
81
|
+
)
|
82
|
+
end
|
83
|
+
new_reader(path).type.should eq 'sv'
|
84
|
+
|
85
|
+
File.open(path, 'w') do |subs|
|
86
|
+
subs.write(<<-eos
|
87
|
+
some
|
88
|
+
other
|
89
|
+
format
|
90
|
+
eos
|
91
|
+
)
|
92
|
+
end
|
93
|
+
new_reader(path).type.should eq 'uk'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe SubRipReader do
|
100
|
+
include FakeFS
|
101
|
+
|
102
|
+
def setup
|
103
|
+
FakeFS.activate!
|
104
|
+
FileSystem.clear
|
105
|
+
end
|
106
|
+
|
107
|
+
def teardown
|
108
|
+
FakeFS.deactivate!
|
109
|
+
end
|
110
|
+
|
111
|
+
def new_reader(path)
|
112
|
+
SubRipReader.new path
|
113
|
+
end
|
114
|
+
|
115
|
+
describe 'syntax checking' do
|
116
|
+
path = 'subs.srt'
|
117
|
+
|
118
|
+
it 'validates correct syntax' do
|
119
|
+
FakeFS do
|
120
|
+
File.open(path, 'w') do |subs|
|
121
|
+
subs.write(<<-eos
|
122
|
+
12
|
123
|
+
00:02:04,240 --> 00:02:05,593
|
124
|
+
It was funny, huh?
|
125
|
+
|
126
|
+
13
|
127
|
+
00:02:06,320 --> 00:02:07,639
|
128
|
+
Yes, but I have to go.
|
129
|
+
|
130
|
+
14
|
131
|
+
00:02:07,840 --> 00:02:09,831
|
132
|
+
That'll teach you to excite yourself like this.
|
133
|
+
|
134
|
+
15
|
135
|
+
00:02:10,040 --> 00:02:12,508
|
136
|
+
Stop somewhere if you can.
|
137
|
+
|
138
|
+
16
|
139
|
+
00:02:43,560 --> 00:02:46,028
|
140
|
+
Honey, you're not at school.
|
141
|
+
Don't bother poor Elly.
|
142
|
+
eos
|
143
|
+
)
|
144
|
+
end
|
145
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
146
|
+
|
147
|
+
File.open(path, 'w') do |subs|
|
148
|
+
subs.write(<<-eos
|
149
|
+
12
|
150
|
+
00:02:04,240--> 00:02:05,593
|
151
|
+
It was funny, huh?
|
152
|
+
|
153
|
+
13
|
154
|
+
00:02:06,20 --> 00:02:07,639
|
155
|
+
Yes, but I have to go.
|
156
|
+
|
157
|
+
1
|
158
|
+
00:2:07,840-->00:02:09,831
|
159
|
+
That'll teach you to excite yourself like this.
|
160
|
+
|
161
|
+
15
|
162
|
+
00:02:10,00 --> 00:02:12,5
|
163
|
+
Stop somewhere if you can.
|
164
|
+
eos
|
165
|
+
)
|
166
|
+
end
|
167
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
168
|
+
|
169
|
+
File.open(path, 'w') do |subs|
|
170
|
+
subs.write(<<-eos
|
171
|
+
12
|
172
|
+
00:02:04,240 --> 00:02:05,593
|
173
|
+
It was funny, huh?
|
174
|
+
|
175
|
+
13
|
176
|
+
00:02:06,320-->00:02:07,639
|
177
|
+
Yes, but I have to go.
|
178
|
+
|
179
|
+
|
180
|
+
00:02:07,840 --> 00:02:09,831
|
181
|
+
That'll
|
182
|
+
teach you to
|
183
|
+
excite yourself
|
184
|
+
|
185
|
+
like this.
|
186
|
+
|
187
|
+
15
|
188
|
+
00:02:10,040 --> 00:02:12,508
|
189
|
+
Stop somewhere if you can.
|
190
|
+
|
191
|
+
16
|
192
|
+
00:02:43,560 --> 0:2:46,028
|
193
|
+
Honey,
|
194
|
+
you're not at school.
|
195
|
+
Don't bother poor Elly.
|
196
|
+
eos
|
197
|
+
)
|
198
|
+
end
|
199
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'validates invalid timing' do
|
205
|
+
FakeFS do
|
206
|
+
File.open(path, 'w') do |subs|
|
207
|
+
subs.write(<<-eos
|
208
|
+
12
|
209
|
+
00:02:04,240 --> 00:02:04,3
|
210
|
+
It was funny, huh?
|
211
|
+
|
212
|
+
13
|
213
|
+
00:02:06,320 --> 00:02:07,639
|
214
|
+
Yes, but I have to go.
|
215
|
+
|
216
|
+
14
|
217
|
+
00:02:07,840 --> 00:02:09,831
|
218
|
+
That'll teach you to excite yourself like this.
|
219
|
+
|
220
|
+
15
|
221
|
+
00:02:10,040 --> 00:02:12,508
|
222
|
+
Stop somewhere if you can.
|
223
|
+
|
224
|
+
16
|
225
|
+
00:02:43,560 --> 00:02:46,028
|
226
|
+
Honey, you're not at school.
|
227
|
+
Don't bother poor Elly.
|
228
|
+
eos
|
229
|
+
)
|
230
|
+
end
|
231
|
+
|
232
|
+
new_reader(path).read_subs(true).should eq "Invalid timing at line 2."
|
233
|
+
|
234
|
+
File.open(path, 'w') do |subs|
|
235
|
+
subs.write(<<-eos
|
236
|
+
12
|
237
|
+
00:02:04,240 --> 00:02:05,593
|
238
|
+
It was funny, huh?
|
239
|
+
|
240
|
+
13
|
241
|
+
00:02:06,320 --> 00:02:06,320
|
242
|
+
Yes, but I have to go.
|
243
|
+
|
244
|
+
14
|
245
|
+
00:02:07,840 --> 00:02:09,831
|
246
|
+
That'll teach you to excite yourself like this.
|
247
|
+
|
248
|
+
15
|
249
|
+
00:02:10,040 --> 00:02:12,508
|
250
|
+
Stop somewhere if you can.
|
251
|
+
|
252
|
+
16
|
253
|
+
00:02:43,560 --> 00:02:46,028
|
254
|
+
Honey, you're not at school.
|
255
|
+
Don't bother poor Elly.
|
256
|
+
eos
|
257
|
+
)
|
258
|
+
end
|
259
|
+
|
260
|
+
new_reader(path).read_subs(true).should eq "Invalid timing at line 6."
|
261
|
+
|
262
|
+
File.open(path, 'w') do |subs|
|
263
|
+
subs.write(<<-eos
|
264
|
+
12
|
265
|
+
00:02:04,240 --> 00:02:03,593
|
266
|
+
It was funny, huh?
|
267
|
+
|
268
|
+
13
|
269
|
+
00:02:06,320 --> 00:02:07,639
|
270
|
+
Yes, but I have to go.
|
271
|
+
|
272
|
+
14
|
273
|
+
00:02:07,840 --> 00:02:07,831
|
274
|
+
That'll teach you to excite yourself like this.
|
275
|
+
|
276
|
+
15
|
277
|
+
00:02:10,040 --> 00:02:12,508
|
278
|
+
Stop somewhere if you can.
|
279
|
+
|
280
|
+
16
|
281
|
+
00:02:43,560 --> 00:02:46,028
|
282
|
+
Honey, you're not at school.
|
283
|
+
Don't bother poor Elly.
|
284
|
+
eos
|
285
|
+
)
|
286
|
+
end
|
287
|
+
|
288
|
+
new_reader(path).read_subs(true).should eq "Invalid timing at line 2.\nInvalid timing at line 10."
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'validates invalid start-end time format' do
|
294
|
+
FakeFS do
|
295
|
+
File.open(path, 'w') do |subs|
|
296
|
+
subs.write(<<-eos
|
297
|
+
12
|
298
|
+
00:02:04,240 --> 00:02:05,593
|
299
|
+
It was funny, huh?
|
300
|
+
|
301
|
+
13
|
302
|
+
00:02:06320 --> 00:02:07,639
|
303
|
+
Yes, but I have to go.
|
304
|
+
|
305
|
+
14
|
306
|
+
00:02:07,840 --> 00:02:09,831
|
307
|
+
That'll teach you to excite yourself like this.
|
308
|
+
|
309
|
+
15
|
310
|
+
00:02:10,040 --> 00:02:12,508
|
311
|
+
Stop somewhere if you can.
|
312
|
+
|
313
|
+
16
|
314
|
+
00:02:43,560 --> 00:02:46,028
|
315
|
+
Honey, you're not at school.
|
316
|
+
Don't bother poor Elly.
|
317
|
+
eos
|
318
|
+
)
|
319
|
+
end
|
320
|
+
|
321
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 6."
|
322
|
+
|
323
|
+
File.open(path, 'w') do |subs|
|
324
|
+
subs.write(<<-eos
|
325
|
+
12
|
326
|
+
00:02:04,240 --> 00:02:05593
|
327
|
+
It was funny, huh?
|
328
|
+
|
329
|
+
13
|
330
|
+
00:02:06,320 --> 00:02:07,639
|
331
|
+
Yes, but I have to go.
|
332
|
+
|
333
|
+
14
|
334
|
+
00:02:07,840 -> 00:02:09,831
|
335
|
+
That'll teach you to excite yourself like this.
|
336
|
+
|
337
|
+
15
|
338
|
+
00:02:10,040 --> 00:02:12,508
|
339
|
+
Stop somewhere if you can.
|
340
|
+
|
341
|
+
16
|
342
|
+
00:02:43,560 --> 00:02:46,028
|
343
|
+
Honey, you're not at school.
|
344
|
+
Don't bother poor Elly.
|
345
|
+
eos
|
346
|
+
)
|
347
|
+
end
|
348
|
+
|
349
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 2.\nSyntax error at line 10."
|
350
|
+
|
351
|
+
File.open(path, 'w') do |subs|
|
352
|
+
subs.write(<<-eos
|
353
|
+
12
|
354
|
+
00:02:04,240 --> 00:02:05,593
|
355
|
+
It was funny, huh?
|
356
|
+
|
357
|
+
13
|
358
|
+
00:02:06,320 --> 00:02:07,639
|
359
|
+
Yes, but I have to go.
|
360
|
+
|
361
|
+
14
|
362
|
+
00:02:07,840 --> 00:02:09,831
|
363
|
+
That'll teach you to excite yourself like this.
|
364
|
+
|
365
|
+
15
|
366
|
+
00:02:10,040 --> 00:02:12,508
|
367
|
+
Stop somewhere if you can.
|
368
|
+
|
369
|
+
16
|
370
|
+
00:02:43,560 -- 00:02:46,028
|
371
|
+
Honey, you're not at school.
|
372
|
+
Don't bother poor Elly.
|
373
|
+
eos
|
374
|
+
)
|
375
|
+
end
|
376
|
+
|
377
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 18."
|
378
|
+
end
|
379
|
+
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'validates invalid text between index and start-end time lines' do
|
383
|
+
FakeFS do
|
384
|
+
File.open(path, 'w') do |subs|
|
385
|
+
subs.write(<<-eos
|
386
|
+
12
|
387
|
+
00:02:04,240 --> 00:02:05,593
|
388
|
+
It was funny, huh?
|
389
|
+
|
390
|
+
1
|
391
|
+
s
|
392
|
+
00:02:06,320 --> 00:02:07,639
|
393
|
+
Yes, but I have to go.
|
394
|
+
|
395
|
+
14
|
396
|
+
00:02:07,840 --> 00:02:09,831
|
397
|
+
That'll teach you to excite yourself like this.
|
398
|
+
|
399
|
+
15
|
400
|
+
00:02:10,040 --> 00:02:12,508
|
401
|
+
Stop somewhere if you can.
|
402
|
+
|
403
|
+
16
|
404
|
+
00:02:43,560 --> 00:02:46,028
|
405
|
+
Honey, you're not at school.
|
406
|
+
Don't bother poor Elly.
|
407
|
+
eos
|
408
|
+
)
|
409
|
+
end
|
410
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 6."
|
411
|
+
|
412
|
+
File.open(path, 'w') do |subs|
|
413
|
+
subs.write(<<-eos
|
414
|
+
12
|
415
|
+
00:02:04,240 --> 00:02:05,593
|
416
|
+
It was funny, huh?
|
417
|
+
|
418
|
+
1
|
419
|
+
s
|
420
|
+
00:02:06,320 --> 00:02:07,639
|
421
|
+
Yes, but I have to go.
|
422
|
+
|
423
|
+
14
|
424
|
+
00:02:07,840 --> 00:02:09,831
|
425
|
+
That'll teach you to excite yourself like this.
|
426
|
+
|
427
|
+
15
|
428
|
+
00:02:10,040 --> 00:02:12,508
|
429
|
+
Stop somewhere if you can.
|
430
|
+
|
431
|
+
16
|
432
|
+
a
|
433
|
+
00:02:43,560 --> 00:02:46,028
|
434
|
+
Honey, you're not at school.
|
435
|
+
Don't bother poor Elly.
|
436
|
+
eos
|
437
|
+
)
|
438
|
+
end
|
439
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 6.\nSyntax error at line 19."
|
440
|
+
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
describe 'cue loading' do
|
446
|
+
path = 'subs.srt'
|
447
|
+
|
448
|
+
it 'loads all cues when syntax is correct' do
|
449
|
+
FakeFS do
|
450
|
+
File.open(path, 'w') do |subs|
|
451
|
+
subs.write(<<-eos
|
452
|
+
12
|
453
|
+
00:02:04,240 --> 00:02:05,593
|
454
|
+
It was funny, huh?
|
455
|
+
|
456
|
+
13
|
457
|
+
00:02:06,320 --> 00:02:07,639
|
458
|
+
Yes, but I have to go.
|
459
|
+
|
460
|
+
14
|
461
|
+
00:02:07,840 --> 00:02:09,831
|
462
|
+
That'll teach you to excite
|
463
|
+
yourself like this.
|
464
|
+
eos
|
465
|
+
)
|
466
|
+
end
|
467
|
+
cues = []
|
468
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 4, 240000), Time.mktime(1, 1, 1, 0, 2, 5, 593000), "It was funny, huh?")
|
469
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 6, 320000), Time.mktime(1, 1, 1, 0, 2, 7, 639000), "Yes, but I have to go.")
|
470
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 7, 840000), Time.mktime(1, 1, 1, 0, 2, 9, 831000), "That'll teach you to excite\nyourself like this.")
|
471
|
+
|
472
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
it 'loads the valid cues when syntax is incorrect' do
|
477
|
+
FakeFS do
|
478
|
+
File.open(path, 'w') do |subs|
|
479
|
+
subs.write(<<-eos
|
480
|
+
12
|
481
|
+
00:02:04,240 --> 00:02:05,593
|
482
|
+
It was funny, huh?
|
483
|
+
|
484
|
+
13
|
485
|
+
00:02:06,320 -- 00:02:07,639
|
486
|
+
Yes, but I have to go.
|
487
|
+
|
488
|
+
14
|
489
|
+
00:02:07,840 --> 00:02:09,831
|
490
|
+
That'll teach you to excite
|
491
|
+
yourself like this.
|
492
|
+
eos
|
493
|
+
)
|
494
|
+
end
|
495
|
+
cues = []
|
496
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 4, 240000), Time.mktime(1, 1, 1, 0, 2, 5, 593000), "It was funny, huh?")
|
497
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 7, 840000), Time.mktime(1, 1, 1, 0, 2, 9, 831000), "That'll teach you to excite\nyourself like this.")
|
498
|
+
|
499
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
500
|
+
|
501
|
+
File.open(path, 'w') do |subs|
|
502
|
+
subs.write(<<-eos
|
503
|
+
12
|
504
|
+
00:02:04240 --> 00:02:05,593
|
505
|
+
It was funny, huh?
|
506
|
+
|
507
|
+
13
|
508
|
+
00:02:06,320 --> 00:02:07,639
|
509
|
+
Yes, but I have to go.
|
510
|
+
|
511
|
+
14
|
512
|
+
00:02:07,840 --> 00:02:03,831
|
513
|
+
That'll teach you to excite
|
514
|
+
yourself like this.
|
515
|
+
eos
|
516
|
+
)
|
517
|
+
end
|
518
|
+
cues = []
|
519
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 6, 320000), Time.mktime(1, 1, 1, 0, 2, 7, 639000), "Yes, but I have to go.")
|
520
|
+
|
521
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
describe MicroDVDReader do
|
529
|
+
include FakeFS
|
530
|
+
|
531
|
+
def setup
|
532
|
+
FakeFS.activate!
|
533
|
+
FileSystem.clear
|
534
|
+
end
|
535
|
+
|
536
|
+
def teardown
|
537
|
+
FakeFS.deactivate!
|
538
|
+
end
|
539
|
+
|
540
|
+
def new_reader(path)
|
541
|
+
MicroDVDReader.new path
|
542
|
+
end
|
543
|
+
|
544
|
+
describe 'syntax checking' do
|
545
|
+
path = 'subs.sub'
|
546
|
+
|
547
|
+
it 'validates correct syntax' do
|
548
|
+
FakeFS do
|
549
|
+
File.open(path, 'w') do |subs|
|
550
|
+
subs.write(<<-eos
|
551
|
+
{5277}{5309}You want some water with that?
|
552
|
+
{5311}{5345}No, no. No, I don't.
|
553
|
+
{5362}{5396}Looks like you had a night.
|
554
|
+
{5529}{5562}They look perfect.
|
555
|
+
eos
|
556
|
+
)
|
557
|
+
end
|
558
|
+
|
559
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
560
|
+
|
561
|
+
File.open(path, 'w') do |subs|
|
562
|
+
subs.write(<<-eos
|
563
|
+
{5277}{5309}{y:i}You want some water with that?
|
564
|
+
{5311}{5345}No, no. No, I don't.
|
565
|
+
{5362}{5396}Looks like you had a night.
|
566
|
+
{5529}{5562}They look perfect.
|
567
|
+
eos
|
568
|
+
)
|
569
|
+
end
|
570
|
+
|
571
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
572
|
+
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
it 'validates invalid frames' do
|
577
|
+
FakeFS do
|
578
|
+
File.open(path, 'w') do |subs|
|
579
|
+
subs.write(<<-eos
|
580
|
+
{5277}{309}You want some water with that?
|
581
|
+
{5311}{5345}No, no. No, I don't.
|
582
|
+
{5362}{5396}Looks like you had a night.
|
583
|
+
{5529}{5562}They look perfect.
|
584
|
+
eos
|
585
|
+
)
|
586
|
+
end
|
587
|
+
|
588
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 1."
|
589
|
+
|
590
|
+
File.open(path, 'w') do |subs|
|
591
|
+
subs.write(<<-eos
|
592
|
+
{5277}{5309}{y:i}You want some water with that?
|
593
|
+
{5311}{535}No, no. No, I don't.
|
594
|
+
{5362}{5396}Looks like you had a night.
|
595
|
+
{552}{5562}They look perfect.
|
596
|
+
eos
|
597
|
+
)
|
598
|
+
end
|
599
|
+
|
600
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 2.\nSyntax error at line 4."
|
601
|
+
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
it 'validates invalid frame format' do
|
606
|
+
FakeFS do
|
607
|
+
File.open(path, 'w') do |subs|
|
608
|
+
subs.write(<<-eos
|
609
|
+
{5277}5309}You want some water with that?
|
610
|
+
{5311}{5345}No, no. No, I don't.
|
611
|
+
{5362}{5396}Looks like you had a night.
|
612
|
+
{5529}{5562}They look perfect.
|
613
|
+
eos
|
614
|
+
)
|
615
|
+
end
|
616
|
+
|
617
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 1."
|
618
|
+
|
619
|
+
File.open(path, 'w') do |subs|
|
620
|
+
subs.write(<<-eos
|
621
|
+
{5277}{5309}{y:i}You want some water with that?
|
622
|
+
{5311}{5345}No, no. No, I don't.
|
623
|
+
{,5362}{5396}Looks like you had a night.
|
624
|
+
{5529{5562}They look perfect.
|
625
|
+
eos
|
626
|
+
)
|
627
|
+
end
|
628
|
+
|
629
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 3.\nSyntax error at line 4."
|
630
|
+
|
631
|
+
end
|
632
|
+
end
|
633
|
+
|
634
|
+
end
|
635
|
+
|
636
|
+
describe 'reading finds the fps if available' do
|
637
|
+
path = 'subs.sub'
|
638
|
+
|
639
|
+
it 'validates correct syntax' do
|
640
|
+
FakeFS do
|
641
|
+
File.open(path, 'w') do |subs|
|
642
|
+
subs.write(<<-eos
|
643
|
+
{5277}{5309}You want some water with that?
|
644
|
+
{5311}{5345}No, no. No, I don't.
|
645
|
+
{5362}{5396}Looks like you had a night.
|
646
|
+
{5529}{5562}They look perfect.
|
647
|
+
eos
|
648
|
+
)
|
649
|
+
end
|
650
|
+
|
651
|
+
new_reader(path).read_subs(false)[1].should eq 23.976
|
652
|
+
|
653
|
+
File.open(path, 'w') do |subs|
|
654
|
+
subs.write(<<-eos
|
655
|
+
{1}{1}25
|
656
|
+
{5311}{5345}No, no. No, I don't.
|
657
|
+
{5362}{5396}Looks like you had a night.
|
658
|
+
{5529}{5562}They look perfect.
|
659
|
+
eos
|
660
|
+
)
|
661
|
+
end
|
662
|
+
|
663
|
+
new_reader(path).read_subs(false)[1].should eq 25
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
describe 'cue loading' do
|
669
|
+
path = 'subs.sub'
|
670
|
+
|
671
|
+
it 'loads all cues when syntax is correct' do
|
672
|
+
FakeFS do
|
673
|
+
File.open(path, 'w') do |subs|
|
674
|
+
subs.write(<<-eos
|
675
|
+
{5277}{5309}You want some water with that?
|
676
|
+
{5311}{5345}No, no.|No, I don't.
|
677
|
+
{5362}{5396}Looks like you had a night.
|
678
|
+
eos
|
679
|
+
)
|
680
|
+
end
|
681
|
+
|
682
|
+
cues = []
|
683
|
+
cues << Cue.new(5277, 5309, "You want some water with that?")
|
684
|
+
cues << Cue.new(5311, 5345, "No, no.\nNo, I don't.")
|
685
|
+
cues << Cue.new(5362, 5396, "Looks like you had a night.")
|
686
|
+
|
687
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
688
|
+
end
|
689
|
+
end
|
690
|
+
|
691
|
+
it 'loads valid cues when syntax is incorrect' do
|
692
|
+
FakeFS do
|
693
|
+
File.open(path, 'w') do |subs|
|
694
|
+
subs.write(<<-eos
|
695
|
+
{5277}{309}You want some water with that?
|
696
|
+
{5311}{5345}No, no.|No, I don't.
|
697
|
+
{5362}{5396}Looks like you had a night.
|
698
|
+
eos
|
699
|
+
)
|
700
|
+
end
|
701
|
+
|
702
|
+
cues = []
|
703
|
+
cues << Cue.new(5311, 5345, "No, no.\nNo, I don't.")
|
704
|
+
cues << Cue.new(5362, 5396, "Looks like you had a night.")
|
705
|
+
|
706
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
707
|
+
|
708
|
+
File.open(path, 'w') do |subs|
|
709
|
+
subs.write(<<-eos
|
710
|
+
{5277{5309}You want some water with that?
|
711
|
+
{5311}{5345}No, no.|No, I don't.
|
712
|
+
{532}{5396}Looks like you had a night.
|
713
|
+
eos
|
714
|
+
)
|
715
|
+
end
|
716
|
+
|
717
|
+
cues = []
|
718
|
+
cues << Cue.new(5311, 5345, "No, no.\nNo, I don't.")
|
719
|
+
|
720
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
721
|
+
end
|
722
|
+
end
|
723
|
+
|
724
|
+
end
|
725
|
+
|
726
|
+
end
|
727
|
+
|
728
|
+
describe SubviewerReader do
|
729
|
+
include FakeFS
|
730
|
+
|
731
|
+
def setup
|
732
|
+
FakeFS.activate!
|
733
|
+
FileSystem.clear
|
734
|
+
end
|
735
|
+
|
736
|
+
def teardown
|
737
|
+
FakeFS.deactivate!
|
738
|
+
end
|
739
|
+
|
740
|
+
def new_reader(path)
|
741
|
+
SubviewerReader.new path
|
742
|
+
end
|
743
|
+
|
744
|
+
describe 'syntax checking' do
|
745
|
+
path = 'subs.sub'
|
746
|
+
|
747
|
+
it 'validates correct syntax' do
|
748
|
+
FakeFS do
|
749
|
+
File.open(path, 'w') do |subs|
|
750
|
+
subs.write(<<-eos
|
751
|
+
00:02:04.240,00:02:05.593
|
752
|
+
It was funny, huh?
|
753
|
+
|
754
|
+
00:02:06.320,00:02:07.639
|
755
|
+
Yes, but I have to go.
|
756
|
+
|
757
|
+
00:02:07.840,00:02:09.831
|
758
|
+
That'll teach you to excite yourself like this.
|
759
|
+
|
760
|
+
00:02:10.040,00:02:12.508
|
761
|
+
Stop somewhere if you can.
|
762
|
+
|
763
|
+
00:02:43.560,00:02:46.028
|
764
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
765
|
+
eos
|
766
|
+
)
|
767
|
+
end
|
768
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
769
|
+
|
770
|
+
File.open(path, 'w') do |subs|
|
771
|
+
subs.write(<<-eos
|
772
|
+
00:02:04.240,00:2:5.593
|
773
|
+
It was funny, huh?
|
774
|
+
|
775
|
+
00:02:06.20,00:02:07.639
|
776
|
+
Yes, but I have to go.
|
777
|
+
|
778
|
+
00:2:07.840,00:02:09.831
|
779
|
+
That'll teach you to excite yourself like this.
|
780
|
+
|
781
|
+
00:02:10.00,00:02:12.5
|
782
|
+
Stop somewhere if you can.
|
783
|
+
eos
|
784
|
+
)
|
785
|
+
end
|
786
|
+
new_reader(path).read_subs(true).should eq "No errors were found."
|
787
|
+
|
788
|
+
end
|
789
|
+
|
790
|
+
end
|
791
|
+
|
792
|
+
it 'validates invalid timing' do
|
793
|
+
FakeFS do
|
794
|
+
File.open(path, 'w') do |subs|
|
795
|
+
subs.write(<<-eos
|
796
|
+
00:02:04.240,00:02:04.003
|
797
|
+
It was funny, huh?
|
798
|
+
|
799
|
+
00:02:06.320,00:02:07.639
|
800
|
+
Yes, but I have to go.
|
801
|
+
|
802
|
+
00:02:07.840,00:02:09.831
|
803
|
+
That'll teach you to excite yourself like this.
|
804
|
+
|
805
|
+
00:02:10.040,00:02:12.508
|
806
|
+
Stop somewhere if you can.
|
807
|
+
|
808
|
+
00:02:43.560,00:02:46.028
|
809
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
810
|
+
eos
|
811
|
+
)
|
812
|
+
end
|
813
|
+
|
814
|
+
new_reader(path).read_subs(true).should eq "Invalid timing at line 1."
|
815
|
+
|
816
|
+
File.open(path, 'w') do |subs|
|
817
|
+
subs.write(<<-eos
|
818
|
+
00:02:04.240,00:02:05.593
|
819
|
+
It was funny, huh?
|
820
|
+
|
821
|
+
00:02:06.320,00:02:06.320
|
822
|
+
Yes, but I have to go.
|
823
|
+
|
824
|
+
00:02:07.840,00:02:09.831
|
825
|
+
That'll teach you to excite yourself like this.
|
826
|
+
|
827
|
+
00:02:10.040,00:02:12.508
|
828
|
+
Stop somewhere if you can.
|
829
|
+
|
830
|
+
00:02:43.560,00:02:46.028
|
831
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
832
|
+
eos
|
833
|
+
)
|
834
|
+
end
|
835
|
+
|
836
|
+
new_reader(path).read_subs(true).should eq "Invalid timing at line 4."
|
837
|
+
|
838
|
+
File.open(path, 'w') do |subs|
|
839
|
+
subs.write(<<-eos
|
840
|
+
00:02:04.240,00:02:03.593
|
841
|
+
It was funny, huh?
|
842
|
+
|
843
|
+
00:02:06.320,00:02:07.639
|
844
|
+
Yes, but I have to go.
|
845
|
+
|
846
|
+
00:02:07.840,00:02:07.831
|
847
|
+
That'll teach you to excite yourself like this.
|
848
|
+
|
849
|
+
00:02:10.040,00:02:12.508
|
850
|
+
Stop somewhere if you can.
|
851
|
+
|
852
|
+
00:02:43.560,00:02:46.028
|
853
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
854
|
+
eos
|
855
|
+
)
|
856
|
+
end
|
857
|
+
|
858
|
+
new_reader(path).read_subs(true).should eq "Invalid timing at line 1.\nInvalid timing at line 7."
|
859
|
+
end
|
860
|
+
|
861
|
+
end
|
862
|
+
|
863
|
+
it 'validates invalid start-end time format' do
|
864
|
+
FakeFS do
|
865
|
+
File.open(path, 'w') do |subs|
|
866
|
+
subs.write(<<-eos
|
867
|
+
00:02:04.240,00:02:05.593
|
868
|
+
It was funny, huh?
|
869
|
+
|
870
|
+
00:02:06320,00:02:07.639
|
871
|
+
Yes, but I have to go.
|
872
|
+
|
873
|
+
00:02:07.840,00:02:09.831
|
874
|
+
That'll teach you to excite yourself like this.
|
875
|
+
|
876
|
+
00:02:10.040,00:02:12.508
|
877
|
+
Stop somewhere if you can.
|
878
|
+
|
879
|
+
00:02:43.560,00:02:46.028
|
880
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
881
|
+
eos
|
882
|
+
)
|
883
|
+
end
|
884
|
+
|
885
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 4."
|
886
|
+
|
887
|
+
File.open(path, 'w') do |subs|
|
888
|
+
subs.write(<<-eos
|
889
|
+
00:02:04.240,00:02:05593
|
890
|
+
It was funny, huh?
|
891
|
+
|
892
|
+
00:02:06.320,00:02:07.639
|
893
|
+
Yes, but I have to go.
|
894
|
+
|
895
|
+
00:02:07.84000:02:09.831
|
896
|
+
That'll teach you to excite yourself like this.
|
897
|
+
|
898
|
+
00:02:10.040,00:02:12.508
|
899
|
+
Stop somewhere if you can.
|
900
|
+
|
901
|
+
00:02:43.560,00:02:46.028
|
902
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
903
|
+
eos
|
904
|
+
)
|
905
|
+
end
|
906
|
+
|
907
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 1.\nSyntax error at line 7."
|
908
|
+
|
909
|
+
File.open(path, 'w') do |subs|
|
910
|
+
subs.write(<<-eos
|
911
|
+
00:02:04.240,00:02:05.593
|
912
|
+
It was funny, huh?
|
913
|
+
|
914
|
+
00:02:06.320,00:02:07.639
|
915
|
+
Yes, but I have to go.
|
916
|
+
|
917
|
+
00:02:07.840,00:02:09.831
|
918
|
+
That'll teach you to excite yourself like this.
|
919
|
+
|
920
|
+
00:02:10.040,00:02:12.508
|
921
|
+
Stop somewhere if you can.
|
922
|
+
|
923
|
+
00:02:43,560,00:02:46.028
|
924
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
925
|
+
eos
|
926
|
+
)
|
927
|
+
end
|
928
|
+
|
929
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 13."
|
930
|
+
end
|
931
|
+
|
932
|
+
end
|
933
|
+
|
934
|
+
it 'validates invalid text after a line of valid text' do
|
935
|
+
FakeFS do
|
936
|
+
File.open(path, 'w') do |subs|
|
937
|
+
subs.write(<<-eos
|
938
|
+
00:02:04.240,00:02:05.593
|
939
|
+
It was funny, huh?
|
940
|
+
s
|
941
|
+
|
942
|
+
00:02:06.320,00:02:07.639
|
943
|
+
Yes, but I have to go.
|
944
|
+
|
945
|
+
00:02:07.840,00:02:09.831
|
946
|
+
That'll teach you to excite yourself like this.
|
947
|
+
|
948
|
+
00:02:10.040,00:02:12.508
|
949
|
+
Stop somewhere if you can.
|
950
|
+
|
951
|
+
00:02:43.560,00:02:46.028
|
952
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
953
|
+
eos
|
954
|
+
)
|
955
|
+
end
|
956
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 3."
|
957
|
+
|
958
|
+
File.open(path, 'w') do |subs|
|
959
|
+
subs.write(<<-eos
|
960
|
+
00:02:04.240,00:02:05.593
|
961
|
+
It was funny, huh?
|
962
|
+
|
963
|
+
00:02:06.320,00:02:07.639
|
964
|
+
Yes, but I have to go.
|
965
|
+
|
966
|
+
00:02:07.840,00:02:09.831
|
967
|
+
That'll teach you to excite yourself like this.
|
968
|
+
s
|
969
|
+
|
970
|
+
00:02:10.040,00:02:12.508
|
971
|
+
Stop somewhere if you can.
|
972
|
+
|
973
|
+
00:02:43.560,00:02:46.028
|
974
|
+
Honey, you're not at school.[br]Don't bother poor Elly.
|
975
|
+
eos
|
976
|
+
)
|
977
|
+
end
|
978
|
+
new_reader(path).read_subs(true).should eq "Syntax error at line 9."
|
979
|
+
|
980
|
+
end
|
981
|
+
end
|
982
|
+
end
|
983
|
+
|
984
|
+
describe 'cue loading' do
|
985
|
+
path = 'subs.sub'
|
986
|
+
|
987
|
+
it 'loads all cues when syntax is correct' do
|
988
|
+
FakeFS do
|
989
|
+
File.open(path, 'w') do |subs|
|
990
|
+
subs.write(<<-eos
|
991
|
+
00:02:04.240,00:02:05.593
|
992
|
+
It was funny, huh?
|
993
|
+
|
994
|
+
00:02:06.320,00:02:07.639
|
995
|
+
Yes, but I have to go.
|
996
|
+
|
997
|
+
00:02:07.840,00:02:09.831
|
998
|
+
That'll teach you to excite[br]yourself like this.
|
999
|
+
eos
|
1000
|
+
)
|
1001
|
+
end
|
1002
|
+
cues = []
|
1003
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 4, 240000), Time.mktime(1, 1, 1, 0, 2, 5, 593000), "It was funny, huh?")
|
1004
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 6, 320000), Time.mktime(1, 1, 1, 0, 2, 7, 639000), "Yes, but I have to go.")
|
1005
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 7, 840000), Time.mktime(1, 1, 1, 0, 2, 9, 831000), "That'll teach you to excite\nyourself like this.")
|
1006
|
+
|
1007
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
1008
|
+
end
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
it 'loads the valid cues when syntax is incorrect' do
|
1012
|
+
FakeFS do
|
1013
|
+
File.open(path, 'w') do |subs|
|
1014
|
+
subs.write(<<-eos
|
1015
|
+
00:02:04.240,00:02:05.593
|
1016
|
+
It was funny, huh?
|
1017
|
+
|
1018
|
+
00:02:06.320.00:02:07.639
|
1019
|
+
Yes, but I have to go.
|
1020
|
+
|
1021
|
+
00:02:07.840,00:02:09.831
|
1022
|
+
That'll teach you to excite[br]yourself like this.
|
1023
|
+
eos
|
1024
|
+
)
|
1025
|
+
end
|
1026
|
+
cues = []
|
1027
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 4, 240000), Time.mktime(1, 1, 1, 0, 2, 5, 593000), "It was funny, huh?")
|
1028
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 7, 840000), Time.mktime(1, 1, 1, 0, 2, 9, 831000), "That'll teach you to excite\nyourself like this.")
|
1029
|
+
|
1030
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
1031
|
+
|
1032
|
+
File.open(path, 'w') do |subs|
|
1033
|
+
subs.write(<<-eos
|
1034
|
+
00:02:04240,00:02:05.593
|
1035
|
+
It was funny, huh?
|
1036
|
+
|
1037
|
+
00:02:06.320,00:02:07.639
|
1038
|
+
Yes, but I have to go.
|
1039
|
+
|
1040
|
+
00:02:07.840,00:02:.831
|
1041
|
+
That'll teach you to excite[br]yourself like this.
|
1042
|
+
eos
|
1043
|
+
)
|
1044
|
+
end
|
1045
|
+
cues = []
|
1046
|
+
cues << Cue.new(Time.mktime(1, 1, 1, 0, 2, 6, 320000), Time.mktime(1, 1, 1, 0, 2, 7, 639000), "Yes, but I have to go.")
|
1047
|
+
|
1048
|
+
new_reader(path).read_subs(false)[0].should eq cues
|
1049
|
+
end
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
end
|
1053
|
+
end
|