subtool 0.1.0 → 0.1.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/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/README.md +7 -2
- data/Rakefile +1 -1
- data/bin/subtool +9 -4
- data/features/files/simple2.srt +12 -0
- data/features/filter.feature +11 -0
- data/features/import_export.feature +11 -2
- data/features/support/env.rb +9 -0
- data/lib/subtool/import/srt.rb +19 -6
- data/lib/subtool/version.rb +1 -1
- metadata +31 -10
- data/Gemfile.lock +0 -42
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# Subtool
|
2
|
+
|
3
|
+
[](https://travis-ci.org/0livier/subtool) [](https://codeclimate.com/github/0livier/subtool) [](http://badge.fury.io/rb/subtool)
|
2
4
|
|
3
5
|
subtool is a commandline tool that help fix the timing of subtitles files.
|
4
6
|
|
@@ -10,10 +12,13 @@ Install it using the gem command:
|
|
10
12
|
|
11
13
|
## Usage
|
12
14
|
|
15
|
+
subtool -i subtitle.srt add > output.srt
|
16
|
+
subtool < subtitle.srt remove 3.5 -o output.srt
|
17
|
+
subtool --help
|
13
18
|
|
14
19
|
## Want another tool ?
|
15
20
|
|
16
|
-
There are several other
|
21
|
+
There are several other tools to manipulate SRT files. Among them,
|
17
22
|
|
18
23
|
* https://github.com/remram44/srt-shift
|
19
24
|
* http://www.aegisub.org/
|
data/Rakefile
CHANGED
data/bin/subtool
CHANGED
@@ -24,7 +24,7 @@ option_parser = OptionParser.new do |opts|
|
|
24
24
|
end
|
25
25
|
|
26
26
|
opts.on('-o', '--output FILENAME',
|
27
|
-
'
|
27
|
+
'Output SRT filename. STDOUT by default or if - is given.') do |filename|
|
28
28
|
options.output = filename unless filename == '-'
|
29
29
|
end
|
30
30
|
|
@@ -54,10 +54,15 @@ if ARGV.count == 0
|
|
54
54
|
exit
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
# as jruby does not support ARGV/ARGF well (see code history)
|
58
|
+
# we have to import
|
59
|
+
if options.input
|
60
|
+
subtitles = Subtool::Import::Srt.file(options.input)
|
61
|
+
else
|
62
|
+
subtitles = Subtool::Import::Srt.filehandler($stdin)
|
63
|
+
end
|
58
64
|
|
59
|
-
|
60
|
-
subtitles = Subtool::Import::Srt.filehandler(ARGF)
|
65
|
+
commands = ARGV.dup
|
61
66
|
|
62
67
|
# @Todo more filters otherwise the loop won't make any sense
|
63
68
|
while commands.count > 0
|
data/features/filter.feature
CHANGED
@@ -53,3 +53,14 @@ Feature: Modifying Parser Import / Export should get and write content properly
|
|
53
53
|
| 1 | 22100 | 26500 | Altocumulus clouds occur between six thousand |
|
54
54
|
| 2 | 26700 | 29900 | and twenty thousand feet above ground level. |
|
55
55
|
| 3 | 3663200 | 7324300 | QUACK\n\\_o< |
|
56
|
+
|
57
|
+
Scenario: Srt Loading #2
|
58
|
+
When I parse a Srt file named "features/files/simple2.srt"
|
59
|
+
And I add a delay of 2 seconds
|
60
|
+
And I export the subtitles to a file named "tmp/output_simple2.srt"
|
61
|
+
And I parse a Srt file named "tmp/output_simple2.srt"
|
62
|
+
Then I should have the following subtitles:
|
63
|
+
| id | start | end | body |
|
64
|
+
| 1 | 3000 | 6074 | My wonderful SRT |
|
65
|
+
| 2 | 54341 | 60341 | SHOULD BE NICE\nAnd clean |
|
66
|
+
| 3 | 65091 | 67881 | Nah? |
|
@@ -4,7 +4,7 @@ Feature: Parser Import / Export should get and write content properly
|
|
4
4
|
As a developer of subtool
|
5
5
|
I want it to load and write them correctly
|
6
6
|
|
7
|
-
Scenario: Srt Loading
|
7
|
+
Scenario: Srt Loading #1
|
8
8
|
When I parse a Srt file named "features/files/simple.srt"
|
9
9
|
Then I should have the following subtitles:
|
10
10
|
| id | start | end | body |
|
@@ -12,6 +12,15 @@ Feature: Parser Import / Export should get and write content properly
|
|
12
12
|
| 2 | 24600 | 27800 | and twenty thousand feet above ground level. |
|
13
13
|
| 3 | 3661100 | 7322200 | QUACK\n\\_o< |
|
14
14
|
|
15
|
+
Scenario: Srt Loading #2
|
16
|
+
When I parse a Srt file named "features/files/simple2.srt"
|
17
|
+
And I export the subtitles to a file named "tmp/output_simple2.srt"
|
18
|
+
And I parse a Srt file named "tmp/output_simple2.srt"
|
19
|
+
Then I should have the following subtitles:
|
20
|
+
| id | start | end | body |
|
21
|
+
| 1 | 1000 | 4074 | My wonderful SRT |
|
22
|
+
| 2 | 52341 | 58341 | SHOULD BE NICE\nAnd clean |
|
23
|
+
| 3 | 63091 | 65881 | Nah? |
|
15
24
|
|
16
25
|
Scenario: Writing file
|
17
26
|
When I parse a Srt file named "features/files/simple.srt"
|
@@ -23,7 +32,7 @@ Feature: Parser Import / Export should get and write content properly
|
|
23
32
|
| 2 | 24600 | 27800 | and twenty thousand feet above ground level. |
|
24
33
|
| 3 | 3661100 | 7322200 | QUACK\n\\_o< |
|
25
34
|
|
26
|
-
# need to call the binary since
|
35
|
+
# need to call the binary since we do not capture the output of current process
|
27
36
|
Scenario: Writing file on STDOUT
|
28
37
|
When I call "subtool" with the argument "-i ../../features/files/simple.srt add 0"
|
29
38
|
Then the output should contain "1\n00:00:20,000 --> 00:00:24,400\nAltocumulus clouds occur between six thousand"
|
data/features/support/env.rb
CHANGED
@@ -14,6 +14,15 @@ Before do
|
|
14
14
|
@puts = true
|
15
15
|
@original_rubylib = ENV['RUBYLIB']
|
16
16
|
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
17
|
+
|
18
|
+
# Spawning processes in tests with jruby is slow, so we wait longer and we try to make it start faster
|
19
|
+
@aruba_timeout_seconds = RUBY_PLATFORM == 'java' ? 60 : 3
|
20
|
+
Aruba.configure do |config|
|
21
|
+
config.before_cmd do |cmd|
|
22
|
+
set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
|
23
|
+
set_env('JAVA_OPTS', "#{ENV['JAVA_OPTS']}")
|
24
|
+
end
|
25
|
+
end if RUBY_PLATFORM == 'java'
|
17
26
|
end
|
18
27
|
|
19
28
|
After do
|
data/lib/subtool/import/srt.rb
CHANGED
@@ -2,16 +2,22 @@ module Subtool
|
|
2
2
|
module Import
|
3
3
|
class Srt
|
4
4
|
|
5
|
+
HOUR = 60 * 60 * 1000
|
6
|
+
MIN = 60 * 1000
|
7
|
+
SEC = 1000
|
8
|
+
|
5
9
|
def self.filehandler(fh)
|
6
10
|
subtitles = []
|
7
|
-
|
8
11
|
until fh.eof? do
|
9
12
|
|
10
13
|
number = Integer(fh.readline.strip)
|
11
14
|
position = self.parse_position(fh.readline.strip)
|
12
|
-
body =
|
15
|
+
body = ""
|
16
|
+
while (! fh.eof?) && ("" != (content = fh.readline.strip))
|
17
|
+
body = body + content + "\n"
|
18
|
+
end
|
13
19
|
|
14
|
-
subtitles.push(Subtool::Subtitle.new(number, position[:start], position[:end], body))
|
20
|
+
subtitles.push(Subtool::Subtitle.new(number, position[:start], position[:end], body.strip))
|
15
21
|
end
|
16
22
|
|
17
23
|
subtitles
|
@@ -28,13 +34,20 @@ module Subtool
|
|
28
34
|
def self.parse_position(position)
|
29
35
|
matches = position.match(/^(\d\d):(\d\d):(\d\d),(\d\d\d) --> (\d\d):(\d\d):(\d\d),(\d\d\d)$/)
|
30
36
|
throw Exception.new("Can't parse #{position} as a valid time range") unless matches
|
31
|
-
|
37
|
+
|
38
|
+
matches = matches[1..8].map { |s| s.to_i }
|
32
39
|
{
|
33
|
-
:start => matches[0]
|
34
|
-
:end => matches[4]
|
40
|
+
:start => self.to_millisecs(matches[0], matches[1], matches[2], matches[3]),
|
41
|
+
:end => self.to_millisecs(matches[4], matches[5], matches[6], matches[7]),
|
35
42
|
}
|
36
43
|
end
|
37
44
|
|
45
|
+
private
|
46
|
+
|
47
|
+
def self.to_millisecs(hour, min, sec, millisec)
|
48
|
+
return hour * HOUR + min * MIN + sec * SEC + millisec
|
49
|
+
end
|
50
|
+
|
38
51
|
end
|
39
52
|
end
|
40
53
|
end
|
data/lib/subtool/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subtool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: aruba
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: simplecov
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
description: subtool is a library and CLI program to add (or remove) delay in subtitles
|
48
63
|
files
|
49
64
|
email: olivier@lol.cat
|
@@ -55,13 +70,13 @@ files:
|
|
55
70
|
- .gitignore
|
56
71
|
- .travis.yml
|
57
72
|
- Gemfile
|
58
|
-
- Gemfile.lock
|
59
73
|
- LICENSE
|
60
74
|
- README.md
|
61
75
|
- Rakefile
|
62
76
|
- bin/subtool
|
63
77
|
- features/files/malformed.srt
|
64
78
|
- features/files/simple.srt
|
79
|
+
- features/files/simple2.srt
|
65
80
|
- features/filter.feature
|
66
81
|
- features/help.feature
|
67
82
|
- features/import_export.feature
|
@@ -87,15 +102,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
102
|
- - ! '>='
|
88
103
|
- !ruby/object:Gem::Version
|
89
104
|
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: 4316214694996564458
|
90
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
109
|
none: false
|
92
110
|
requirements:
|
93
111
|
- - ! '>='
|
94
112
|
- !ruby/object:Gem::Version
|
95
113
|
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: 4316214694996564458
|
96
117
|
requirements: []
|
97
118
|
rubyforge_project:
|
98
|
-
rubygems_version: 1.8.
|
119
|
+
rubygems_version: 1.8.25
|
99
120
|
signing_key:
|
100
121
|
specification_version: 3
|
101
122
|
summary: CLI tool for manipulating subtitles files
|
data/Gemfile.lock
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
subtool (0.0.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
aruba (0.5.1)
|
10
|
-
childprocess (~> 0.3.6)
|
11
|
-
cucumber (>= 1.1.1)
|
12
|
-
rspec-expectations (>= 2.7.0)
|
13
|
-
builder (3.1.4)
|
14
|
-
childprocess (0.3.6)
|
15
|
-
ffi (~> 1.0, >= 1.0.6)
|
16
|
-
cucumber (1.2.1)
|
17
|
-
builder (>= 2.1.2)
|
18
|
-
diff-lcs (>= 1.1.3)
|
19
|
-
gherkin (~> 2.11.0)
|
20
|
-
json (>= 1.4.6)
|
21
|
-
diff-lcs (1.1.3)
|
22
|
-
ffi (1.2.0)
|
23
|
-
gherkin (2.11.5)
|
24
|
-
json (>= 1.4.6)
|
25
|
-
json (1.7.5)
|
26
|
-
multi_json (1.1.0)
|
27
|
-
rake (10.0.2)
|
28
|
-
rspec-expectations (2.12.0)
|
29
|
-
diff-lcs (~> 1.1.3)
|
30
|
-
simplecov (0.6.1)
|
31
|
-
multi_json (~> 1.0)
|
32
|
-
simplecov-html (~> 0.5.3)
|
33
|
-
simplecov-html (0.5.3)
|
34
|
-
|
35
|
-
PLATFORMS
|
36
|
-
ruby
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
aruba
|
40
|
-
rake
|
41
|
-
simplecov
|
42
|
-
subtool!
|