srtshifter 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/srtshifter/options.rb +46 -58
- data/lib/srtshifter/shifter.rb +24 -0
- data/lib/srtshifter/version.rb +1 -1
- data/lib/srtshifter.rb +5 -1
- data/test/lib/srtshifter/shifter_test.rb +2 -0
- metadata +5 -2
data/lib/srtshifter/options.rb
CHANGED
@@ -3,75 +3,63 @@ require 'optparse'
|
|
3
3
|
module SrtShifter
|
4
4
|
class Options
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :options
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
ARGV.options do |opts|
|
8
|
+
def initialize(args)
|
9
|
+
@arguments = args
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
opts.separator ""
|
15
|
-
opts.separator "Common Options:"
|
11
|
+
@operations = ["ADD", "SUB"]
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
13
|
+
@options = {}
|
14
|
+
end
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
def parse_options
|
17
|
+
@arguments.options do |opts|
|
18
|
+
|
19
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] input_file output_file"
|
20
|
+
|
21
|
+
opts.separator ""
|
22
|
+
opts.separator "Common Options:"
|
23
|
+
|
24
|
+
opts.on("-o","--operation (ADD|SUB)", String, "Type ADD to increase time or SUB to decrease time.") do |o|
|
25
|
+
@options[:operation] = o
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-t","--time (VALUE)", Float, "Time in milliseconds.") do |n|
|
29
|
+
@options[:time] = n
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
opts.on_tail('-h', '--help', 'Show this help message.') do
|
33
|
+
puts(opts)
|
34
|
+
exit(0)
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.parse!
|
28
38
|
end
|
29
|
-
|
30
|
-
opts.parse!
|
39
|
+
end
|
31
40
|
|
41
|
+
def validate_args
|
32
42
|
begin
|
33
|
-
raise "Operation option is missing" if options[:operation].nil?
|
34
|
-
raise "Time option is missing" if options[:time].nil?
|
35
|
-
|
36
|
-
raise "Input file is missing" if ARGV[0].nil?
|
37
|
-
options[:input] = ARGV[0]
|
38
|
-
|
39
|
-
raise "Output file is missing" if ARGV[1].nil?
|
40
|
-
options[:output] = ARGV[1]
|
41
43
|
|
42
|
-
subtitle = SrtShifter::Subtitle.new(options)
|
43
|
-
subtitle.shift
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
raise "Operation option is missing" if @options[:operation].nil?
|
46
|
+
raise "Unknown operation: #{@options[:operation]}" unless @operations.include? @options[:operation].upcase
|
47
|
+
|
48
|
+
raise "Time option is missing" if @options[:time].nil?
|
49
|
+
|
50
|
+
raise "Input file is missing" if @arguments[0].nil?
|
51
|
+
@options[:input] = @arguments[0]
|
52
|
+
|
53
|
+
raise "Output file is missing" if @arguments[1].nil?
|
54
|
+
@options[:output] = @arguments[1]
|
55
|
+
|
56
|
+
# subtitle = SrtShifter::Subtitle.new(@options)
|
57
|
+
# subtitle.shift
|
49
58
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# exit(1)
|
55
|
-
# end
|
56
|
-
|
57
|
-
# begin
|
58
|
-
|
59
|
-
# opts.parse! ARGV
|
60
|
-
|
61
|
-
# # raise OptionParser::MissingArgument if options[:operation].nil? || options[:time].nil?
|
62
|
-
|
63
|
-
# # options[:input] = ARGV[0] unless ARGV[0] == nil
|
64
|
-
# # options[:output] = ARGV[1] unless ARGV[1] == nil
|
65
|
-
|
66
|
-
# # subtitle = SrtShifter::Subtitle.new(options)
|
67
|
-
# # subtitle.shift
|
68
|
-
# rescue
|
69
|
-
# # $stderr.print $!
|
70
|
-
# # puts options
|
71
|
-
# # puts "\n"
|
72
|
-
# # puts opts
|
73
|
-
# # #exit
|
74
|
-
# end
|
59
|
+
rescue Exception => ex
|
60
|
+
puts "#{ex.message}. Please use -h or --help for usage."
|
61
|
+
exit(1)
|
62
|
+
end
|
75
63
|
end
|
76
64
|
end
|
77
65
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SrtShifter
|
2
|
+
class Shifter
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
@arguments = args
|
6
|
+
@opts = SrtShifter::Options.new(@arguments)
|
7
|
+
@subtitle = subtitle = SrtShifter::Subtitle.new(@opts.options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
@subtitle.shift if parsed_options? and valid_args?
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def parsed_options?
|
16
|
+
@opts.parse_options
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_args?
|
20
|
+
@opts.validate_args
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/srtshifter/version.rb
CHANGED
data/lib/srtshifter.rb
CHANGED
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Shifts STR Subtitles
|
15
15
|
email:
|
@@ -27,10 +27,12 @@ files:
|
|
27
27
|
- bin/srtshifter
|
28
28
|
- lib/srtshifter.rb
|
29
29
|
- lib/srtshifter/options.rb
|
30
|
+
- lib/srtshifter/shifter.rb
|
30
31
|
- lib/srtshifter/subtitle.rb
|
31
32
|
- lib/srtshifter/version.rb
|
32
33
|
- srtshifter.gemspec
|
33
34
|
- test/lib/srtshifter/options_test.rb
|
35
|
+
- test/lib/srtshifter/shifter_test.rb
|
34
36
|
- test/lib/srtshifter/subtitle_test.rb
|
35
37
|
- test/lib/srtshifter/version_test.rb
|
36
38
|
- test/samples/test_srt.srt
|
@@ -61,6 +63,7 @@ specification_version: 3
|
|
61
63
|
summary: It fixes the timing of a given SubRip file
|
62
64
|
test_files:
|
63
65
|
- test/lib/srtshifter/options_test.rb
|
66
|
+
- test/lib/srtshifter/shifter_test.rb
|
64
67
|
- test/lib/srtshifter/subtitle_test.rb
|
65
68
|
- test/lib/srtshifter/version_test.rb
|
66
69
|
- test/samples/test_srt.srt
|