vtt2ass 0.3.0 → 0.3.3
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 +4 -4
- data/README.md +2 -0
- data/lib/vtt2ass/{Application.rb → application.rb} +16 -6
- data/lib/vtt2ass/{ASSFile.rb → ass_file.rb} +17 -7
- data/lib/vtt2ass/{ASSLine.rb → ass_line.rb} +0 -0
- data/lib/vtt2ass/{ASSStyle.rb → ass_style.rb} +10 -4
- data/lib/vtt2ass/{ASSStyleParams.rb → ass_style_params.rb} +0 -0
- data/lib/vtt2ass/{CSSFile.rb → css_file.rb} +1 -1
- data/lib/vtt2ass/{CSSRule.rb → css_rule.rb} +1 -1
- data/lib/vtt2ass/{Validator.rb → validator.rb} +0 -0
- data/lib/vtt2ass/version.rb +1 -1
- data/lib/vtt2ass/{VTTFile.rb → vtt_file.rb} +1 -1
- data/lib/vtt2ass/{VTTLine.rb → vtt_line.rb} +0 -0
- data/lib/vtt2ass.rb +2 -1
- metadata +12 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3959903aff7b00e3544a9656edf9a17f9508445db041d28518549926cca7a09
|
|
4
|
+
data.tar.gz: 51359298d3ff0ed985ce10f48b18c5f2b84eec19b267e0781cd2b6ef12320e22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae929a40df7f483e8bd76cc43920177d299756cfe9774fc850f0e7a66b877d74c40314d2d8647cabf6ba5b2c7e0743533ce9236873d28c86203a76c74c9628d8
|
|
7
|
+
data.tar.gz: 1a280a2a76c87e2678c6275b65c1226779799e61abd8b2909816897e5e44b18a649d0c0f364ae97249044593656120e823edf80f06836703963840321449d088
|
data/README.md
CHANGED
|
@@ -43,6 +43,8 @@ Options:
|
|
|
43
43
|
-f, [--font-family=FONT_FAMILY] # Specify a font family for the subtitles
|
|
44
44
|
# Default: Open Sans Semibold
|
|
45
45
|
-c, [--css=CSS] # Specify a CSS file path for Hidive subs
|
|
46
|
+
-l, [--line-offset=N] # Specify a line offset for the main dialog (e.g. 50 lowers the text line by 50px of the total height)
|
|
47
|
+
# Default: 0
|
|
46
48
|
-q, [--quiet], [--no-quiet] # Don't output to the console
|
|
47
49
|
|
|
48
50
|
Run the VTT to ASS conversion for the specified file(s)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Relative imports
|
|
2
|
-
require_relative '
|
|
3
|
-
require_relative '
|
|
2
|
+
require_relative 'vtt_file'
|
|
3
|
+
require_relative 'ass_file'
|
|
4
4
|
|
|
5
5
|
##
|
|
6
6
|
# Main application class that manages all the operations.
|
|
@@ -21,8 +21,9 @@ class Application
|
|
|
21
21
|
end
|
|
22
22
|
@quiet = options[:quiet]
|
|
23
23
|
if options[:css] then
|
|
24
|
-
@css = options[:css].gsub('\\', '/')
|
|
24
|
+
@css = options[:css].gsub('\\', '/').delete_suffix('/')
|
|
25
25
|
end
|
|
26
|
+
@line_offset = options[:line_offset]
|
|
26
27
|
end
|
|
27
28
|
|
|
28
29
|
##
|
|
@@ -53,14 +54,23 @@ class Application
|
|
|
53
54
|
# This method creates a new VTTFile object from the file path provided and convert its content
|
|
54
55
|
# inside a new ASSFile object.
|
|
55
56
|
def vtt_to_ass(file_path)
|
|
57
|
+
base_file_name = File.basename(file_path).gsub('.vtt', '')
|
|
58
|
+
css_file = nil
|
|
59
|
+
if defined?(@css) and File.directory?(@css) then
|
|
60
|
+
css_file = "#{@css}/#{base_file_name}.css"
|
|
61
|
+
elsif File.file?("#{file_path.gsub('.vtt', '')}.css") then
|
|
62
|
+
css_file = "#{file_path.gsub('.vtt', '')}.css"
|
|
63
|
+
else
|
|
64
|
+
css_file = @css
|
|
65
|
+
end
|
|
56
66
|
vtt_file = VTTFile.new(file_path, @width, @height)
|
|
57
67
|
ass_file = ASSFile.new(
|
|
58
|
-
(defined?(@title) ? @title :
|
|
68
|
+
(defined?(@title) ? @title : base_file_name),
|
|
59
69
|
@width,
|
|
60
70
|
@height,
|
|
61
|
-
|
|
71
|
+
css_file
|
|
62
72
|
)
|
|
63
|
-
ass_file.convertVTTtoASS(vtt_file, @font_family, @font_size)
|
|
73
|
+
ass_file.convertVTTtoASS(vtt_file, @font_family, @font_size, @line_offset)
|
|
64
74
|
return ass_file
|
|
65
75
|
end
|
|
66
76
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Relative imports
|
|
2
|
-
require_relative '
|
|
3
|
-
require_relative '
|
|
4
|
-
require_relative '
|
|
5
|
-
require_relative '
|
|
2
|
+
require_relative 'ass_line'
|
|
3
|
+
require_relative 'ass_style'
|
|
4
|
+
require_relative 'css_file'
|
|
5
|
+
require_relative 'css_rule'
|
|
6
6
|
|
|
7
7
|
##
|
|
8
8
|
# This class defines an ASS subtitle file.
|
|
@@ -45,10 +45,12 @@ class ASSFile
|
|
|
45
45
|
# This method receives a VTTFile object and font arguments creates new ASSLine with the params of
|
|
46
46
|
# each VTTLine. All those ASSLine are stored in an array. It also creates an array of ASSStyle that
|
|
47
47
|
# will be used in the ASS style list.
|
|
48
|
-
def convertVTTtoASS(vtt_file, font_family, font_size)
|
|
48
|
+
def convertVTTtoASS(vtt_file, font_family, font_size, line_offset = 0)
|
|
49
49
|
fs = font_size
|
|
50
|
-
font_color = '&H00FFFFFF'
|
|
51
50
|
vtt_file.lines.each do |line|
|
|
51
|
+
font_color = '&H00FFFFFF'
|
|
52
|
+
is_italic = false
|
|
53
|
+
is_bold = false
|
|
52
54
|
@ass_lines.push(ASSLine.new(line.style, line.time_start, line.time_end, line.text))
|
|
53
55
|
style_exists = false
|
|
54
56
|
@ass_styles.each do |style|
|
|
@@ -74,11 +76,19 @@ class ASSFile
|
|
|
74
76
|
font_size = (fs * em_size).to_i
|
|
75
77
|
when 'color'
|
|
76
78
|
font_color = ASSStyle.convert_color(property[:value])
|
|
79
|
+
when 'font-weight'
|
|
80
|
+
if property[:value].eql? 'bold' then
|
|
81
|
+
is_bold = true
|
|
82
|
+
end
|
|
83
|
+
when 'font-style'
|
|
84
|
+
if property[:value].eql? 'italic' then
|
|
85
|
+
is_italic = true
|
|
86
|
+
end
|
|
77
87
|
end
|
|
78
88
|
end
|
|
79
89
|
end
|
|
80
90
|
end
|
|
81
|
-
@ass_styles.push(ASSStyle.new(line.style, line.params, font_family, font_size, font_color, @width, @height))
|
|
91
|
+
@ass_styles.push(ASSStyle.new(line.style, line.params, font_family, font_size, font_color, is_bold, is_italic, line_offset, @width, @height))
|
|
82
92
|
end
|
|
83
93
|
end
|
|
84
94
|
end
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Relative imports
|
|
2
|
-
require_relative '
|
|
3
|
-
require_relative '
|
|
2
|
+
require_relative 'ass_style_params'
|
|
3
|
+
require_relative 'validator'
|
|
4
4
|
require 'redgreenblue'
|
|
5
5
|
|
|
6
6
|
##
|
|
@@ -15,7 +15,7 @@ class ASSStyle
|
|
|
15
15
|
# * Requires +params+, a string of VTT styling as input.
|
|
16
16
|
# * Requires a video +width+ as input.
|
|
17
17
|
# * Requires a video +height+ as input.
|
|
18
|
-
def initialize(style_name, params, font_family, font_size, font_color, width, height)
|
|
18
|
+
def initialize(style_name, params, font_family, font_size, font_color, is_bold, is_italic, line_offset, width, height)
|
|
19
19
|
@width = width
|
|
20
20
|
@height = height
|
|
21
21
|
@font_family = font_family
|
|
@@ -26,12 +26,18 @@ class ASSStyle
|
|
|
26
26
|
if style_name.eql? 'MainTop' then
|
|
27
27
|
@s_params.vertical_margin = 50
|
|
28
28
|
end
|
|
29
|
+
if style_name.include? 'Subtitle' then
|
|
30
|
+
@s_params.vertical_margin -= line_offset
|
|
31
|
+
end
|
|
32
|
+
@is_italic = is_italic
|
|
33
|
+
@is_bold = is_bold
|
|
29
34
|
end
|
|
30
35
|
|
|
31
36
|
##
|
|
32
37
|
# This method assigns the object values to an ASS style line and outputs it.
|
|
33
38
|
def to_s
|
|
34
|
-
|
|
39
|
+
# Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
|
|
40
|
+
return "Style: #{@style_name},#{@font_family},#{@font_size},#{@font_color},&H000000FF,&H00020713,&H00000000,#{@is_bold ? '-1' : '0'},#{@is_italic ? '-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
41
|
end
|
|
36
42
|
|
|
37
43
|
def self.convert_color(color_value)
|
|
File without changes
|
|
File without changes
|
data/lib/vtt2ass/version.rb
CHANGED
|
File without changes
|
data/lib/vtt2ass.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'thor'
|
|
|
3
3
|
|
|
4
4
|
# Relative imports
|
|
5
5
|
require_relative 'vtt2ass/version'
|
|
6
|
-
require_relative 'vtt2ass/
|
|
6
|
+
require_relative 'vtt2ass/application'
|
|
7
7
|
|
|
8
8
|
class MainCommand < Thor
|
|
9
9
|
def self.exit_on_failure?
|
|
@@ -16,6 +16,7 @@ class MainCommand < Thor
|
|
|
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
18
|
method_option :css, :aliases => '-c', :desc => 'Specify a CSS file path for Hidive subs', :type => :string
|
|
19
|
+
method_option :line_offset, :aliases => '-l', :desc => 'Specify a line offset for the main dialog (e.g. 50 lowers the text line by 50px of the total height)', :default => 0, :type => :numeric
|
|
19
20
|
method_option :quiet, :aliases => '-q', :desc => 'Don\'t output to the console', :type => :boolean
|
|
20
21
|
def convert(input)
|
|
21
22
|
app = Application.new(input, options)
|
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.3.
|
|
4
|
+
version: 0.3.3
|
|
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: 2022-
|
|
11
|
+
date: 2022-05-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: htmlentities
|
|
@@ -153,17 +153,17 @@ files:
|
|
|
153
153
|
- doc/top-level-namespace.html
|
|
154
154
|
- exe/vtt2ass
|
|
155
155
|
- lib/vtt2ass.rb
|
|
156
|
-
- lib/vtt2ass/
|
|
157
|
-
- lib/vtt2ass/
|
|
158
|
-
- lib/vtt2ass/
|
|
159
|
-
- lib/vtt2ass/
|
|
160
|
-
- lib/vtt2ass/
|
|
161
|
-
- lib/vtt2ass/
|
|
162
|
-
- lib/vtt2ass/
|
|
163
|
-
- lib/vtt2ass/
|
|
164
|
-
- lib/vtt2ass/VTTLine.rb
|
|
165
|
-
- lib/vtt2ass/Validator.rb
|
|
156
|
+
- lib/vtt2ass/application.rb
|
|
157
|
+
- lib/vtt2ass/ass_file.rb
|
|
158
|
+
- lib/vtt2ass/ass_line.rb
|
|
159
|
+
- lib/vtt2ass/ass_style.rb
|
|
160
|
+
- lib/vtt2ass/ass_style_params.rb
|
|
161
|
+
- lib/vtt2ass/css_file.rb
|
|
162
|
+
- lib/vtt2ass/css_rule.rb
|
|
163
|
+
- lib/vtt2ass/validator.rb
|
|
166
164
|
- lib/vtt2ass/version.rb
|
|
165
|
+
- lib/vtt2ass/vtt_file.rb
|
|
166
|
+
- lib/vtt2ass/vtt_line.rb
|
|
167
167
|
- vtt2ass.gemspec
|
|
168
168
|
homepage: https://gitlab.com/dkb-weeblets/vtt2ass
|
|
169
169
|
licenses:
|