srtshifter 1.1.0 → 1.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/bin/srtshifter +5 -1
- data/lib/srtshifter/options.rb +2 -6
- data/lib/srtshifter/shifter.rb +1 -1
- data/lib/srtshifter/subtitle.rb +2 -2
- data/lib/srtshifter/version.rb +1 -1
- data/lib/srtshifter.rb +1 -4
- data/srtshifter.gemspec +1 -0
- data/test/lib/srtshifter/options_test.rb +48 -1
- data/test/lib/srtshifter/subtitle_test.rb +50 -1
- metadata +18 -4
- data/test/lib/srtshifter/shifter_test.rb +0 -2
data/bin/srtshifter
CHANGED
data/lib/srtshifter/options.rb
CHANGED
@@ -31,7 +31,7 @@ module SrtShifter
|
|
31
31
|
|
32
32
|
opts.on_tail('-h', '--help', 'Show this help message.') do
|
33
33
|
puts(opts)
|
34
|
-
exit(0)
|
34
|
+
# exit(0)
|
35
35
|
end
|
36
36
|
|
37
37
|
opts.parse!
|
@@ -41,7 +41,6 @@ module SrtShifter
|
|
41
41
|
def validate_args
|
42
42
|
begin
|
43
43
|
|
44
|
-
|
45
44
|
raise "Operation option is missing" if @options[:operation].nil?
|
46
45
|
raise "Unknown operation: #{@options[:operation]}" unless @operations.include? @options[:operation].upcase
|
47
46
|
|
@@ -53,12 +52,9 @@ module SrtShifter
|
|
53
52
|
raise "Output file is missing" if @arguments[1].nil?
|
54
53
|
@options[:output] = @arguments[1]
|
55
54
|
|
56
|
-
# subtitle = SrtShifter::Subtitle.new(@options)
|
57
|
-
# subtitle.shift
|
58
|
-
|
59
55
|
rescue Exception => ex
|
60
56
|
puts "#{ex.message}. Please use -h or --help for usage."
|
61
|
-
exit(1)
|
57
|
+
# exit(1)
|
62
58
|
end
|
63
59
|
end
|
64
60
|
end
|
data/lib/srtshifter/shifter.rb
CHANGED
data/lib/srtshifter/subtitle.rb
CHANGED
@@ -32,7 +32,7 @@ module SrtShifter
|
|
32
32
|
|
33
33
|
end_time = Time.now
|
34
34
|
|
35
|
-
puts "
|
35
|
+
puts "\nFile created with success!"
|
36
36
|
puts "Elapsed time: #{end_time-start_time} seconds."
|
37
37
|
end
|
38
38
|
|
@@ -44,7 +44,7 @@ module SrtShifter
|
|
44
44
|
|
45
45
|
current_time = Time.parse(time)
|
46
46
|
new_time = Time.at(current_time.to_f + @opts[:time])
|
47
|
-
"#{new_time.strftime('%H:%M:%S')},#{new_time.usec/1000}"
|
47
|
+
"#{new_time.strftime('%H:%M:%S')},#{sprintf("%.3d",new_time.usec/1000)}"
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/srtshifter/version.rb
CHANGED
data/lib/srtshifter.rb
CHANGED
data/srtshifter.gemspec
CHANGED
@@ -2,7 +2,54 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
describe SrtShifter do
|
4
4
|
|
5
|
-
describe "
|
5
|
+
describe "Options" do
|
6
|
+
|
7
|
+
describe "validate_args" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@args = {:operation => "add", :time => 10.0, :input => "test/samples/test_srt.srt", :output => "test_output.srt"}
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:each) do
|
14
|
+
@args = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raise error when get none operation option" do
|
18
|
+
|
19
|
+
args = ""
|
20
|
+
opts = SrtShifter::Options.new args
|
21
|
+
|
22
|
+
lambda { opts.validate_args }.must_output("Operation option is missing. Please use -h or --help for usage.\n", nil)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raise error when operation is unknown" do
|
27
|
+
|
28
|
+
opts = SrtShifter::Options.new ""
|
29
|
+
opts.options[:operation] = "bla"
|
30
|
+
|
31
|
+
lambda { opts.validate_args }.must_output("Unknown operation: bla. Please use -h or --help for usage.\n", nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "must accept lowercase existing operations" do
|
35
|
+
|
36
|
+
opts = SrtShifter::Options.new "test/samples/test_srt.srt test_output.srt"
|
37
|
+
@args[:operation] = "add"
|
38
|
+
opts.options = @args
|
39
|
+
|
40
|
+
lambda { opts.validate_args }.must_be_silent
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raise error when get none time option"
|
44
|
+
|
45
|
+
it "raise error when get none time value"
|
46
|
+
|
47
|
+
it "raise error when get none input file path"
|
48
|
+
|
49
|
+
it "raise error when get none output file path"
|
50
|
+
|
51
|
+
end
|
6
52
|
|
7
53
|
end
|
54
|
+
|
8
55
|
end
|
@@ -1,5 +1,54 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
describe SrtShifter do
|
4
|
-
|
4
|
+
|
5
|
+
describe "SUBTITLE" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@options = {:operation => "ADD", :time => 10.0, :input => "test/samples/test_srt.srt", :output => "test_output.srt"}
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
@options = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "convert_time" do
|
16
|
+
|
17
|
+
it "must add 2.5 seconds to a given time" do
|
18
|
+
|
19
|
+
given_time = "00:00:10,000"
|
20
|
+
|
21
|
+
@options[:operation] = "ADD"
|
22
|
+
@options[:time] = 2.5
|
23
|
+
sub = SrtShifter::Subtitle.new(@options)
|
24
|
+
|
25
|
+
sub.convert_time(given_time).must_equal "00:00:12,500"
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it "must subtract 5.3 seconds to a given time" do
|
30
|
+
|
31
|
+
given_time = "00:00:10,000"
|
32
|
+
|
33
|
+
@options[:operation] = "SUB"
|
34
|
+
@options[:time] = 5.3
|
35
|
+
sub = SrtShifter::Subtitle.new(@options)
|
36
|
+
|
37
|
+
sub.convert_time(given_time).must_equal "00:00:04,700"
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "shift" do
|
44
|
+
|
45
|
+
it "must generate a new srt file" do
|
46
|
+
sub = SrtShifter::Subtitle.new(@options)
|
47
|
+
sub.shift
|
48
|
+
File.exist?(@options[:output]).must_equal true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
5
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: srtshifter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,23 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-12-26 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Shifts STR Subtitles
|
15
31
|
email:
|
16
32
|
- kimobr@gmail.com
|
@@ -32,7 +48,6 @@ files:
|
|
32
48
|
- lib/srtshifter/version.rb
|
33
49
|
- srtshifter.gemspec
|
34
50
|
- test/lib/srtshifter/options_test.rb
|
35
|
-
- test/lib/srtshifter/shifter_test.rb
|
36
51
|
- test/lib/srtshifter/subtitle_test.rb
|
37
52
|
- test/lib/srtshifter/version_test.rb
|
38
53
|
- test/samples/test_srt.srt
|
@@ -63,7 +78,6 @@ specification_version: 3
|
|
63
78
|
summary: It fixes the timing of a given SubRip file
|
64
79
|
test_files:
|
65
80
|
- test/lib/srtshifter/options_test.rb
|
66
|
-
- test/lib/srtshifter/shifter_test.rb
|
67
81
|
- test/lib/srtshifter/subtitle_test.rb
|
68
82
|
- test/lib/srtshifter/version_test.rb
|
69
83
|
- test/samples/test_srt.srt
|