srt 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -10
- data/lib/srt/file.rb +4 -5
- data/lib/srt/version.rb +1 -1
- data/spec/srt_spec.rb +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 226ede0afdafbb23daefe624ec7becc9460ed027
|
4
|
+
data.tar.gz: 010fd1033ada594a51cce591d0c0fc7f430ebaa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3629bbcef44c932ae1b458ad73fe7339fbcd9aa06d8b297955d76bb075691237d759c2631d112f947e1331504bb135bb8d38c6643f41db7a38b267e05eb4789c
|
7
|
+
data.tar.gz: ab882c03bfa03565304ab707352442ecccd3ac0191d3eea1f7d86bf15b661cf1d893880979af730fd73097e98dc5617bbcdf49c463f96b5b169248ac2f1840dc
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SRT [![Build Status](https://travis-ci.org/cpetersen/srt.png?branch=master)](https://travis-ci.org/cpetersen/srt)
|
2
2
|
|
3
|
-
SRT stands for SubRip text file format, which is a file for storing subtitles; This is a Ruby library for manipulating SRT files.
|
3
|
+
SRT stands for SubRip text file format, which is a file for storing subtitles; This is a Ruby library for manipulating SRT files.
|
4
4
|
Current functionality includes **parsing**, **appending**, **splitting** and **timeshifting** (constant, progressive and framerate-based).
|
5
5
|
|
6
6
|
## Installation
|
@@ -12,7 +12,7 @@ Add this line to your application's Gemfile:
|
|
12
12
|
And then execute:
|
13
13
|
|
14
14
|
$ bundle
|
15
|
-
|
15
|
+
|
16
16
|
Or install it yourself as:
|
17
17
|
|
18
18
|
$ gem install srt
|
@@ -31,7 +31,7 @@ You can parse an SRT file with the following code:
|
|
31
31
|
Each line exposes the following methods/members:
|
32
32
|
* `sequence` The incrementing subtitle ID (starts at 1)
|
33
33
|
* `text` An **Array** holding one or multiple lines of text.
|
34
|
-
* `start_time` The subtitle start timecode in seconds as a float
|
34
|
+
* `start_time` The subtitle start timecode in seconds as a float
|
35
35
|
* `end_time` The subtitle end timecode in seconds as a float
|
36
36
|
* `time_str` Returns a timecode string of the form `"00:53:35,558 --> 00:53:36,556"`
|
37
37
|
* `display_coordinates` Optional display coordinates of the form `"X1:100 X2:600 Y1:100 Y2:400"`
|
@@ -66,14 +66,14 @@ Example options for a multi-split: `{ :at => ["00:19:24,500", "01:32:09,120", ..
|
|
66
66
|
|
67
67
|
The method `timeshift` takes a hash and supports three different modes of timecode processing:
|
68
68
|
|
69
|
-
**Constant timeshift**
|
69
|
+
**Constant timeshift**
|
70
70
|
|
71
71
|
```ruby
|
72
|
-
file.timeshift( :all => "-2.5s" ) # Shift all subtitles so they show up 2.5 seconds earlier
|
72
|
+
file.timeshift( :all => "-2.5s" ) # Shift all subtitles so they show up 2.5 seconds earlier
|
73
73
|
```
|
74
74
|
|
75
|
-
Simply pass a hash of the form `:all => "[+|-][amount][h|m|s|
|
76
|
-
Other example options, e.g.: `:all => "+
|
75
|
+
Simply pass a hash of the form `:all => "[+|-][amount][h|m|s|ms]"`
|
76
|
+
Other example options, e.g.: `:all => "+1.34m"`, `:all => "0.15h"`, `:all => "90ms"`
|
77
77
|
|
78
78
|
**Progressive timeshift**
|
79
79
|
|
@@ -86,14 +86,14 @@ This example call would shift the **first subtitle** to `00:02:12`, the **last s
|
|
86
86
|
To make this work pass two `origin timecode => target timecode` pairs, where the *origin timecodes* can be supplied as:
|
87
87
|
|
88
88
|
* `float` providing the raw timecode in *seconds*, e.g.: `195.65`
|
89
|
-
* `"[hh]:[mm]:[ss],[
|
89
|
+
* `"[hh]:[mm]:[ss],[ms]"` string, which is a timecode in SRT notation, e.g.: `"00:02:12,000"`
|
90
90
|
* `"#[id]"` string, which references the timecode of the subtitle with the supplied id, e.g.: `"#317"`
|
91
91
|
|
92
92
|
... and the *target timecodes* can be supplied as:
|
93
93
|
|
94
94
|
* `float` providing the raw timecode in *seconds*, e.g.: `3211.3`
|
95
|
-
* `"[hh]:[mm]:[ss],[
|
96
|
-
* `"[+/-][amount][h|m|s|
|
95
|
+
* `"[hh]:[mm]:[ss],[ms]"` string, which is a timecode in SRT notation, e.g.: `"01:01:03,300"`
|
96
|
+
* `"[+/-][amount][h|m|s|ms]"` string, describing the amount by which to shift the origin timecode, e.g.: `"+1.5s"`
|
97
97
|
|
98
98
|
So for example: `{ "00:00:51,400" => "+13s", "01:12:44,320" => "+2.436m" }`
|
99
99
|
|
data/lib/srt/file.rb
CHANGED
@@ -225,19 +225,18 @@ module SRT
|
|
225
225
|
end
|
226
226
|
|
227
227
|
def self.parse_timecode(timecode_string)
|
228
|
-
mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+),(?<
|
229
|
-
mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["
|
228
|
+
mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+),(?<ms>\d+)/)
|
229
|
+
mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["ms"]}".to_f : nil
|
230
230
|
end
|
231
231
|
|
232
232
|
def self.parse_timespan(timespan_string)
|
233
233
|
factors = {
|
234
|
-
"
|
234
|
+
"ms" => 0.001,
|
235
235
|
"s" => 1,
|
236
236
|
"m" => 60,
|
237
237
|
"h" => 3600
|
238
238
|
}
|
239
|
-
|
240
|
-
mres = timespan_string.match(/(?<amount>(\+|-)?\d+((\.)?\d+)?)(?<unit>mil|s|m|h)/)
|
239
|
+
mres = timespan_string.match(/(?<amount>(\+|-)?\d+((\.)?\d+)?)(?<unit>ms|s|m|h)/)
|
241
240
|
mres ? mres["amount"].to_f * factors[mres["unit"]] : nil
|
242
241
|
end
|
243
242
|
end
|
data/lib/srt/version.rb
CHANGED
data/spec/srt_spec.rb
CHANGED
@@ -40,13 +40,17 @@ describe SRT do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
describe ".parse_timespan" do
|
43
|
-
it "should convert a timespan string ([+|-][amount][h|m|s|
|
43
|
+
it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
|
44
44
|
SRT::File.parse_timespan("-3.5m").should eq(-210)
|
45
45
|
end
|
46
46
|
|
47
|
-
it "should convert a timespan string ([+|-][amount][h|m|s|
|
47
|
+
it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
|
48
48
|
SRT::File.parse_timespan("-1s").should eq(-1)
|
49
49
|
end
|
50
|
+
|
51
|
+
it "should convert a timespan string ([+|-][amount][h|m|s|ms]) to a float representing seconds" do
|
52
|
+
SRT::File.parse_timespan("100ms").should eq(0.1)
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
describe ".parse_framerate" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|