srtshifter 1.2.1 → 1.3.0
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/lib/srtshifter/options.rb +1 -1
- data/lib/srtshifter/subtitle.rb +22 -11
- data/lib/srtshifter/version.rb +1 -1
- data/srtshifter.gemspec +0 -1
- data/test/lib/srtshifter/options_test.rb +1 -1
- data/test/lib/srtshifter/subtitle_test.rb +27 -0
- metadata +1 -17
data/lib/srtshifter/options.rb
CHANGED
data/lib/srtshifter/subtitle.rb
CHANGED
@@ -38,15 +38,26 @@ module SrtShifter
|
|
38
38
|
puts "Elapsed time: #{end_time-start_time} seconds."
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
def convert_time(time)
|
42
|
+
time_diff = time_in_seconds(@opts[:time])
|
43
|
+
if @opts[:operation] == "SUB" and time_diff > 0
|
44
|
+
time_diff *= -1
|
45
|
+
end
|
46
|
+
|
47
|
+
current_time = Time.parse(time)
|
48
|
+
new_time = Time.at(current_time.to_f + time_diff)
|
49
|
+
"#{new_time.strftime('%H:%M:%S')},#{sprintf("%.3d",new_time.usec/1000)}"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def time_in_seconds(time_string)
|
55
|
+
return time_string if time_string.kind_of?(Numeric)
|
56
|
+
|
57
|
+
times = time_string.scan(/(\d{2}):(\d{2}):(\d{2}).(\d{3})/)
|
58
|
+
times.flatten!
|
59
|
+
times.map!(&:to_i)
|
60
|
+
times[3]/1_000.0 + times[2] + 60*(times[1] + times[0]*60)
|
61
|
+
end
|
62
|
+
end
|
52
63
|
end
|
data/lib/srtshifter/version.rb
CHANGED
data/srtshifter.gemspec
CHANGED
@@ -38,6 +38,33 @@ describe SrtShifter do
|
|
38
38
|
|
39
39
|
end
|
40
40
|
|
41
|
+
it "must accept time in '%H:%M:%S.%L' format in ADD operation" do
|
42
|
+
given_time = "00:00:10,000"
|
43
|
+
@options[:operation] = "ADD"
|
44
|
+
@options[:time] = "01:20:03.999"
|
45
|
+
|
46
|
+
sub = SrtShifter::Subtitle.new(@options)
|
47
|
+
sub.convert_time(given_time).must_equal "01:20:13,999"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "must accept time in '%H:%M:%S.%L' format in SUB operation" do
|
51
|
+
given_time = "01:20:03,999"
|
52
|
+
@options[:operation] = "SUB"
|
53
|
+
@options[:time] = "01:20:01.999"
|
54
|
+
|
55
|
+
sub = SrtShifter::Subtitle.new(@options)
|
56
|
+
sub.convert_time(given_time).must_equal "00:00:02,000"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "must accept time in '-%H:%M:%S.%L' format in SUB operation" do
|
60
|
+
given_time = "01:20:03,999"
|
61
|
+
@options[:operation] = "SUB"
|
62
|
+
@options[:time] = "-01:20:01.999"
|
63
|
+
|
64
|
+
sub = SrtShifter::Subtitle.new(@options)
|
65
|
+
sub.convert_time(given_time).must_equal "00:00:02,000"
|
66
|
+
end
|
67
|
+
|
41
68
|
end
|
42
69
|
|
43
70
|
describe "shift" do
|
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.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: coveralls
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
30
|
description: Shifts STR Subtitles
|
47
31
|
email:
|
48
32
|
- kimobr@gmail.com
|