srt 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Mzk5Mjk2ZGU5NjI2NTZjYWVmN2JkN2E1MTY4ZjJkMmEzZmRmNzA5ZA==
5
- data.tar.gz: !binary |-
6
- MTIxY2EyYTczM2Q2NTg1NjZlZGNlNDQ4ZGQ4MDRmZDBmOWE3OTA1Yg==
2
+ SHA256:
3
+ metadata.gz: 28e7323497b349d7a2089aa395ad2c1ba1c3985729111dc56706c3280521bb5f
4
+ data.tar.gz: 82fe89057aee1e6a6aea48a16d33740686a18d0444f5559820603ff1b9a2a062
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTQyM2M1Y2I4ZDY5MGJkNTk3MWVkNGJkNzk5ZWI5MTJkYjZkMjBiYzhmMDY0
10
- YThlZDQyOWQ5YzRmYjNjODkwYjFmMGM4ZjQ1ZTgwN2QwMTJiOWM3Y2I0Y2M1
11
- Njc4NTg5ZjI5ZTNiZTAxZjYzYzQzZjg2YmFjODY5NzUyOTVjOTE=
12
- data.tar.gz: !binary |-
13
- NzIyNzExYzBiMjYzZWMzOGVkZDMyZjhiN2EyNWNmNGZhNThhNzkwMDhmNGRk
14
- NGE3ZTMxMjA5YmNlYjJmYmNmZmZmYTgwNDIzOWJkZjA2YzE2YzAyZThlOGY5
15
- ZTNhYTBlN2ZiYmFlYmY2ZmM4NzI0ODc5NTg4MmFmNDY5YjE1NTE=
6
+ metadata.gz: 699aaea2dda022acb10cb2e5d1db24d36ad8adec53528b1e186c6b75a549a049cbfd33f806d2cd4e276ae7ecabde412c9e9181c50335dc2f613ac79cefda5f31
7
+ data.tar.gz: c8abffc1bf997c624ee0cb0e06b0a49b9dd88b584a6fdb3c9edbd3170acb3a5e8a449b4d35eb3edfd2bc825c79389170da2d44589be602b02dced7a39223e4ef
@@ -1,2 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.3.0
1
7
  script:
2
- - bundle exec rake spec
8
+ - bundle exec rake spec
@@ -67,6 +67,7 @@ module SRT
67
67
  srt_data.split(/\n/) + ["\n"]
68
68
  rescue
69
69
  begin
70
+ srt_data = srt_data.unpack("C*").pack("U*")
70
71
  srt_data.force_encoding('utf-8').split(/\n/) + ["\n"]
71
72
  rescue
72
73
  srt_data.force_encoding('iso-8859-1').split(/\n/) + ["\n"]
@@ -167,10 +168,10 @@ module SRT
167
168
  line.end_time += seconds
168
169
  end
169
170
  elsif (original_framerate = Parser.framerate(options.keys[0])) && (target_framerate = Parser.framerate(options.values[0]))
170
- ratio = target_framerate / original_framerate
171
+ time_ratio = original_framerate / target_framerate
171
172
  lines.each do |line|
172
- line.start_time *= ratio
173
- line.end_time *= ratio
173
+ line.start_time *= time_ratio
174
+ line.end_time *= time_ratio
174
175
  end
175
176
  end
176
177
  elsif options.length == 2
@@ -209,13 +210,13 @@ module SRT
209
210
  end
210
211
 
211
212
  def to_s(time_str_function=:time_str)
212
- lines.map { |l| [l.sequence, (l.display_coordinates ? l.send(time_str_function) + l.display_coordinates : l.send(time_str_function)), l.text, ""] }.flatten.join("\n")
213
+ lines.map { |l| l.to_s(time_str_function) }.join("\n")
213
214
  end
214
215
 
215
216
  def to_webvtt
216
217
  header = <<eos
217
218
  WEBVTT
218
- X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000
219
+ X-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000
219
220
 
220
221
  eos
221
222
  header + to_s(:webvtt_time_str)
@@ -33,11 +33,17 @@ module SRT
33
33
  end
34
34
 
35
35
  def time_str(subframe_separator=",")
36
- [@start_time, @end_time].map { |t| sprintf("%02d:%02d:%02d#{subframe_separator}%s", t / 3600, (t % 3600) / 60, t % 60, sprintf("%.3f", t)[-3, 3]) }.join(" --> ")
36
+ [@start_time, @end_time].map { |t| f=sprintf("%.3f", t); ip=f[0,f.size-4].to_i;fp=f[-3,3]; "%02d:%02d:%02d#{subframe_separator}%s" % [ip / 3600, (ip % 3600) / 60, ip % 60,fp] }.join(" --> ")
37
37
  end
38
38
 
39
39
  def webvtt_time_str
40
40
  time_str(".")
41
41
  end
42
+
43
+ def to_s(time_str_function=:time_str)
44
+ content = text.empty? ? [''] : text
45
+ coordinates = display_coordinates ? display_coordinates : ""
46
+ [sequence, send(time_str_function) + coordinates, content, ""].flatten.join("\n")
47
+ end
42
48
  end
43
49
  end
@@ -12,7 +12,7 @@ module SRT
12
12
  end
13
13
 
14
14
  def timecode(timecode_string)
15
- mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+),(?<ms>\d+)/)
15
+ mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+)[,.]?(?<ms>\d+)?/)
16
16
  mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["ms"]}".to_f : nil
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module SRT
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'spec_helper'
2
3
  require 'srt'
3
4
 
@@ -5,14 +6,14 @@ describe SRT::File do
5
6
  describe '#parse' do
6
7
  context "parsing with debug true" do
7
8
  it "should be verbose when failing" do
8
- $stderr.should_receive(:puts).once
9
- SRT::File.parse(File.open("./spec/fixtures/invalid.srt"), debug: true).errors.should_not be_empty
9
+ expect($stderr).to receive(:puts).once
10
+ expect(SRT::File.parse(File.open("./spec/fixtures/invalid.srt"), debug: true).errors).not_to be_empty
10
11
  end
11
12
  end
12
13
  context "parsing with debug false" do
13
14
  it "should raise exception silently" do
14
- $stderr.should_not_receive(:puts)
15
- SRT::File.parse(File.open("./spec/fixtures/invalid.srt")).errors.should_not be_empty
15
+ expect($stderr).not_to receive(:puts)
16
+ expect(SRT::File.parse(File.open("./spec/fixtures/invalid.srt")).errors).not_to be_empty
16
17
  end
17
18
  end
18
19
  end
@@ -20,39 +21,39 @@ describe SRT::File do
20
21
  shared_examples_for "an SRT file" do
21
22
  context "when parsing a properly formatted BSG SRT file" do
22
23
  it "should return an SRT::File" do
23
- subject.class.should eq(SRT::File)
24
+ expect(subject.class).to eq(SRT::File)
24
25
  end
25
26
 
26
27
  it "should have 600 lines" do
27
- subject.lines.size.should eq(600)
28
+ expect(subject.lines.size).to eq(600)
28
29
  end
29
30
 
30
31
  it "should have no errors" do
31
- subject.errors.should be_empty
32
+ expect(subject.errors).to be_empty
32
33
  end
33
34
 
34
35
  it "should have the expected sequence number on the first subtitle" do
35
- subject.lines.first.sequence.should eq(1)
36
+ expect(subject.lines.first.sequence).to eq(1)
36
37
  end
37
38
 
38
39
  it "should have the expected timecodes on the first subtitle" do
39
- subject.lines.first.time_str.should eq("00:00:02,110 --> 00:00:04,578")
40
+ expect(subject.lines.first.time_str).to eq("00:00:02,110 --> 00:00:04,578")
40
41
  end
41
42
 
42
43
  it "should have the expected text on the first subtitle" do
43
- subject.lines.first.text.should eq(["<i>(male narrator) Previously", "on Battlestar Galactica.</i>"])
44
+ expect(subject.lines.first.text).to eq(["<i>(male narrator) Previously", "on Battlestar Galactica.</i>"])
44
45
  end
45
46
 
46
47
  it "should have the expected sequence number on the last subtitle" do
47
- subject.lines.last.sequence.should eq(600)
48
+ expect(subject.lines.last.sequence).to eq(600)
48
49
  end
49
50
 
50
51
  it "should have the expected timecodes on the last subtitle" do
51
- subject.lines.last.time_str.should eq("00:43:26,808 --> 00:43:28,139")
52
+ expect(subject.lines.last.time_str).to eq("00:43:26,808 --> 00:43:28,139")
52
53
  end
53
54
 
54
55
  it "should have the expected text on the last subtitle" do
55
- subject.lines.last.text.should eq(["Thank you."])
56
+ expect(subject.lines.last.text).to eq(["Thank you."])
56
57
  end
57
58
  end
58
59
  end
@@ -62,15 +63,20 @@ describe SRT::File do
62
63
  let(:file) { SRT::File.parse(File.open("./spec/fixtures/wotw-dubious.srt")) }
63
64
 
64
65
  it "should parse" do
65
- file.class.should eq(SRT::File)
66
+ expect(file.class).to eq(SRT::File)
66
67
  end
67
68
 
68
69
  it "should have 1123 lines" do
69
- file.lines.size.should eq(1123)
70
+ expect(file.lines.size).to eq(1123)
70
71
  end
71
72
 
72
73
  it "should have no errors" do
73
- file.errors.should be_empty
74
+ expect(file.errors).to be_empty
75
+ end
76
+
77
+ it "should convert some dubious UTF-8 encodings" do
78
+ first_line = file.lines.first.text.join(" ")
79
+ expect(first_line).to eq("<i>Nadie habría creído en los primeros años del siglo 21...</i>")
74
80
  end
75
81
  end
76
82
 
@@ -78,23 +84,23 @@ describe SRT::File do
78
84
  let(:file) { SRT::File.parse(File.open("./spec/fixtures/coordinates-dummy.srt")) }
79
85
 
80
86
  it "should return an SRT::File" do
81
- file.class.should eq(SRT::File)
87
+ expect(file.class).to eq(SRT::File)
82
88
  end
83
89
 
84
90
  it "should have 3 lines" do
85
- file.lines.size.should eq(3)
91
+ expect(file.lines.size).to eq(3)
86
92
  end
87
93
 
88
94
  it "should have no errors" do
89
- file.errors.should be_empty
95
+ expect(file.errors).to be_empty
90
96
  end
91
97
 
92
98
  it "should have the expected display coordinates on the first subtitle" do
93
- file.lines.first.display_coordinates.should eq("X1:100 X2:600 Y1:1 Y2:4")
99
+ expect(file.lines.first.display_coordinates).to eq("X1:100 X2:600 Y1:1 Y2:4")
94
100
  end
95
101
 
96
102
  it "should have the expected display coordinates on the last subtitle" do
97
- file.lines.last.display_coordinates.should eq("X1:1 X2:333 Y1:50 Y2:29")
103
+ expect(file.lines.last.display_coordinates).to eq("X1:1 X2:333 Y1:50 Y2:29")
98
104
  end
99
105
  end
100
106
  end
@@ -118,19 +124,19 @@ describe SRT::File do
118
124
  before { part1.append({ "00:53:57,241" => part2 }) }
119
125
 
120
126
  it "should have grown to 808 subtitles" do
121
- part1.lines.length.should eq(808)
127
+ expect(part1.lines.length).to eq(808)
122
128
  end
123
129
 
124
130
  it "should have appended subtitles starting with sequence number 448" do
125
- part1.lines[447].sequence.should eq(448)
131
+ expect(part1.lines[447].sequence).to eq(448)
126
132
  end
127
133
 
128
134
  it "should have appended subtitles ending with sequence number 808" do
129
- part1.lines.last.sequence.should eq(808)
135
+ expect(part1.lines.last.sequence).to eq(808)
130
136
  end
131
137
 
132
138
  it "should have appended subtitles relatively from 00:53:57,241" do
133
- part1.lines[447].time_str.should eq("00:54:02,152 --> 00:54:04,204")
139
+ expect(part1.lines[447].time_str).to eq("00:54:02,152 --> 00:54:04,204")
134
140
  end
135
141
  end
136
142
 
@@ -138,7 +144,7 @@ describe SRT::File do
138
144
  before { part1.append({ "+7.241s" => part2 }) }
139
145
 
140
146
  it "should have appended subtitles relatively from +7.241s after the previously last subtitle" do
141
- part1.lines[447].time_str.should eq("00:54:02,283 --> 00:54:04,335")
147
+ expect(part1.lines[447].time_str).to eq("00:54:02,283 --> 00:54:04,335")
142
148
  end
143
149
  end
144
150
  end
@@ -152,29 +158,29 @@ describe SRT::File do
152
158
  let(:result) { file.split( :at => "00:19:24,500" ) }
153
159
 
154
160
  it "should return an array containing two SRT::File instances" do
155
- result.length.should eq(2)
156
- result[0].class.should eq(SRT::File)
157
- result[1].class.should eq(SRT::File)
161
+ expect(result.length).to eq(2)
162
+ expect(result[0].class).to eq(SRT::File)
163
+ expect(result[1].class).to eq(SRT::File)
158
164
  end
159
165
 
160
166
  it "should include a subtitle that overlaps a splitting point in the first file" do
161
- result[0].lines.last.text.should eq(["I'll see you guys in combat."])
167
+ expect(result[0].lines.last.text).to eq(["I'll see you guys in combat."])
162
168
  end
163
169
 
164
170
  it "should make an overlapping subtitle end at the splitting point in the first file" do
165
- result[0].lines.last.time_str.should eq("00:19:23,901 --> 00:19:24,500")
171
+ expect(result[0].lines.last.time_str).to eq("00:19:23,901 --> 00:19:24,500")
166
172
  end
167
173
 
168
174
  it "should include a subtitle that overlaps a splitting point in the second file as well" do
169
- result[1].lines.first.text.should eq(["I'll see you guys in combat."])
175
+ expect(result[1].lines.first.text).to eq(["I'll see you guys in combat."])
170
176
  end
171
177
 
172
178
  it "should make an overlapping subtitle remain at the beginning in the second file" do
173
- result[1].lines.first.time_str.should eq("00:00:00,000 --> 00:00:01,528")
179
+ expect(result[1].lines.first.time_str).to eq("00:00:00,000 --> 00:00:01,528")
174
180
  end
175
181
 
176
182
  it "should shift back all timecodes of the second file relative to the new file beginning" do
177
- result[1].lines[1].time_str.should eq("00:00:01,737 --> 00:00:03,466")
183
+ expect(result[1].lines[1].time_str).to eq("00:00:01,737 --> 00:00:03,466")
178
184
  end
179
185
  end
180
186
 
@@ -182,29 +188,29 @@ describe SRT::File do
182
188
  let(:result) { file.split( :at => "00:19:24,500", :timeshift => false ) }
183
189
 
184
190
  it "should return an array containing two SRT::File instances" do
185
- result.length.should eq(2)
186
- result[0].class.should eq(SRT::File)
187
- result[1].class.should eq(SRT::File)
191
+ expect(result.length).to eq(2)
192
+ expect(result[0].class).to eq(SRT::File)
193
+ expect(result[1].class).to eq(SRT::File)
188
194
  end
189
195
 
190
196
  it "should include a subtitle that overlaps a splitting point in the first file" do
191
- result[0].lines.last.text.should eq(["I'll see you guys in combat."])
197
+ expect(result[0].lines.last.text).to eq(["I'll see you guys in combat."])
192
198
  end
193
199
 
194
200
  it "should not make an overlapping subtitle end at the splitting point in the first file" do
195
- result[0].lines.last.time_str.should eq("00:19:23,901 --> 00:19:26,028")
201
+ expect(result[0].lines.last.time_str).to eq("00:19:23,901 --> 00:19:26,028")
196
202
  end
197
203
 
198
204
  it "should include a subtitle that overlaps a splitting point in the second file as well" do
199
- result[1].lines.first.text.should eq(["I'll see you guys in combat."])
205
+ expect(result[1].lines.first.text).to eq(["I'll see you guys in combat."])
200
206
  end
201
207
 
202
208
  it "should not make an overlapping subtitle remain at the beginning in the second file" do
203
- result[1].lines.first.time_str.should eq("00:19:23,901 --> 00:19:26,028")
209
+ expect(result[1].lines.first.time_str).to eq("00:19:23,901 --> 00:19:26,028")
204
210
  end
205
211
 
206
212
  it "should not shift back timecodes of the second file relative to the new file beginning" do
207
- result[1].lines[1].time_str.should eq("00:19:26,237 --> 00:19:27,966")
213
+ expect(result[1].lines[1].time_str).to eq("00:19:26,237 --> 00:19:27,966")
208
214
  end
209
215
  end
210
216
 
@@ -212,31 +218,31 @@ describe SRT::File do
212
218
  let(:result) { file.split( :at => ["00:15:00,000", "00:30:00,000"] ) }
213
219
 
214
220
  it "should return an array containing three SRT::File instances" do
215
- result.length.should eq(3)
216
- result[0].class.should eq(SRT::File)
217
- result[1].class.should eq(SRT::File)
218
- result[2].class.should eq(SRT::File)
221
+ expect(result.length).to eq(3)
222
+ expect(result[0].class).to eq(SRT::File)
223
+ expect(result[1].class).to eq(SRT::File)
224
+ expect(result[2].class).to eq(SRT::File)
219
225
  end
220
226
 
221
227
  it "should let subtitles start at sequence number #1 in all three files" do
222
- result[0].lines.first.sequence.should eq(1)
223
- result[1].lines.first.sequence.should eq(1)
224
- result[2].lines.first.sequence.should eq(1)
228
+ expect(result[0].lines.first.sequence).to eq(1)
229
+ expect(result[1].lines.first.sequence).to eq(1)
230
+ expect(result[2].lines.first.sequence).to eq(1)
225
231
  end
226
232
 
227
233
  it "should put 176 subtitles in the first file" do
228
- result[0].lines.length.should eq(176)
229
- result[0].lines.last.sequence.should eq(176)
234
+ expect(result[0].lines.length).to eq(176)
235
+ expect(result[0].lines.last.sequence).to eq(176)
230
236
  end
231
237
 
232
238
  it "should put 213 subtitles in the second file" do
233
- result[1].lines.length.should eq(213)
234
- result[1].lines.last.sequence.should eq(213)
239
+ expect(result[1].lines.length).to eq(213)
240
+ expect(result[1].lines.last.sequence).to eq(213)
235
241
  end
236
242
 
237
243
  it "should put 212 subtitles in the third file" do
238
- result[2].lines.length.should eq(212)
239
- result[2].lines.last.sequence.should eq(212)
244
+ expect(result[2].lines.length).to eq(212)
245
+ expect(result[2].lines.last.sequence).to eq(212)
240
246
  end
241
247
  end
242
248
 
@@ -244,9 +250,9 @@ describe SRT::File do
244
250
  let(:result) { file.split( :at => "00:19:24,500", :every => "00:00:01,000" ) }
245
251
 
246
252
  it "should return an array containing two SRT::File instances, ignoring :every" do
247
- result.length.should eq(2)
248
- result[0].class.should eq(SRT::File)
249
- result[1].class.should eq(SRT::File)
253
+ expect(result.length).to eq(2)
254
+ expect(result[0].class).to eq(SRT::File)
255
+ expect(result[1].class).to eq(SRT::File)
250
256
  end
251
257
  end
252
258
 
@@ -254,9 +260,9 @@ describe SRT::File do
254
260
  let(:result) { file.split( :every => "00:05:00,000" ) }
255
261
 
256
262
  it "should return an array containing nine SRT::File instances" do
257
- result.length.should eq(9)
263
+ expect(result.length).to eq(9)
258
264
  (0...result.count).each do |n|
259
- result[n].class.should eq(SRT::File)
265
+ expect(result[n].class).to eq(SRT::File)
260
266
  end
261
267
  end
262
268
  end
@@ -265,8 +271,8 @@ describe SRT::File do
265
271
  let(:result) { file.split( :at => "00:19:24,500", :renumber => false ) }
266
272
 
267
273
  it "sequence for the last line of first part should be the sequence for the first line of second part" do
268
- result[0].lines.last.text.should == result[1].lines.first.text
269
- result[0].lines.last.sequence.should == result[1].lines.first.sequence
274
+ expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
275
+ expect(result[0].lines.last.sequence).to eq(result[1].lines.first.sequence)
270
276
  end
271
277
  end
272
278
 
@@ -274,12 +280,12 @@ describe SRT::File do
274
280
  let(:result) { file.split( :at => "00:19:24,500", :renumber => true ) }
275
281
 
276
282
  it "first line of second part's number should be one" do
277
- result[1].lines.first.sequence.should == 1
283
+ expect(result[1].lines.first.sequence).to eq(1)
278
284
  end
279
285
 
280
286
  it "sequence for the last line of first part should have different number than the sequence for the first line of second part" do
281
- result[0].lines.last.text.should == result[1].lines.first.text
282
- result[0].lines.last.sequence.should_not == result[1].lines.first.sequence
287
+ expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
288
+ expect(result[0].lines.last.sequence).not_to eq(result[1].lines.first.sequence)
283
289
  end
284
290
  end
285
291
 
@@ -287,8 +293,8 @@ describe SRT::File do
287
293
  let(:result) { file.split( :at => "00:19:24,500", :timeshift => false ) }
288
294
 
289
295
  it "time for last line of first part should be the time for first line of second part" do
290
- result[0].lines.last.text.should == result[1].lines.first.text
291
- result[0].lines.last.time_str.should == result[1].lines.first.time_str
296
+ expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
297
+ expect(result[0].lines.last.time_str).to eq(result[1].lines.first.time_str)
292
298
  end
293
299
  end
294
300
 
@@ -296,12 +302,12 @@ describe SRT::File do
296
302
  let(:result) { file.split( :at => "00:19:24,500", :timeshift => true ) }
297
303
 
298
304
  it "start_time of first line in second part should be 0" do
299
- result[1].lines.first.start_time.should == 0
305
+ expect(result[1].lines.first.start_time).to eq(0)
300
306
  end
301
307
 
302
308
  it "time for last line of first part should not be the time for first line of second part" do
303
- result[0].lines.last.text.should == result[1].lines.first.text
304
- result[0].lines.last.time_str.should_not == result[1].lines.first.time_str
309
+ expect(result[0].lines.last.text).to eq(result[1].lines.first.text)
310
+ expect(result[0].lines.last.time_str).not_to eq(result[1].lines.first.time_str)
305
311
  end
306
312
  end
307
313
  end
@@ -315,11 +321,11 @@ describe SRT::File do
315
321
  before { file.timeshift({ :all => "+2.5s" }) }
316
322
 
317
323
  it "should have timecodes shifted forward by 2.5s for subtitle #24" do
318
- file.lines[23].time_str.should eq("00:01:59,291 --> 00:02:00,815")
324
+ expect(file.lines[23].time_str).to eq("00:01:59,291 --> 00:02:00,815")
319
325
  end
320
326
 
321
327
  it "should have timecodes shifted forward by 2.5s for subtitle #43" do
322
- file.lines[42].time_str.should eq("00:03:46,164 --> 00:03:47,631")
328
+ expect(file.lines[42].time_str).to eq("00:03:46,164 --> 00:03:47,631")
323
329
  end
324
330
  end
325
331
 
@@ -327,11 +333,11 @@ describe SRT::File do
327
333
  before { file.timeshift({ "25fps" => "23.976fps" }) }
328
334
 
329
335
  it "should have correctly scaled timecodes for subtitle #24" do
330
- file.lines[23].time_str.should eq("00:01:52,007 --> 00:01:53,469")
336
+ expect(file.lines[23].time_str).to eq("00:02:01,779 --> 00:02:03,368")
331
337
  end
332
338
 
333
339
  it "should have correctly scaled timecodes for subtitle #43" do
334
- file.lines[42].time_str.should eq("00:03:34,503 --> 00:03:35,910")
340
+ expect(file.lines[42].time_str).to eq("00:03:53,217 --> 00:03:54,746")
335
341
  end
336
342
  end
337
343
 
@@ -339,11 +345,11 @@ describe SRT::File do
339
345
  before { file.timeshift({ "#24" => "00:03:53,582", "#42" => "00:04:24,656" }) }
340
346
 
341
347
  it "should have shifted timecodes for subtitle #24" do
342
- file.lines[23].time_str.should eq("00:03:53,582 --> 00:03:54,042")
348
+ expect(file.lines[23].time_str).to eq("00:03:53,582 --> 00:03:54,042")
343
349
  end
344
350
 
345
351
  it "should have differently shifted timecodes for subtitle #43" do
346
- file.lines[41].time_str.should eq("00:04:24,656 --> 00:04:25,298")
352
+ expect(file.lines[41].time_str).to eq("00:04:24,656 --> 00:04:25,298")
347
353
  end
348
354
  end
349
355
 
@@ -351,11 +357,11 @@ describe SRT::File do
351
357
  before { file.timeshift({ 180 => "+1s", 264 => "+1.5s" }) }
352
358
 
353
359
  it "should have shifted by +1s at 180 seconds" do
354
- file.lines[23].time_str.should eq("00:01:57,415 --> 00:01:58,948")
360
+ expect(file.lines[23].time_str).to eq("00:01:57,415 --> 00:01:58,948")
355
361
  end
356
362
 
357
363
  it "should have shifted by +1.5s at 264 seconds" do
358
- file.lines[41].time_str.should eq("00:03:40,997 --> 00:03:43,136")
364
+ expect(file.lines[41].time_str).to eq("00:03:40,997 --> 00:03:43,136")
359
365
  end
360
366
  end
361
367
  end
@@ -367,7 +373,7 @@ describe SRT::File do
367
373
  before { file.timeshift({ :all => "-2.7m" }) }
368
374
 
369
375
  it "should have dumped 16 lines with now negative timecodes, leaving 1107" do
370
- file.lines.size.should eq(1107)
376
+ expect(file.lines.size).to eq(1107)
371
377
  end
372
378
  end
373
379
 
@@ -375,7 +381,7 @@ describe SRT::File do
375
381
  before { file.timeshift({ "00:03:25,430" => "00:00:44,200", "01:49:29,980" => "01:46:35,600" }) }
376
382
 
377
383
  it "should have dumped 16 lines with now negative timecodes, leaving 1107" do
378
- file.lines.size.should eq(1107)
384
+ expect(file.lines.size).to eq(1107)
379
385
  end
380
386
  end
381
387
  end
@@ -402,7 +408,7 @@ you're a machine.
402
408
  00:00:07,014 --> 00:00:08,003
403
409
  The robot.
404
410
  END
405
- file.to_s.should eq(OUTPUT)
411
+ expect(file.to_s).to eq(OUTPUT)
406
412
  end
407
413
  end
408
414
  end
@@ -416,7 +422,7 @@ END
416
422
  it "should produce the exactly correct output" do
417
423
  OUTPUT_WEBVTT =<<END
418
424
  WEBVTT
419
- X-TIMESTAMP-MAP=MPEGTS:0,LOCAL:00:00:00.000
425
+ X-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000
420
426
 
421
427
  1
422
428
  00:00:02.110 --> 00:00:04.578
@@ -432,7 +438,7 @@ you're a machine.
432
438
  00:00:07.014 --> 00:00:08.003
433
439
  The robot.
434
440
  END
435
- file.to_webvtt.should eq(OUTPUT_WEBVTT)
441
+ expect(file.to_webvtt).to eq(OUTPUT_WEBVTT)
436
442
  end
437
443
  end
438
444
  end
@@ -6,7 +6,7 @@ describe SRT::Line do
6
6
  let(:line) { SRT::Line.new }
7
7
 
8
8
  it "should create an empty subtitle" do
9
- line.should be_empty
9
+ expect(line).to be_empty
10
10
  end
11
11
  end
12
12
 
@@ -19,7 +19,36 @@ describe SRT::Line do
19
19
  end
20
20
 
21
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")
22
+ expect(line.time_str).to eq("00:03:44,200 --> 00:04:04,578")
23
+ end
24
+ end
25
+
26
+ describe "#time_str (second time)" do
27
+ let(:line) { SRT::Line.new }
28
+
29
+ before do
30
+ line.start_time = 36915.85455630479
31
+ line.end_time = 36915.999869858395
32
+ end
33
+
34
+ it "should produce timecodes that match the internal float values" do
35
+ expect(line.time_str).to eq("10:15:15,855 --> 10:15:16,000")
36
+ end
37
+ end
38
+
39
+ describe "#to_s" do
40
+ let(:line) { SRT::Line.new }
41
+
42
+ before do
43
+ line.sequence = "1"
44
+ line.start_time = 224.2
45
+ line.end_time = 244.578
46
+ end
47
+
48
+ context "with empty content" do
49
+ it "creates a valid empty node" do
50
+ expect(line.to_s).to eq("1\n00:03:44,200 --> 00:04:04,578\n\n")
51
+ end
23
52
  end
24
53
  end
25
54
  end
@@ -6,33 +6,37 @@ describe SRT::Parser do
6
6
 
7
7
  describe ".id" do
8
8
  it "should convert the id string (#[id]) to an int representing the sequence number" do
9
- subject.id("#317").should eq(317)
9
+ expect(subject.id("#317")).to eq(317)
10
10
  end
11
11
  end
12
12
 
13
13
  describe ".timecode" do
14
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)
15
+ expect(subject.timecode("01:03:44,200")).to eq(3824.2)
16
+ end
17
+
18
+ it "should handle timecodes with no milliseconds component" do
19
+ expect(subject.timecode("01:03:44")).to eq(3824.0)
16
20
  end
17
21
  end
18
22
 
19
23
  describe ".timespan" do
20
24
  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)
25
+ expect(subject.timespan("-3.5m")).to eq(-210)
22
26
  end
23
27
 
24
28
  it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
25
- subject.timespan("-1s").should eq(-1)
29
+ expect(subject.timespan("-1s")).to eq(-1)
26
30
  end
27
31
 
28
32
  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)
33
+ expect(subject.timespan("100ms")).to eq(0.1)
30
34
  end
31
35
  end
32
36
 
33
37
  describe ".parse_framerate" do
34
38
  it "should convert a framerate string ([number]fps) to a float representing seconds" do
35
- subject.framerate("23.976fps").should eq(23.976)
39
+ expect(subject.framerate("23.976fps")).to eq(23.976)
36
40
  end
37
41
  end
38
42
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Petersen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Ruby gem for parsing srt (subtitle) files. SRT stands for SubRip text
@@ -60,8 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
65
  - Gemfile
66
66
  - LICENSE
67
67
  - README.md
@@ -92,17 +92,17 @@ require_paths:
92
92
  - lib
93
93
  required_ruby_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ! '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ! '>='
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.2.1
105
+ rubygems_version: 2.7.6.2
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Ruby gem for parsing subtitle files.