smart_ass 0.2.0 → 0.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.
- checksums.yaml +7 -0
- data/.ruby-version +1 -0
- data/README.md +6 -2
- data/bin/smart_ass +19 -6
- data/lib/smart_ass.rb +2 -1
- data/lib/smart_ass/app.rb +19 -29
- data/lib/smart_ass/input_file.rb +32 -0
- data/lib/smart_ass/{ass.rb → mkv.rb} +23 -9
- data/lib/smart_ass/version.rb +1 -1
- data/spec/{ass_spec.rb → mkv_spec.rb} +2 -2
- metadata +12 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03ac31d6a1df96a33bb982c9606d5bc571c2c378
|
4
|
+
data.tar.gz: 6b629af238f02738dd2bcc5da651fe89faf48b84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c62f50057fc6f6b3bfdf030a6f7511c7e4e4d0e2d745d515a8fef3152d997025b42440bb7e8631dc397e5922cf02d11fd7b26acfcee6cf1a7159a0905dd53f35
|
7
|
+
data.tar.gz: 139f5889b4507601c6acf28d8200afa20ae6bc5ca7666452e7c45ccf4598d25a83362a7b1c0132677e98c072d0ea266ba3bb83d7330b2ba86174a31154ce7f96
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p195
|
data/README.md
CHANGED
@@ -34,9 +34,13 @@ Install the Ruby Gem:
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
-
This is really minimal.
|
37
|
+
This is really minimal. To process mkvs:
|
38
38
|
|
39
|
-
smart_ass path/to/movie.mkv
|
39
|
+
smart_ass --type mkv path/to/movie.mkv
|
40
|
+
|
41
|
+
To process .ass scripts:
|
42
|
+
|
43
|
+
smart_ass --type ass --suffix bt709 path/to/movie.mkv
|
40
44
|
|
41
45
|
## Contributing
|
42
46
|
|
data/bin/smart_ass
CHANGED
@@ -3,11 +3,24 @@
|
|
3
3
|
$:.unshift File.join(File.dirname(File.dirname(__FILE__)), 'lib')
|
4
4
|
|
5
5
|
require 'smart_ass'
|
6
|
+
require 'optparse'
|
7
|
+
require 'ostruct'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
options = OpenStruct.new
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: smart_ass [options] <file>"
|
13
|
+
opts.on('--type [TYPE]', SmartAss::InputFile.types,
|
14
|
+
'Type of the file you are trying to process') do |type|
|
15
|
+
options.type = type
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('--suffix [STRING]', 'String to append to output file name') do |s|
|
19
|
+
options.suffix = s
|
20
|
+
end
|
13
21
|
end
|
22
|
+
|
23
|
+
parser.parse!
|
24
|
+
|
25
|
+
app = SmartAss::App.new(options, ARGV[0])
|
26
|
+
app.run
|
data/lib/smart_ass.rb
CHANGED
@@ -2,7 +2,8 @@ require "smart_ass/version"
|
|
2
2
|
|
3
3
|
module SmartAss
|
4
4
|
autoload :App, 'smart_ass/app'
|
5
|
-
autoload :
|
5
|
+
autoload :MKV, 'smart_ass/mkv'
|
6
|
+
autoload :InputFile, 'smart_ass/input_file'
|
6
7
|
autoload :BT601ColorMatrix, 'smart_ass/bt601_colormatrix'
|
7
8
|
autoload :BT709ColorMatrix, 'smart_ass/bt709_colormatrix'
|
8
9
|
autoload :RGBAColor, 'smart_ass/rgba_color'
|
data/lib/smart_ass/app.rb
CHANGED
@@ -1,22 +1,35 @@
|
|
1
1
|
class SmartAss::App
|
2
|
-
def initialize(file)
|
3
|
-
|
4
|
-
|
2
|
+
def initialize(options, file)
|
3
|
+
if options.type == :ass and not options.suffix
|
4
|
+
raise "Please provide a suffix for the output file!"
|
5
|
+
end
|
6
|
+
|
7
|
+
@ass = SmartAss::InputFile.from_type(options.type, file)
|
8
|
+
@output_suffix = options.suffix
|
9
|
+
@file = Pathname.new(file)
|
5
10
|
end
|
6
11
|
|
7
12
|
def run
|
8
13
|
# function composition baby!
|
9
|
-
write_ass_script replace_colors
|
14
|
+
write_ass_script replace_colors @ass.stream
|
10
15
|
end
|
11
16
|
|
12
17
|
private
|
13
18
|
def write_ass_script(ass_script)
|
14
|
-
|
15
|
-
File.open(@file.expand_path.dirname + script_file_basename, "w") {|f|
|
19
|
+
File.open(@file.expand_path.dirname + output_file_basename, "w") {|f|
|
16
20
|
f.puts(ass_script)
|
17
21
|
}
|
18
22
|
end
|
19
23
|
|
24
|
+
def output_file_basename
|
25
|
+
name = [
|
26
|
+
@file.basename(@file.extname),
|
27
|
+
@output_suffix
|
28
|
+
].select{|a| a}.join('-')
|
29
|
+
|
30
|
+
"#{name}.ass"
|
31
|
+
end
|
32
|
+
|
20
33
|
def replace_colors(ass_script)
|
21
34
|
ass_script.gsub(/&H[\da-zA-Z]{6,8}/) {|c| convert_color(c)}
|
22
35
|
end
|
@@ -41,27 +54,4 @@ class SmartAss::App
|
|
41
54
|
|
42
55
|
@_colors_cache[c]
|
43
56
|
end
|
44
|
-
|
45
|
-
def track
|
46
|
-
if @ass.tracks.size > 1
|
47
|
-
track = ask_for_track
|
48
|
-
elsif @ass.tracks.size == 1
|
49
|
-
track = @ass.tracks[0]
|
50
|
-
else
|
51
|
-
puts "No ASS tracks found. Aborting."
|
52
|
-
exit
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def ask_for_track
|
57
|
-
puts "Please enter a track name - #{@ass.tracks.inspect}:"
|
58
|
-
readline.to_i
|
59
|
-
rescue
|
60
|
-
puts "Invalid track provided. Try again."
|
61
|
-
retry
|
62
|
-
end
|
63
|
-
|
64
|
-
def extract(track_id)
|
65
|
-
@ass.extract(track_id)
|
66
|
-
end
|
67
57
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
class SmartAss::InputFile
|
4
|
+
attr_reader :file
|
5
|
+
|
6
|
+
def initialize(file)
|
7
|
+
@file = Pathname.new(file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def stream
|
11
|
+
IO.read(@file)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.types
|
15
|
+
[:mkv, :ass]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_type(type, file)
|
19
|
+
klass(type).new(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.klass(kind)
|
23
|
+
case kind
|
24
|
+
when :mkv
|
25
|
+
SmartAss::MKV
|
26
|
+
when :ass
|
27
|
+
SmartAss::InputFile
|
28
|
+
else
|
29
|
+
raise "Unrecognized kind=#{kind}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,27 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class SmartAss::MKV < SmartAss::InputFile
|
2
|
+
def stream
|
3
|
+
extract track
|
4
|
+
end
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def track
|
7
|
+
if tracks.size > 1
|
8
|
+
track = ask_for_track
|
9
|
+
elsif tracks.size == 1
|
10
|
+
track = tracks[0]
|
11
|
+
else
|
12
|
+
puts "No ASS tracks found. Aborting."
|
13
|
+
exit
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
17
|
def tracks
|
11
18
|
identify.each_line \
|
12
19
|
.map {|l| (l =~ identify_ass_regexp) ? $1 : nil } \
|
13
20
|
.compact \
|
14
|
-
.map
|
21
|
+
.map(&:to_i)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def ask_for_track
|
26
|
+
puts "Please enter a track name - #{tracks.inspect}:"
|
27
|
+
readline.to_i
|
28
|
+
rescue
|
29
|
+
puts "Invalid track provided. Try again."
|
30
|
+
retry
|
15
31
|
end
|
16
32
|
|
17
|
-
# TODO: test this!
|
18
33
|
def extract(track_id)
|
19
34
|
puts `mkvextract tracks "#{expanded_file}" #{track_id}:#{export_temp_file}`
|
20
35
|
IO.read(export_temp_file, :encoding => 'UTF-8') \
|
21
36
|
.tap {|_| File.delete(export_temp_file) }
|
22
37
|
end
|
23
38
|
|
24
|
-
private
|
25
39
|
def identify
|
26
40
|
`mkvmerge -i "#{expanded_file}"`
|
27
41
|
end
|
data/lib/smart_ass/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_ass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Stefano Pigozzi
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Utility for YCbCr ColorMatrix conversion of ASS Subtitles.
|
15
14
|
email:
|
@@ -21,6 +20,7 @@ extra_rdoc_files: []
|
|
21
20
|
files:
|
22
21
|
- .gitignore
|
23
22
|
- .rspec
|
23
|
+
- .ruby-version
|
24
24
|
- Gemfile
|
25
25
|
- LICENSE
|
26
26
|
- README.md
|
@@ -28,50 +28,50 @@ files:
|
|
28
28
|
- bin/smart_ass
|
29
29
|
- lib/smart_ass.rb
|
30
30
|
- lib/smart_ass/app.rb
|
31
|
-
- lib/smart_ass/ass.rb
|
32
31
|
- lib/smart_ass/bt601_colormatrix.rb
|
33
32
|
- lib/smart_ass/bt709_colormatrix.rb
|
33
|
+
- lib/smart_ass/input_file.rb
|
34
|
+
- lib/smart_ass/mkv.rb
|
34
35
|
- lib/smart_ass/rgba_color.rb
|
35
36
|
- lib/smart_ass/version.rb
|
36
37
|
- lib/smart_ass/ycbcr_colormatrix.rb
|
37
38
|
- lib/smart_ass/ycbcr_converter.rb
|
38
39
|
- smart_ass.gemspec
|
39
|
-
- spec/ass_spec.rb
|
40
40
|
- spec/fixtures/info_0
|
41
41
|
- spec/fixtures/info_1_t_3
|
42
42
|
- spec/fixtures/info_3_t_3_5_6
|
43
|
+
- spec/mkv_spec.rb
|
43
44
|
- spec/rgba_color_spec.rb
|
44
45
|
- spec/spec_helper.rb
|
45
46
|
- spec/ycbcr_converter_spec.rb
|
46
47
|
homepage: http://github.com/pigoz/smart_ass
|
47
48
|
licenses: []
|
49
|
+
metadata: {}
|
48
50
|
post_install_message:
|
49
51
|
rdoc_options: []
|
50
52
|
require_paths:
|
51
53
|
- lib
|
52
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
55
|
requirements:
|
55
|
-
- -
|
56
|
+
- - '>='
|
56
57
|
- !ruby/object:Gem::Version
|
57
58
|
version: '0'
|
58
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
-
none: false
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - '>='
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
65
|
rubyforge_project:
|
66
|
-
rubygems_version:
|
66
|
+
rubygems_version: 2.0.2
|
67
67
|
signing_key:
|
68
|
-
specification_version:
|
68
|
+
specification_version: 4
|
69
69
|
summary: Utility for YCbCr ColorMatrix conversion of ASS Subtitles.
|
70
70
|
test_files:
|
71
|
-
- spec/ass_spec.rb
|
72
71
|
- spec/fixtures/info_0
|
73
72
|
- spec/fixtures/info_1_t_3
|
74
73
|
- spec/fixtures/info_3_t_3_5_6
|
74
|
+
- spec/mkv_spec.rb
|
75
75
|
- spec/rgba_color_spec.rb
|
76
76
|
- spec/spec_helper.rb
|
77
77
|
- spec/ycbcr_converter_spec.rb
|