vtt2ass 0.3.5 → 0.3.6
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/.gitignore +3 -0
- data/lib/vtt2ass/application.rb +4 -1
- data/lib/vtt2ass/ass_file.rb +3 -2
- data/lib/vtt2ass/ass_style.rb +3 -2
- data/lib/vtt2ass/ass_style_params.rb +1 -0
- data/lib/vtt2ass/version.rb +1 -1
- data/lib/vtt2ass.rb +50 -35
- data/vtt2ass.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bacdcc421becff18a39326c953658fb28c07eb06bd5a4dacc951098e661a9601
|
4
|
+
data.tar.gz: ef37756d00cdfa88d23a778fd2ad0718e1129e74e412aa77a5ceebfd0daeb5f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74ffa9400ecd804d00fe2a5649cb9a7e5b0ebb14b2cb7fd1fe4744517b047c4af4e05edf5e0f9ad1b8d34e47ece1d4c8f8e74c749b78f88a193258853fffceb9
|
7
|
+
data.tar.gz: e861fe563ab6ef59085062bd1e2269ca56f20eb939df05eaead50ff78fb754c8339fdb4291c3cf9f357fdd5712df7a2fcbacdf8d4bce2a2773e11c51694d37ce
|
data/.gitignore
CHANGED
data/lib/vtt2ass/application.rb
CHANGED
@@ -39,12 +39,14 @@ class Application
|
|
39
39
|
puts 'ERROR: The application stopped unexpectedly. The conversion may not have been completed.'
|
40
40
|
rescue StandardError => e
|
41
41
|
puts e.message
|
42
|
+
puts e.backtrace
|
42
43
|
end
|
43
44
|
|
44
45
|
##
|
45
46
|
# This method launches the conversion process on the specified input file.
|
46
47
|
def convert(input_path)
|
47
48
|
output = sanitize_path(@options[:output])
|
49
|
+
output = '.' if output.nil?
|
48
50
|
raise StandardError, 'ERROR: Output directory does not exist.' unless File.directory?(output)
|
49
51
|
|
50
52
|
ass_file = vtt_to_ass(input_path)
|
@@ -72,7 +74,8 @@ class Application
|
|
72
74
|
@options[:height],
|
73
75
|
css_file
|
74
76
|
)
|
75
|
-
ass_file.convert_vtt_to_ass(vtt_file, @options[:font_family], @options[:font_size],
|
77
|
+
ass_file.convert_vtt_to_ass(vtt_file, @options[:font_family], @options[:font_size],
|
78
|
+
{ line: @options[:line_offset], caption: @options[:caption_offset] })
|
76
79
|
ass_file
|
77
80
|
end
|
78
81
|
end
|
data/lib/vtt2ass/ass_file.rb
CHANGED
@@ -16,6 +16,7 @@ class ASSFile
|
|
16
16
|
def initialize(title, width, height, css_file_path = nil)
|
17
17
|
@width = width
|
18
18
|
@height = height
|
19
|
+
@css_file = nil
|
19
20
|
@css_file = CSSFile.new(css_file_path) unless css_file_path.nil?
|
20
21
|
@header = <<~HEADER
|
21
22
|
[Script Info]
|
@@ -44,7 +45,7 @@ class ASSFile
|
|
44
45
|
# This method receives a VTTFile object and font arguments creates new ASSLine with the params of
|
45
46
|
# each VTTLine. All those ASSLine are stored in an array. It also creates an array of ASSStyle that
|
46
47
|
# will be used in the ASS style list.
|
47
|
-
def convert_vtt_to_ass(vtt_file, font_family, font_size,
|
48
|
+
def convert_vtt_to_ass(vtt_file, font_family, font_size, offset = { line: 0, caption: 0 }) # rubocop:disable Metrics/MethodLength
|
48
49
|
fs = font_size
|
49
50
|
vtt_file.lines.each do |line| # rubocop:disable Metrics/BlockLength
|
50
51
|
font_color = '&H00FFFFFF'
|
@@ -83,7 +84,7 @@ class ASSFile
|
|
83
84
|
ASSStyle.new(
|
84
85
|
line.style, line.params,
|
85
86
|
font_family, font_size, font_color, is_bold, is_italic,
|
86
|
-
|
87
|
+
offset, @width, @height
|
87
88
|
)
|
88
89
|
)
|
89
90
|
end
|
data/lib/vtt2ass/ass_style.rb
CHANGED
@@ -16,7 +16,7 @@ class ASSStyle
|
|
16
16
|
# * Requires +params+, a string of VTT styling as input.
|
17
17
|
# * Requires a video +width+ as input.
|
18
18
|
# * Requires a video +height+ as input.
|
19
|
-
def initialize(style_name, params, font_family, font_size, font_color, is_bold, is_italic,
|
19
|
+
def initialize(style_name, params, font_family, font_size, font_color, is_bold, is_italic, offset, width, height)
|
20
20
|
@width = width
|
21
21
|
@height = height
|
22
22
|
@font_family = font_family
|
@@ -25,7 +25,8 @@ class ASSStyle
|
|
25
25
|
@style_name = style_name
|
26
26
|
@s_params = ASSStyleParams.new(params, width, height)
|
27
27
|
@s_params.vertical_margin = 50 if style_name.eql? 'MainTop'
|
28
|
-
@s_params.vertical_margin -=
|
28
|
+
@s_params.vertical_margin -= offset[:line] if style_name.include?('Subtitle') || style_name.eql?('Main')
|
29
|
+
@s_params.vertical_margin += offset[:caption] if style_name.include?('Caption') || style_name.eql?('MainTop')
|
29
30
|
@is_italic = is_italic
|
30
31
|
@is_bold = is_bold
|
31
32
|
end
|
@@ -10,6 +10,7 @@ class ASSStyleParams
|
|
10
10
|
# It takes VTT style arguments and assign them to their respectful instance variable.
|
11
11
|
# It calls methods to create ASS values from the VTT cue settings.
|
12
12
|
def initialize(params, width, height)
|
13
|
+
@align = nil
|
13
14
|
split_params(params)
|
14
15
|
create_alignment
|
15
16
|
create_horizontal_margin(width)
|
data/lib/vtt2ass/version.rb
CHANGED
data/lib/vtt2ass.rb
CHANGED
@@ -13,41 +13,56 @@ class MainCommand < Thor
|
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'convert INPUT', 'Run the VTT to ASS conversion for the specified file(s)'
|
16
|
-
method_option :output,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
method_option :
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
16
|
+
method_option :output,
|
17
|
+
aliases: '-o',
|
18
|
+
desc: 'Output directory of the converted file',
|
19
|
+
lazy_default: './',
|
20
|
+
type: :string
|
21
|
+
method_option :title,
|
22
|
+
aliases: '-t',
|
23
|
+
desc: 'Specify a title for you file. If the input is a directory, '\
|
24
|
+
'all files will share the same title.',
|
25
|
+
type: :string
|
26
|
+
method_option :font_size,
|
27
|
+
aliases: '-s',
|
28
|
+
desc: 'Specify a font size for the subtitles',
|
29
|
+
default: 52,
|
30
|
+
type: :numeric
|
31
|
+
method_option :font_family,
|
32
|
+
aliases: '-f',
|
33
|
+
desc: 'Specify a font family for the subtitles',
|
34
|
+
default: 'Open Sans Semibold',
|
35
|
+
type: :string
|
36
|
+
method_option :css,
|
37
|
+
aliases: '-c',
|
38
|
+
desc: 'Specify a CSS file path for Hidive subs',
|
39
|
+
type: :string
|
40
|
+
method_option :line_offset,
|
41
|
+
aliases: '-l',
|
42
|
+
desc: 'Specify a line offset for the main dialog (e.g. 50 lowers the '\
|
43
|
+
'text line by 50px of the total height)',
|
44
|
+
default: 0,
|
45
|
+
type: :numeric
|
46
|
+
method_option :caption_offset,
|
47
|
+
aliases: '-z',
|
48
|
+
desc: 'Specify a line offset for the captions (e.g. 50 lowers the '\
|
49
|
+
'text line by 50px of the total height)',
|
50
|
+
default: 0,
|
51
|
+
type: :numeric
|
52
|
+
method_option :width,
|
53
|
+
aliases: '-w',
|
54
|
+
desc: 'Specify the video width',
|
55
|
+
default: 1920,
|
56
|
+
type: :numeric
|
57
|
+
method_option :height,
|
58
|
+
aliases: '-h',
|
59
|
+
desc: 'Specify the video height',
|
60
|
+
default: 1080,
|
61
|
+
type: :numeric
|
62
|
+
method_option :quiet,
|
63
|
+
aliases: '-q',
|
64
|
+
desc: 'Don\'t output to the console',
|
65
|
+
type: :boolean
|
51
66
|
def convert(input)
|
52
67
|
app = Application.new(input, options)
|
53
68
|
app.start
|
data/vtt2ass.gemspec
CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
36
|
spec.add_development_dependency 'rake', '~> 12.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 1.38'
|
37
38
|
spec.add_development_dependency 'yard', '~> 0.9'
|
38
39
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
39
40
|
end
|
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.6
|
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-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '12.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.38'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.38'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: yard
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|