vtt2ass 0.2.14 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/README.md +1 -0
- data/lib/vtt2ass/ASSFile.rb +29 -2
- data/lib/vtt2ass/ASSStyle.rb +11 -2
- data/lib/vtt2ass/Application.rb +5 -2
- data/lib/vtt2ass/CSSFile.rb +36 -0
- data/lib/vtt2ass/CSSRule.rb +22 -0
- data/lib/vtt2ass/Validator.rb +10 -0
- data/lib/vtt2ass/version.rb +1 -1
- data/lib/vtt2ass.rb +1 -0
- data/vtt2ass.gemspec +2 -0
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725876fe775e13997b8bfea4f1f8d1bd87fe18420c4adfabebc7aa6eced12464
|
4
|
+
data.tar.gz: 13ebdd5f0542f75a9a886e028afb3f93621e68c6b61304d8976320d804d447f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1656502fd7ff8f0b180a8826d593d763e855641e780b70f3e9f320a05c385c5ebfca97b5f037f87bacadabbbe86c35f9718fb6e9a5dd828bd3d9c7b2ede3ac37
|
7
|
+
data.tar.gz: a6099e227e52f45783a9462b3041b272bbe01ff76c87f10c44508df3711a61559865dd180f06ea38c02b2db245a6a9ed48732626e8ef4dd95b664d1f3177ac8f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,7 @@ Options:
|
|
42
42
|
# Default: 52
|
43
43
|
-f, [--font-family=FONT_FAMILY] # Specify a font family for the subtitles
|
44
44
|
# Default: Open Sans Semibold
|
45
|
+
-c, [--css=CSS] # Specify a CSS file path for Hidive subs
|
45
46
|
-q, [--quiet], [--no-quiet] # Don't output to the console
|
46
47
|
|
47
48
|
Run the VTT to ASS conversion for the specified file(s)
|
data/lib/vtt2ass/ASSFile.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Relative imports
|
2
2
|
require_relative 'ASSLine'
|
3
3
|
require_relative 'ASSStyle'
|
4
|
+
require_relative 'CSSFile'
|
5
|
+
require_relative 'CSSRule'
|
4
6
|
|
5
7
|
##
|
6
8
|
# This class defines an ASS subtitle file.
|
@@ -10,9 +12,12 @@ class ASSFile
|
|
10
12
|
|
11
13
|
##
|
12
14
|
# Creates a new ASSFile instance and assigns the default values of instance variables.
|
13
|
-
def initialize(title, width, height)
|
15
|
+
def initialize(title, width, height, css_file_path = nil)
|
14
16
|
@width = width
|
15
17
|
@height = height
|
18
|
+
if not css_file_path.nil? then
|
19
|
+
@css_file = CSSFile.new(css_file_path)
|
20
|
+
end
|
16
21
|
@header = [
|
17
22
|
'[Script Info]',
|
18
23
|
"Title: #{title}",
|
@@ -41,6 +46,8 @@ class ASSFile
|
|
41
46
|
# each VTTLine. All those ASSLine are stored in an array. It also creates an array of ASSStyle that
|
42
47
|
# will be used in the ASS style list.
|
43
48
|
def convertVTTtoASS(vtt_file, font_family, font_size)
|
49
|
+
fs = font_size
|
50
|
+
font_color = '&H00FFFFFF'
|
44
51
|
vtt_file.lines.each do |line|
|
45
52
|
@ass_lines.push(ASSLine.new(line.style, line.time_start, line.time_end, line.text))
|
46
53
|
style_exists = false
|
@@ -51,7 +58,27 @@ class ASSFile
|
|
51
58
|
end
|
52
59
|
end
|
53
60
|
if not style_exists then
|
54
|
-
|
61
|
+
if defined?(@css_file) then
|
62
|
+
css_rule = @css_file.find_rule(line.style)
|
63
|
+
if not css_rule.nil? then
|
64
|
+
css_rule.properties.each do |property|
|
65
|
+
case property[:key]
|
66
|
+
when 'font-family'
|
67
|
+
font_family = property[:value].gsub('"', '').split(' ,').last
|
68
|
+
when 'font-size'
|
69
|
+
em_size = 1
|
70
|
+
#em_size = property[:value][0].eql? '.' ? "0#{property[:value]}" : property[:value]
|
71
|
+
if property[:value][0].eql? '.' then
|
72
|
+
em_size = "0#{property[:value]}".gsub('em', '').to_f
|
73
|
+
end
|
74
|
+
font_size = (fs * em_size).to_i
|
75
|
+
when 'color'
|
76
|
+
font_color = ASSStyle.convert_color(property[:value])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@ass_styles.push(ASSStyle.new(line.style, line.params, font_family, font_size, font_color, @width, @height))
|
55
82
|
end
|
56
83
|
end
|
57
84
|
end
|
data/lib/vtt2ass/ASSStyle.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Relative imports
|
2
2
|
require_relative 'ASSStyleParams'
|
3
|
+
require_relative 'Validator'
|
4
|
+
require 'redgreenblue'
|
3
5
|
|
4
6
|
##
|
5
7
|
# This class defines an ASS style that can be applied on a subtitle line.
|
@@ -13,11 +15,12 @@ class ASSStyle
|
|
13
15
|
# * Requires +params+, a string of VTT styling as input.
|
14
16
|
# * Requires a video +width+ as input.
|
15
17
|
# * Requires a video +height+ as input.
|
16
|
-
def initialize(style_name, params, font_family, font_size, width, height)
|
18
|
+
def initialize(style_name, params, font_family, font_size, font_color, width, height)
|
17
19
|
@width = width
|
18
20
|
@height = height
|
19
21
|
@font_family = font_family
|
20
22
|
@font_size = font_size
|
23
|
+
@font_color = font_color
|
21
24
|
@style_name = style_name
|
22
25
|
@s_params = ASSStyleParams.new(params, width, height)
|
23
26
|
if style_name.eql? 'MainTop' then
|
@@ -28,6 +31,12 @@ class ASSStyle
|
|
28
31
|
##
|
29
32
|
# This method assigns the object values to an ASS style line and outputs it.
|
30
33
|
def to_s
|
31
|
-
return "Style: #{@style_name},#{@font_family},#{@font_size},&
|
34
|
+
return "Style: #{@style_name},#{@font_family},#{@font_size},#{@font_color},&H000000FF,&H00020713,&H00000000,-1,0,0,0,100,100,0,0,1,2.0,2.0,#{@s_params.alignment},#{@s_params.horizontal_margin},0,#{@s_params.vertical_margin},1"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.convert_color(color_value)
|
38
|
+
color_value.gsub!('#', '')
|
39
|
+
color = Validator.hex?(color_value) ? RGB.hex(color_value) : RGB.css(color_value)
|
40
|
+
return ("&H00%02x%02x%02x" % [color.b, color.g, color.r]).upcase
|
32
41
|
end
|
33
42
|
end
|
data/lib/vtt2ass/Application.rb
CHANGED
@@ -20,7 +20,9 @@ class Application
|
|
20
20
|
@title = options[:title]
|
21
21
|
end
|
22
22
|
@quiet = options[:quiet]
|
23
|
-
|
23
|
+
if options[:css] then
|
24
|
+
@css = options[:css].gsub('\\', '/')
|
25
|
+
end
|
24
26
|
end
|
25
27
|
|
26
28
|
##
|
@@ -55,7 +57,8 @@ class Application
|
|
55
57
|
ass_file = ASSFile.new(
|
56
58
|
(defined?(@title) ? @title : File.basename(file_path).gsub('.vtt', '')),
|
57
59
|
@width,
|
58
|
-
@height
|
60
|
+
@height,
|
61
|
+
defined?(@css) ? @css : nil
|
59
62
|
)
|
60
63
|
ass_file.convertVTTtoASS(vtt_file, @font_family, @font_size)
|
61
64
|
return ass_file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'css_parser'
|
2
|
+
require_relative 'CSSRule'
|
3
|
+
|
4
|
+
class CSSFile
|
5
|
+
attr_reader :rules
|
6
|
+
include CssParser
|
7
|
+
|
8
|
+
def initialize(file_path)
|
9
|
+
@file_path = file_path
|
10
|
+
parser = CssParser::Parser.new
|
11
|
+
parser.load_file!(file_path)
|
12
|
+
@rules = []
|
13
|
+
parser.each_selector do |selector, declarations, specificity|
|
14
|
+
css_obj = CSSRule.new(selector, declarations)
|
15
|
+
if not css_obj.name.empty? then
|
16
|
+
@rules.push(css_obj)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_rule(value)
|
22
|
+
return_rule = nil
|
23
|
+
@rules.each do |rule|
|
24
|
+
if rule.name == value then
|
25
|
+
return_rule = rule
|
26
|
+
break
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return return_rule
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
return @file_path
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CSSRule
|
2
|
+
attr_reader :name, :properties
|
3
|
+
|
4
|
+
def initialize(selector, declarations)
|
5
|
+
@name = reduce_selector(selector)
|
6
|
+
declarations.split(/;\s?/).each do |dec|
|
7
|
+
@properties = []
|
8
|
+
temp = dec.split(/:\s?/)
|
9
|
+
@properties.push(
|
10
|
+
{ key: temp.first, value: temp.last}
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
return "#{@name} #{@properties}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def reduce_selector(selector)
|
20
|
+
return selector.to_s.gsub(/\.rmp-container>\.rmp-content>\.rmp-cc-area>\.rmp-cc-container>\.rmp-cc-display>\.rmp-cc-cue\s?\.?/, '')
|
21
|
+
end
|
22
|
+
end
|
data/lib/vtt2ass/version.rb
CHANGED
data/lib/vtt2ass.rb
CHANGED
@@ -15,6 +15,7 @@ class MainCommand < Thor
|
|
15
15
|
method_option :title, :aliases => '-t', :desc => 'Specify a title for you file. If the input is a directory, all files will share the same title.', :type => :string
|
16
16
|
method_option :font_size, :aliases => '-s', :desc => 'Specify a font size for the subtitles', :default => 52, :type => :numeric
|
17
17
|
method_option :font_family, :aliases => '-f', :desc => 'Specify a font family for the subtitles', :default => 'Open Sans Semibold', :type => :string
|
18
|
+
method_option :css, :aliases => '-c', :desc => 'Specify a CSS file path for Hidive subs', :type => :string
|
18
19
|
method_option :quiet, :aliases => '-q', :desc => 'Don\'t output to the console', :type => :boolean
|
19
20
|
def convert(input)
|
20
21
|
app = Application.new(input, options)
|
data/vtt2ass.gemspec
CHANGED
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_dependency 'htmlentities', '~> 4.3'
|
29
29
|
spec.add_dependency 'thor', '~> 1.1'
|
30
|
+
spec.add_dependency 'css_parser', '~> 1.10'
|
31
|
+
spec.add_dependency 'redgreenblue', '~> 0.15'
|
30
32
|
|
31
33
|
spec.add_development_dependency 'rake', '~> 12.0'
|
32
34
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vtt2ass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis-Philippe Fortin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: css_parser
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: redgreenblue
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.15'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.15'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,8 +158,11 @@ files:
|
|
130
158
|
- lib/vtt2ass/ASSStyle.rb
|
131
159
|
- lib/vtt2ass/ASSStyleParams.rb
|
132
160
|
- lib/vtt2ass/Application.rb
|
161
|
+
- lib/vtt2ass/CSSFile.rb
|
162
|
+
- lib/vtt2ass/CSSRule.rb
|
133
163
|
- lib/vtt2ass/VTTFile.rb
|
134
164
|
- lib/vtt2ass/VTTLine.rb
|
165
|
+
- lib/vtt2ass/Validator.rb
|
135
166
|
- lib/vtt2ass/version.rb
|
136
167
|
- vtt2ass.gemspec
|
137
168
|
homepage: https://gitlab.com/dkb-weeblets/vtt2ass
|