srtshifter 0.0.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 ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in strshifter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kimo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Strshifter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'strshifter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install strshifter
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
data/bin/srtshifter ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+ require 'srtshifter'
@@ -0,0 +1,77 @@
1
+ require 'optparse'
2
+
3
+ module SrtShifter
4
+ class Options
5
+
6
+ operations = ["ADD", "SUB"]
7
+
8
+ options = {}
9
+
10
+ ARGV.options do |opts|
11
+
12
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] input_file output_file"
13
+
14
+ opts.separator ""
15
+ opts.separator "Common Options:"
16
+
17
+ opts.on("-o","--operation (ADD|SUB)", String, "Type ADD to increase time or SUB to decrease time.") do |o|
18
+ options[:operation] = o.upcase
19
+ end
20
+
21
+ opts.on("-t","--time (VALUE)", Float, "Time in milliseconds.") do |n|
22
+ options[:time] = n
23
+ end
24
+
25
+ opts.on_tail('-h', '--help', 'Show this help message.') do
26
+ puts(opts)
27
+ exit(0)
28
+ end
29
+
30
+ opts.parse!
31
+
32
+ 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
+
42
+ subtitle = SrtShifter::Subtitle.new(options)
43
+ subtitle.shift
44
+
45
+ rescue Exception => ex
46
+ puts "#{ex.message}. Please use -h or --help for usage."
47
+ exit(1)
48
+ end
49
+
50
+ # begin
51
+ # raise "Unknown option(s) #{options.join(', ')}" if options.empty?
52
+ # rescue Exception => e
53
+ # puts "#{ex.message()}. Please use -h or --help for usage."
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
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,50 @@
1
+ require 'time'
2
+
3
+ module SrtShifter
4
+ class Subtitle
5
+
6
+ def initialize(options)
7
+ @opts = options
8
+ end
9
+
10
+ def shift
11
+
12
+ start_time = Time.now
13
+
14
+ output_file = File.open(@opts[:output], 'w')
15
+
16
+ lines = IO.readlines(@opts[:input])
17
+
18
+ lines.each do |line|
19
+
20
+ time_match = line.scan(/(\d{2}:\d{2}:\d{2},\d{3}) --\> (\d{2}:\d{2}:\d{2},\d{3})/)
21
+
22
+ if $1.nil? && $2.nil?
23
+ output_file.write(line)
24
+ else
25
+ new_start_time = convert_time $1
26
+ new_end_time = convert_time $2
27
+ new_line = "#{new_start_time} --> #{new_end_time}\n"
28
+
29
+ output_file.write(new_line)
30
+ end
31
+ end
32
+
33
+ end_time = Time.now
34
+
35
+ puts "File created with success!"
36
+ puts "Elapsed time: #{end_time-start_time} seconds."
37
+ end
38
+
39
+ def convert_time time
40
+
41
+ if @opts[:operation] == "SUB"
42
+ @opts[:time] = -@opts[:time]
43
+ end
44
+
45
+ current_time = Time.parse(time)
46
+ new_time = Time.at(current_time.to_f + @opts[:time])
47
+ "#{new_time.strftime('%H:%M:%S')},#{new_time.usec/1000}"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module SrtShifter
2
+ VERSION = "0.0.1"
3
+ end
data/lib/srtshifter.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "srtshifter/subtitle"
2
+ require "srtshifter/options"
3
+ require "srtshifter/version"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'srtshifter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "srtshifter"
8
+ gem.version = SrtShifter::VERSION
9
+ gem.authors = ["Thiago Rocha"]
10
+ gem.email = ["kimobr@gmail.com"]
11
+ gem.description = %q{Shifts STR Subtitles}
12
+ gem.summary = %q{It fixes the timing of a given SubRip file}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,8 @@
1
+ require "test_helper"
2
+
3
+ describe SrtShifter do
4
+
5
+ describe "OPTIONS" do
6
+
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ require "test_helper"
2
+
3
+ describe SrtShifter do
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ require "test_helper"
2
+
3
+ describe SrtShifter do
4
+ it "must have a version" do
5
+ SrtShifter::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ 1
2
+ 00:00:20,000 --> 00:00:24,400
3
+ Altocumulus clouds occur between six thousand
4
+
5
+ 2
6
+ 00:00:24,600 --> 00:00:27,800
7
+ and twenty thousand feet above ground level.
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require File.expand_path('../../lib/srtshifter.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: srtshifter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thiago Rocha
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Shifts STR Subtitles
15
+ email:
16
+ - kimobr@gmail.com
17
+ executables:
18
+ - srtshifter
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/srtshifter
28
+ - lib/srtshifter.rb
29
+ - lib/srtshifter/options.rb
30
+ - lib/srtshifter/subtitle.rb
31
+ - lib/srtshifter/version.rb
32
+ - srtshifter.gemspec
33
+ - test/lib/srtshifter/options_test.rb
34
+ - test/lib/srtshifter/subtitle_test.rb
35
+ - test/lib/srtshifter/version_test.rb
36
+ - test/samples/test_srt.srt
37
+ - test/test_helper.rb
38
+ homepage: ''
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: It fixes the timing of a given SubRip file
62
+ test_files:
63
+ - test/lib/srtshifter/options_test.rb
64
+ - test/lib/srtshifter/subtitle_test.rb
65
+ - test/lib/srtshifter/version_test.rb
66
+ - test/samples/test_srt.srt
67
+ - test/test_helper.rb