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,891 @@
|
|
1
|
+
require 'subtitle-library'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
|
4
|
+
describe SubsChanger 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_changer(path)
|
21
|
+
SubsChanger.new path
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'shifting subrip format' do
|
25
|
+
path = 'subs.srt'
|
26
|
+
|
27
|
+
it 'shifts the subtitles by seconds' do
|
28
|
+
FakeFS do
|
29
|
+
lines = "1\n"
|
30
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
31
|
+
lines += "You want some water with that?\n\n"
|
32
|
+
lines += "2\n"
|
33
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
34
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
35
|
+
lines += "3\n"
|
36
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
37
|
+
lines += "Looks like you had a night.\n\n"
|
38
|
+
|
39
|
+
File.open(path, 'w') do |subs|
|
40
|
+
subs.write(lines)
|
41
|
+
end
|
42
|
+
|
43
|
+
new_changer(path).shift('ss', 1.5)
|
44
|
+
|
45
|
+
lines = "1\n"
|
46
|
+
lines += "00:03:41,595 --> 00:03:42,929\n"
|
47
|
+
lines += "You want some water with that?\n\n"
|
48
|
+
lines += "2\n"
|
49
|
+
lines += "00:03:43,013 --> 00:03:44,431\n"
|
50
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
51
|
+
lines += "3\n"
|
52
|
+
lines += "00:03:45,140 --> 00:03:46,558\n"
|
53
|
+
lines += "Looks like you had a night.\n\n"
|
54
|
+
|
55
|
+
File.open(path, 'r') do |subs|
|
56
|
+
subs.read.should eq lines
|
57
|
+
end
|
58
|
+
|
59
|
+
new_changer(path).shift('ss', -3.4)
|
60
|
+
|
61
|
+
lines = "1\n"
|
62
|
+
lines += "00:03:38,195 --> 00:03:39,529\n"
|
63
|
+
lines += "You want some water with that?\n\n"
|
64
|
+
lines += "2\n"
|
65
|
+
lines += "00:03:39,613 --> 00:03:41,031\n"
|
66
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
67
|
+
lines += "3\n"
|
68
|
+
lines += "00:03:41,740 --> 00:03:43,158\n"
|
69
|
+
lines += "Looks like you had a night.\n\n"
|
70
|
+
|
71
|
+
File.open(path, 'r') do |subs|
|
72
|
+
subs.read.should eq lines
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'shifts the subtitles by frames' do
|
78
|
+
FakeFS do
|
79
|
+
lines = "1\n"
|
80
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
81
|
+
lines += "You want some water with that?\n\n"
|
82
|
+
lines += "2\n"
|
83
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
84
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
85
|
+
lines += "3\n"
|
86
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
87
|
+
lines += "Looks like you had a night.\n\n"
|
88
|
+
|
89
|
+
File.open(path, 'w') do |subs|
|
90
|
+
subs.write(lines)
|
91
|
+
end
|
92
|
+
|
93
|
+
new_changer(path).shift('fs', 45)
|
94
|
+
|
95
|
+
lines = "1\n"
|
96
|
+
lines += "00:03:41,971 --> 00:03:43,305\n"
|
97
|
+
lines += "You want some water with that?\n\n"
|
98
|
+
lines += "2\n"
|
99
|
+
lines += "00:03:43,389 --> 00:03:44,807\n"
|
100
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
101
|
+
lines += "3\n"
|
102
|
+
lines += "00:03:45,516 --> 00:03:46,934\n"
|
103
|
+
lines += "Looks like you had a night.\n\n"
|
104
|
+
|
105
|
+
File.open(path, 'r') do |subs|
|
106
|
+
subs.read.should eq lines
|
107
|
+
end
|
108
|
+
|
109
|
+
new_changer(path).shift('fs', -15, 25)
|
110
|
+
|
111
|
+
lines = "1\n"
|
112
|
+
lines += "00:03:40,971 --> 00:03:42,305\n"
|
113
|
+
lines += "You want some water with that?\n\n"
|
114
|
+
lines += "2\n"
|
115
|
+
lines += "00:03:42,389 --> 00:03:43,807\n"
|
116
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
117
|
+
lines += "3\n"
|
118
|
+
lines += "00:03:44,516 --> 00:03:45,934\n"
|
119
|
+
lines += "Looks like you had a night.\n\n"
|
120
|
+
|
121
|
+
File.open(path, 'r') do |subs|
|
122
|
+
subs.read.should eq lines
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "doesn't shift when an invalid timing is calculated" do
|
128
|
+
FakeFS do
|
129
|
+
lines = "1\n"
|
130
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
131
|
+
lines += "You want some water with that?\n\n"
|
132
|
+
lines += "2\n"
|
133
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
134
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
135
|
+
lines += "3\n"
|
136
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
137
|
+
lines += "Looks like you had a night.\n\n"
|
138
|
+
|
139
|
+
File.open(path, 'w') do |subs|
|
140
|
+
subs.write(lines)
|
141
|
+
end
|
142
|
+
|
143
|
+
new_changer(path).shift('fs', -5280)
|
144
|
+
|
145
|
+
File.open(path, 'r') do |subs|
|
146
|
+
subs.read.should eq lines
|
147
|
+
end
|
148
|
+
|
149
|
+
new_changer(path).shift('ss', -221)
|
150
|
+
|
151
|
+
File.open(path, 'r') do |subs|
|
152
|
+
subs.read.should eq lines
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'shifting microdvd format' do
|
160
|
+
path = 'subs.sub'
|
161
|
+
|
162
|
+
it 'shifts the subtitles by frames' do
|
163
|
+
FakeFS do
|
164
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
165
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
166
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
167
|
+
|
168
|
+
File.open(path, 'w') do |subs|
|
169
|
+
subs.write(lines)
|
170
|
+
end
|
171
|
+
|
172
|
+
new_changer(path).shift('fs', 80)
|
173
|
+
|
174
|
+
lines = "{1}{1}23.976\n"
|
175
|
+
lines += "{5357}{5389}You want some water with that?\n"
|
176
|
+
lines += "{5391}{5425}No, no.|No, I don't.\n"
|
177
|
+
lines += "{5442}{5476}Looks like you had a night.\n"
|
178
|
+
|
179
|
+
File.open(path, 'r') do |subs|
|
180
|
+
subs.read.should eq lines
|
181
|
+
end
|
182
|
+
|
183
|
+
new_changer(path).shift('fs', -100)
|
184
|
+
|
185
|
+
lines = "{1}{1}23.976\n"
|
186
|
+
lines += "{5257}{5289}You want some water with that?\n"
|
187
|
+
lines += "{5291}{5325}No, no.|No, I don't.\n"
|
188
|
+
lines += "{5342}{5376}Looks like you had a night.\n"
|
189
|
+
|
190
|
+
File.open(path, 'r') do |subs|
|
191
|
+
subs.read.should eq lines
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'shifts the subtitles by seconds' do
|
197
|
+
FakeFS do
|
198
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
199
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
200
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
201
|
+
|
202
|
+
File.open(path, 'w') do |subs|
|
203
|
+
subs.write(lines)
|
204
|
+
end
|
205
|
+
|
206
|
+
new_changer(path).shift('ss', 10)
|
207
|
+
|
208
|
+
lines = "{1}{1}23.976\n"
|
209
|
+
lines += "{5517}{5549}You want some water with that?\n"
|
210
|
+
lines += "{5551}{5585}No, no.|No, I don't.\n"
|
211
|
+
lines += "{5602}{5636}Looks like you had a night.\n"
|
212
|
+
|
213
|
+
File.open(path, 'r') do |subs|
|
214
|
+
subs.read.should eq lines
|
215
|
+
end
|
216
|
+
|
217
|
+
new_changer(path).shift('ss', -21.2, 25)
|
218
|
+
|
219
|
+
lines = "{1}{1}23.976\n"
|
220
|
+
lines += "{4987}{5019}You want some water with that?\n"
|
221
|
+
lines += "{5021}{5055}No, no.|No, I don't.\n"
|
222
|
+
lines += "{5072}{5106}Looks like you had a night.\n"
|
223
|
+
|
224
|
+
File.open(path, 'r') do |subs|
|
225
|
+
subs.read.should eq lines
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
it "doesn't shift when an invalid timing is calculated" do
|
231
|
+
FakeFS do
|
232
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
233
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
234
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
235
|
+
|
236
|
+
File.open(path, 'w') do |subs|
|
237
|
+
subs.write(lines)
|
238
|
+
end
|
239
|
+
|
240
|
+
new_changer(path).shift('fs', -5300)
|
241
|
+
|
242
|
+
File.open(path, 'r') do |subs|
|
243
|
+
subs.read.should eq lines
|
244
|
+
end
|
245
|
+
|
246
|
+
new_changer(path).shift('ss', -212, 25)
|
247
|
+
|
248
|
+
File.open(path, 'r') do |subs|
|
249
|
+
subs.read.should eq lines
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
describe 'shifting subviewer format' do
|
258
|
+
path = 'subs.sub'
|
259
|
+
|
260
|
+
it 'shifts the subtitles by seconds' do
|
261
|
+
FakeFS do
|
262
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
263
|
+
lines += "You want some water with that?\n\n"
|
264
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
265
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
266
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
267
|
+
lines += "Looks like you had a night.\n\n"
|
268
|
+
|
269
|
+
File.open(path, 'w') do |subs|
|
270
|
+
subs.write(lines)
|
271
|
+
end
|
272
|
+
|
273
|
+
new_changer(path).shift('ss', 1.5)
|
274
|
+
|
275
|
+
lines = "[STYLE]no\n"
|
276
|
+
lines += "00:03:41.595,00:03:42.929\n"
|
277
|
+
lines += "You want some water with that?\n\n"
|
278
|
+
lines += "00:03:43.013,00:03:44.431\n"
|
279
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
280
|
+
lines += "00:03:45.140,00:03:46.558\n"
|
281
|
+
lines += "Looks like you had a night.\n\n"
|
282
|
+
|
283
|
+
File.open(path, 'r') do |subs|
|
284
|
+
subs.read.should eq lines
|
285
|
+
end
|
286
|
+
|
287
|
+
new_changer(path).shift('ss', -3.4)
|
288
|
+
|
289
|
+
lines = "[STYLE]no\n"
|
290
|
+
lines += "00:03:38.195,00:03:39.529\n"
|
291
|
+
lines += "You want some water with that?\n\n"
|
292
|
+
lines += "00:03:39.613,00:03:41.031\n"
|
293
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
294
|
+
lines += "00:03:41.740,00:03:43.158\n"
|
295
|
+
lines += "Looks like you had a night.\n\n"
|
296
|
+
|
297
|
+
File.open(path, 'r') do |subs|
|
298
|
+
subs.read.should eq lines
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'shifts the subtitles by frames' do
|
304
|
+
FakeFS do
|
305
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
306
|
+
lines += "You want some water with that?\n\n"
|
307
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
308
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
309
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
310
|
+
lines += "Looks like you had a night.\n\n"
|
311
|
+
|
312
|
+
File.open(path, 'w') do |subs|
|
313
|
+
subs.write(lines)
|
314
|
+
end
|
315
|
+
|
316
|
+
new_changer(path).shift('fs', 45)
|
317
|
+
|
318
|
+
lines = "[STYLE]no\n"
|
319
|
+
lines += "00:03:41.971,00:03:43.305\n"
|
320
|
+
lines += "You want some water with that?\n\n"
|
321
|
+
lines += "00:03:43.389,00:03:44.807\n"
|
322
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
323
|
+
lines += "00:03:45.516,00:03:46.934\n"
|
324
|
+
lines += "Looks like you had a night.\n\n"
|
325
|
+
|
326
|
+
File.open(path, 'r') do |subs|
|
327
|
+
subs.read.should eq lines
|
328
|
+
end
|
329
|
+
|
330
|
+
new_changer(path).shift('fs', -15, 25)
|
331
|
+
|
332
|
+
lines = "[STYLE]no\n"
|
333
|
+
lines += "00:03:40.971,00:03:42.305\n"
|
334
|
+
lines += "You want some water with that?\n\n"
|
335
|
+
lines += "00:03:42.389,00:03:43.807\n"
|
336
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
337
|
+
lines += "00:03:44.516,00:03:45.934\n"
|
338
|
+
lines += "Looks like you had a night.\n\n"
|
339
|
+
|
340
|
+
File.open(path, 'r') do |subs|
|
341
|
+
subs.read.should eq lines
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it "doesn't shift when an invalid timing is calculated" do
|
347
|
+
FakeFS do
|
348
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
349
|
+
lines += "You want some water with that?\n\n"
|
350
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
351
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
352
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
353
|
+
lines += "Looks like you had a night.\n\n"
|
354
|
+
|
355
|
+
File.open(path, 'w') do |subs|
|
356
|
+
subs.write(lines)
|
357
|
+
end
|
358
|
+
|
359
|
+
new_changer(path).shift('fs', -5280)
|
360
|
+
|
361
|
+
File.open(path, 'r') do |subs|
|
362
|
+
subs.read.should eq lines
|
363
|
+
end
|
364
|
+
|
365
|
+
new_changer(path).shift('ss', -221)
|
366
|
+
|
367
|
+
File.open(path, 'r') do |subs|
|
368
|
+
subs.read.should eq lines
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
end
|
374
|
+
|
375
|
+
describe 'stretching subrip format' do
|
376
|
+
path = 'subs.srt'
|
377
|
+
|
378
|
+
it 'stretches the subtitles by seconds' do
|
379
|
+
FakeFS do
|
380
|
+
lines = "1\n"
|
381
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
382
|
+
lines += "You want some water with that?\n\n"
|
383
|
+
lines += "2\n"
|
384
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
385
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
386
|
+
lines += "3\n"
|
387
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
388
|
+
lines += "Looks like you had a night.\n\n"
|
389
|
+
|
390
|
+
File.open(path, 'w') do |subs|
|
391
|
+
subs.write(lines)
|
392
|
+
end
|
393
|
+
|
394
|
+
new_changer(path).stretch('ss', 1.5)
|
395
|
+
|
396
|
+
lines = "1\n"
|
397
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
398
|
+
lines += "You want some water with that?\n\n"
|
399
|
+
lines += "2\n"
|
400
|
+
lines += "00:03:43,013 --> 00:03:44,431\n"
|
401
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
402
|
+
lines += "3\n"
|
403
|
+
lines += "00:03:46,640 --> 00:03:48,058\n"
|
404
|
+
lines += "Looks like you had a night.\n\n"
|
405
|
+
|
406
|
+
File.open(path, 'r') do |subs|
|
407
|
+
subs.read.should eq lines
|
408
|
+
end
|
409
|
+
|
410
|
+
new_changer(path).stretch('ss', -1.1)
|
411
|
+
|
412
|
+
lines = "1\n"
|
413
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
414
|
+
lines += "You want some water with that?\n\n"
|
415
|
+
lines += "2\n"
|
416
|
+
lines += "00:03:41,912 --> 00:03:43,330\n"
|
417
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
418
|
+
lines += "3\n"
|
419
|
+
lines += "00:03:44,439 --> 00:03:45,857\n"
|
420
|
+
lines += "Looks like you had a night.\n\n"
|
421
|
+
|
422
|
+
File.open(path, 'r') do |subs|
|
423
|
+
subs.read.should eq lines
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
it 'stretches the subtitles by frames' do
|
429
|
+
FakeFS do
|
430
|
+
lines = "1\n"
|
431
|
+
lines += "00:03:40,095 --> 00:03:40,429\n"
|
432
|
+
lines += "You want some water with that?\n\n"
|
433
|
+
lines += "2\n"
|
434
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
435
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
436
|
+
lines += "3\n"
|
437
|
+
lines += "00:03:44,640 --> 00:03:46,058\n"
|
438
|
+
lines += "Looks like you had a night.\n\n"
|
439
|
+
|
440
|
+
File.open(path, 'w') do |subs|
|
441
|
+
subs.write(lines)
|
442
|
+
end
|
443
|
+
|
444
|
+
new_changer(path).stretch('fs', 25)
|
445
|
+
|
446
|
+
lines = "1\n"
|
447
|
+
lines += "00:03:40,095 --> 00:03:40,429\n"
|
448
|
+
lines += "You want some water with that?\n\n"
|
449
|
+
lines += "2\n"
|
450
|
+
lines += "00:03:42,555 --> 00:03:43,973\n"
|
451
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
452
|
+
lines += "3\n"
|
453
|
+
lines += "00:03:46,725 --> 00:03:48,143\n"
|
454
|
+
lines += "Looks like you had a night.\n\n"
|
455
|
+
|
456
|
+
File.open(path, 'r') do |subs|
|
457
|
+
subs.read.should eq lines
|
458
|
+
end
|
459
|
+
|
460
|
+
new_changer(path).stretch('fs', -15, 25)
|
461
|
+
|
462
|
+
lines = "1\n"
|
463
|
+
lines += "00:03:40,095 --> 00:03:40,429\n"
|
464
|
+
lines += "You want some water with that?\n\n"
|
465
|
+
lines += "2\n"
|
466
|
+
lines += "00:03:41,555 --> 00:03:42,973\n"
|
467
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
468
|
+
lines += "3\n"
|
469
|
+
lines += "00:03:44,725 --> 00:03:46,143\n"
|
470
|
+
lines += "Looks like you had a night.\n\n"
|
471
|
+
|
472
|
+
File.open(path, 'r') do |subs|
|
473
|
+
subs.read.should eq lines
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
it "doesn't stretch when an invalid timing is calculated" do
|
479
|
+
FakeFS do
|
480
|
+
lines = "1\n"
|
481
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
482
|
+
lines += "You want some water with that?\n\n"
|
483
|
+
lines += "2\n"
|
484
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
485
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
486
|
+
lines += "3\n"
|
487
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
488
|
+
lines += "Looks like you had a night.\n\n"
|
489
|
+
|
490
|
+
File.open(path, 'w') do |subs|
|
491
|
+
subs.write(lines)
|
492
|
+
end
|
493
|
+
|
494
|
+
new_changer(path).stretch('fs', -10)
|
495
|
+
|
496
|
+
File.open(path, 'r') do |subs|
|
497
|
+
subs.read.should eq lines
|
498
|
+
end
|
499
|
+
|
500
|
+
new_changer(path).stretch('ss', -0.1)
|
501
|
+
|
502
|
+
File.open(path, 'r') do |subs|
|
503
|
+
subs.read.should eq lines
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
end
|
509
|
+
|
510
|
+
describe 'stretching microdvd format' do
|
511
|
+
path = 'subs.sub'
|
512
|
+
|
513
|
+
it 'stretchs the subtitles by frames' do
|
514
|
+
FakeFS do
|
515
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
516
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
517
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
518
|
+
|
519
|
+
File.open(path, 'w') do |subs|
|
520
|
+
subs.write(lines)
|
521
|
+
end
|
522
|
+
|
523
|
+
new_changer(path).stretch('fs', 80)
|
524
|
+
|
525
|
+
lines = "{1}{1}23.976\n"
|
526
|
+
lines += "{5277}{5309}You want some water with that?\n"
|
527
|
+
lines += "{5391}{5425}No, no.|No, I don't.\n"
|
528
|
+
lines += "{5522}{5556}Looks like you had a night.\n"
|
529
|
+
|
530
|
+
File.open(path, 'r') do |subs|
|
531
|
+
subs.read.should eq lines
|
532
|
+
end
|
533
|
+
|
534
|
+
new_changer(path).stretch('fs', -10)
|
535
|
+
|
536
|
+
lines = "{1}{1}23.976\n"
|
537
|
+
lines += "{5277}{5309}You want some water with that?\n"
|
538
|
+
lines += "{5381}{5415}No, no.|No, I don't.\n"
|
539
|
+
lines += "{5502}{5536}Looks like you had a night.\n"
|
540
|
+
|
541
|
+
File.open(path, 'r') do |subs|
|
542
|
+
subs.read.should eq lines
|
543
|
+
end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
it 'stretchs the subtitles by seconds' do
|
548
|
+
FakeFS do
|
549
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
550
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
551
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
552
|
+
|
553
|
+
File.open(path, 'w') do |subs|
|
554
|
+
subs.write(lines)
|
555
|
+
end
|
556
|
+
|
557
|
+
new_changer(path).stretch('ss', 10)
|
558
|
+
|
559
|
+
lines = "{1}{1}23.976\n"
|
560
|
+
lines += "{5277}{5309}You want some water with that?\n"
|
561
|
+
lines += "{5551}{5585}No, no.|No, I don't.\n"
|
562
|
+
lines += "{5842}{5876}Looks like you had a night.\n"
|
563
|
+
|
564
|
+
File.open(path, 'r') do |subs|
|
565
|
+
subs.read.should eq lines
|
566
|
+
end
|
567
|
+
|
568
|
+
new_changer(path).stretch('ss', -1.2, 25)
|
569
|
+
|
570
|
+
lines = "{1}{1}23.976\n"
|
571
|
+
lines += "{5277}{5309}You want some water with that?\n"
|
572
|
+
lines += "{5521}{5555}No, no.|No, I don't.\n"
|
573
|
+
lines += "{5782}{5816}Looks like you had a night.\n"
|
574
|
+
|
575
|
+
File.open(path, 'r') do |subs|
|
576
|
+
subs.read.should eq lines
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
it "doesn't stretch when an invalid timing is calculated" do
|
582
|
+
FakeFS do
|
583
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
584
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
585
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
586
|
+
|
587
|
+
File.open(path, 'w') do |subs|
|
588
|
+
subs.write(lines)
|
589
|
+
end
|
590
|
+
|
591
|
+
new_changer(path).stretch('fs', -3)
|
592
|
+
|
593
|
+
File.open(path, 'r') do |subs|
|
594
|
+
subs.read.should eq lines
|
595
|
+
end
|
596
|
+
|
597
|
+
new_changer(path).stretch('ss', -1, 25)
|
598
|
+
|
599
|
+
File.open(path, 'r') do |subs|
|
600
|
+
subs.read.should eq lines
|
601
|
+
end
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
end
|
606
|
+
|
607
|
+
describe 'stretching subviewer format' do
|
608
|
+
path = 'subs.sub'
|
609
|
+
|
610
|
+
it 'stretches the subtitles by seconds' do
|
611
|
+
FakeFS do
|
612
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
613
|
+
lines += "You want some water with that?\n\n"
|
614
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
615
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
616
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
617
|
+
lines += "Looks like you had a night.\n\n"
|
618
|
+
|
619
|
+
File.open(path, 'w') do |subs|
|
620
|
+
subs.write(lines)
|
621
|
+
end
|
622
|
+
|
623
|
+
new_changer(path).stretch('ss', 1.5)
|
624
|
+
|
625
|
+
lines = "[STYLE]no\n"
|
626
|
+
lines += "00:03:40.095,00:03:41.429\n"
|
627
|
+
lines += "You want some water with that?\n\n"
|
628
|
+
lines += "00:03:43.013,00:03:44.431\n"
|
629
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
630
|
+
lines += "00:03:46.640,00:03:48.058\n"
|
631
|
+
lines += "Looks like you had a night.\n\n"
|
632
|
+
|
633
|
+
File.open(path, 'r') do |subs|
|
634
|
+
subs.read.should eq lines
|
635
|
+
end
|
636
|
+
|
637
|
+
new_changer(path).stretch('ss', -1.1)
|
638
|
+
|
639
|
+
lines = "[STYLE]no\n"
|
640
|
+
lines += "00:03:40.095,00:03:41.429\n"
|
641
|
+
lines += "You want some water with that?\n\n"
|
642
|
+
lines += "00:03:41.912,00:03:43.330\n"
|
643
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
644
|
+
lines += "00:03:44.439,00:03:45.857\n"
|
645
|
+
lines += "Looks like you had a night.\n\n"
|
646
|
+
|
647
|
+
File.open(path, 'r') do |subs|
|
648
|
+
subs.read.should eq lines
|
649
|
+
end
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
it 'stretches the subtitles by frames' do
|
654
|
+
FakeFS do
|
655
|
+
lines = "00:03:40.095,00:03:40.429\n"
|
656
|
+
lines += "You want some water with that?\n\n"
|
657
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
658
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
659
|
+
lines += "00:03:44.640,00:03:46.058\n"
|
660
|
+
lines += "Looks like you had a night.\n\n"
|
661
|
+
|
662
|
+
File.open(path, 'w') do |subs|
|
663
|
+
subs.write(lines)
|
664
|
+
end
|
665
|
+
|
666
|
+
new_changer(path).stretch('fs', 25)
|
667
|
+
|
668
|
+
lines = "[STYLE]no\n"
|
669
|
+
lines += "00:03:40.095,00:03:40.429\n"
|
670
|
+
lines += "You want some water with that?\n\n"
|
671
|
+
lines += "00:03:42.555,00:03:43.973\n"
|
672
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
673
|
+
lines += "00:03:46.725,00:03:48.143\n"
|
674
|
+
lines += "Looks like you had a night.\n\n"
|
675
|
+
|
676
|
+
File.open(path, 'r') do |subs|
|
677
|
+
subs.read.should eq lines
|
678
|
+
end
|
679
|
+
|
680
|
+
new_changer(path).stretch('fs', -15, 25)
|
681
|
+
|
682
|
+
lines = "[STYLE]no\n"
|
683
|
+
lines += "00:03:40.095,00:03:40.429\n"
|
684
|
+
lines += "You want some water with that?\n\n"
|
685
|
+
lines += "00:03:41.555,00:03:42.973\n"
|
686
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
687
|
+
lines += "00:03:44.725,00:03:46.143\n"
|
688
|
+
lines += "Looks like you had a night.\n\n"
|
689
|
+
|
690
|
+
File.open(path, 'r') do |subs|
|
691
|
+
subs.read.should eq lines
|
692
|
+
end
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
696
|
+
it "doesn't stretch when an invalid timing is calculated" do
|
697
|
+
FakeFS do
|
698
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
699
|
+
lines += "You want some water with that?\n\n"
|
700
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
701
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
702
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
703
|
+
lines += "Looks like you had a night.\n\n"
|
704
|
+
|
705
|
+
File.open(path, 'w') do |subs|
|
706
|
+
subs.write(lines)
|
707
|
+
end
|
708
|
+
|
709
|
+
new_changer(path).stretch('fs', -10)
|
710
|
+
|
711
|
+
File.open(path, 'r') do |subs|
|
712
|
+
subs.read.should eq lines
|
713
|
+
end
|
714
|
+
|
715
|
+
new_changer(path).stretch('ss', -1)
|
716
|
+
|
717
|
+
File.open(path, 'r') do |subs|
|
718
|
+
subs.read.should eq lines
|
719
|
+
end
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|
723
|
+
end
|
724
|
+
|
725
|
+
describe 'setting the max line length of the subrip format' do
|
726
|
+
path = 'subs.srt'
|
727
|
+
|
728
|
+
it 'sets the max line length where needed' do
|
729
|
+
FakeFS do
|
730
|
+
lines = "1\n"
|
731
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
732
|
+
lines += "You want some water with that?\n\n"
|
733
|
+
lines += "2\n"
|
734
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
735
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
736
|
+
lines += "3\n"
|
737
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
738
|
+
lines += "Looks like you had a night.\n\n"
|
739
|
+
|
740
|
+
File.open(path, 'w') do |subs|
|
741
|
+
subs.write(lines)
|
742
|
+
end
|
743
|
+
|
744
|
+
new_changer(path).set_max_line(14)
|
745
|
+
|
746
|
+
lines = "1\n"
|
747
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
748
|
+
lines += "You want some water\nwith that?\n\n"
|
749
|
+
lines += "2\n"
|
750
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
751
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
752
|
+
lines += "3\n"
|
753
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
754
|
+
lines += "Looks like you had\na night.\n\n"
|
755
|
+
|
756
|
+
File.open(path, 'r') do |subs|
|
757
|
+
subs.read.should eq lines
|
758
|
+
end
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
it "doesn't change the subtitles when not needed" do
|
763
|
+
FakeFS do
|
764
|
+
lines = "1\n"
|
765
|
+
lines += "00:03:40,095 --> 00:03:41,429\n"
|
766
|
+
lines += "You want some water with that?\n\n"
|
767
|
+
lines += "2\n"
|
768
|
+
lines += "00:03:41,513 --> 00:03:42,931\n"
|
769
|
+
lines += "No, no.\nNo, I don't.\n\n"
|
770
|
+
lines += "3\n"
|
771
|
+
lines += "00:03:43,640 --> 00:03:45,058\n"
|
772
|
+
lines += "Looks like you had a night.\n\n"
|
773
|
+
|
774
|
+
File.open(path, 'w') do |subs|
|
775
|
+
subs.write(lines)
|
776
|
+
end
|
777
|
+
|
778
|
+
new_changer(path).set_max_line(32)
|
779
|
+
|
780
|
+
File.open(path, 'r') do |subs|
|
781
|
+
subs.read.should eq lines
|
782
|
+
end
|
783
|
+
end
|
784
|
+
end
|
785
|
+
|
786
|
+
end
|
787
|
+
|
788
|
+
describe 'setting the max line length of the microdvd format' do
|
789
|
+
path = 'subs.sub'
|
790
|
+
|
791
|
+
it 'sets the max line length where needed' do
|
792
|
+
FakeFS do
|
793
|
+
lines = "{5277}{5309}You want some water with that?\n"
|
794
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
795
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
796
|
+
|
797
|
+
File.open(path, 'w') do |subs|
|
798
|
+
subs.write(lines)
|
799
|
+
end
|
800
|
+
|
801
|
+
new_changer(path).set_max_line(14)
|
802
|
+
|
803
|
+
lines = "{1}{1}23.976\n"
|
804
|
+
lines += "{5277}{5309}You want some water|with that?\n"
|
805
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
806
|
+
lines += "{5362}{5396}Looks like you had|a night.\n"
|
807
|
+
|
808
|
+
File.open(path, 'r') do |subs|
|
809
|
+
subs.read.should eq lines
|
810
|
+
end
|
811
|
+
end
|
812
|
+
end
|
813
|
+
|
814
|
+
it "doesn't change the subtitles when not needed" do
|
815
|
+
FakeFS do
|
816
|
+
lines = "{1}{1}23.976\n"
|
817
|
+
lines += "{5277}{5309}You want some water with that?\n"
|
818
|
+
lines += "{5311}{5345}No, no.|No, I don't.\n"
|
819
|
+
lines += "{5362}{5396}Looks like you had a night.\n"
|
820
|
+
|
821
|
+
File.open(path, 'w') do |subs|
|
822
|
+
subs.write(lines)
|
823
|
+
end
|
824
|
+
|
825
|
+
new_changer(path).set_max_line(32)
|
826
|
+
|
827
|
+
File.open(path, 'r') do |subs|
|
828
|
+
subs.read.should eq lines
|
829
|
+
end
|
830
|
+
end
|
831
|
+
end
|
832
|
+
end
|
833
|
+
|
834
|
+
|
835
|
+
describe 'setting the max line length of the subviewer format' do
|
836
|
+
path = 'subs.sub'
|
837
|
+
|
838
|
+
it 'sets the max line length where needed' do
|
839
|
+
FakeFS do
|
840
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
841
|
+
lines += "You want some water with that?\n\n"
|
842
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
843
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
844
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
845
|
+
lines += "Looks like you had a night.\n\n"
|
846
|
+
|
847
|
+
File.open(path, 'w') do |subs|
|
848
|
+
subs.write(lines)
|
849
|
+
end
|
850
|
+
|
851
|
+
new_changer(path).set_max_line(14)
|
852
|
+
|
853
|
+
lines = "[STYLE]no\n"
|
854
|
+
lines += "00:03:40.095,00:03:41.429\n"
|
855
|
+
lines += "You want some water[br]with that?\n\n"
|
856
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
857
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
858
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
859
|
+
lines += "Looks like you had[br]a night.\n\n"
|
860
|
+
|
861
|
+
File.open(path, 'r') do |subs|
|
862
|
+
subs.read.should eq lines
|
863
|
+
end
|
864
|
+
end
|
865
|
+
end
|
866
|
+
|
867
|
+
it "doesn't change the subtitles when not needed" do
|
868
|
+
FakeFS do
|
869
|
+
lines = "00:03:40.095,00:03:41.429\n"
|
870
|
+
lines += "You want some water with that?\n\n"
|
871
|
+
lines += "00:03:41.513,00:03:42.931\n"
|
872
|
+
lines += "No, no.[br]No, I don't.\n\n"
|
873
|
+
lines += "00:03:43.640,00:03:45.058\n"
|
874
|
+
lines += "Looks like you had a night.\n\n"
|
875
|
+
|
876
|
+
File.open(path, 'w') do |subs|
|
877
|
+
subs.write(lines)
|
878
|
+
end
|
879
|
+
|
880
|
+
new_changer(path).set_max_line(32)
|
881
|
+
|
882
|
+
lines = "[STYLE]no\n" + lines
|
883
|
+
|
884
|
+
File.open(path, 'r') do |subs|
|
885
|
+
subs.read.should eq lines
|
886
|
+
end
|
887
|
+
end
|
888
|
+
end
|
889
|
+
end
|
890
|
+
|
891
|
+
end
|