srtshifter 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/srtshifter CHANGED
@@ -2,4 +2,8 @@
2
2
 
3
3
  lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
4
  $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
- require 'srtshifter'
5
+
6
+ require 'srtshifter'
7
+
8
+ shifter = SrtShifter::Shifter.new(ARGV)
9
+ shifter.execute
@@ -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
@@ -4,7 +4,7 @@ module SrtShifter
4
4
  def initialize(args)
5
5
  @arguments = args
6
6
  @opts = SrtShifter::Options.new(@arguments)
7
- @subtitle = subtitle = SrtShifter::Subtitle.new(@opts.options)
7
+ @subtitle = SrtShifter::Subtitle.new(@opts.options)
8
8
  end
9
9
 
10
10
  def execute
@@ -32,7 +32,7 @@ module SrtShifter
32
32
 
33
33
  end_time = Time.now
34
34
 
35
- puts "File created with success!"
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
@@ -1,3 +1,3 @@
1
1
  module SrtShifter
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/srtshifter.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require "srtshifter/subtitle"
2
2
  require "srtshifter/options"
3
3
  require "srtshifter/version"
4
- require "srtshifter/shifter"
5
-
6
- shifter = SrtShifter::Shifter.new(ARGV)
7
- shifter.execute
4
+ require "srtshifter/shifter"
data/srtshifter.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+ gem.add_development_dependency 'rake'
19
20
  end
@@ -2,7 +2,54 @@ require "test_helper"
2
2
 
3
3
  describe SrtShifter do
4
4
 
5
- describe "OPTIONS" do
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.0
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
@@ -1,2 +0,0 @@
1
- require "test_helper"
2
-