srt 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d78709bafbe0108d1b453ea5ccad50e65ac8d77
4
- data.tar.gz: c25aceb9b79d1beb1c0be65bf6383593238d8aad
3
+ metadata.gz: 226ede0afdafbb23daefe624ec7becc9460ed027
4
+ data.tar.gz: 010fd1033ada594a51cce591d0c0fc7f430ebaa1
5
5
  SHA512:
6
- metadata.gz: eca5bb6785cedd43ee20d2cc0d700713df14dc5e5d8d02d520f04730405b65c11a6cb8f2e72e802d971b87040ff356d8d919f4a74b40d1e3cf4a38fccd6af14a
7
- data.tar.gz: e4a936cb2d04bb08b2e3dd64b9d8043a957ad403c57df1949cfc45d80c411f13b4efdd38d8c3636ccf8ced401261f2fbd817b9be989f4d47c8cd320b56314a36
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|mil]"`
76
- Other example options, e.g.: `:all => "+700mil"`, `:all => "1.34m"`, `:all => "0.15h"`
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],[mil]"` string, which is a timecode in SRT notation, e.g.: `"00:02:12,000"`
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],[mil]"` string, which is a timecode in SRT notation, e.g.: `"01:01:03,300"`
96
- * `"[+/-][amount][h|m|s|mil]"` string, describing the amount by which to shift the origin timecode, e.g.: `"+1.5s"`
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
 
@@ -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+),(?<mil>\d+)/)
229
- mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["mil"]}".to_f : nil
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
- "mil" => 0.001,
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
@@ -1,3 +1,3 @@
1
1
  module SRT
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -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|mil]) to a float representing seconds" do
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|mil]) to a float representing seconds" do
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.7
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-14 00:00:00.000000000 Z
11
+ date: 2013-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake