vtt2ass 0.2.1 → 0.2.2
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/.gitlab-ci.yml +4 -6
- data/README.md +2 -1
- data/lib/vtt2ass.rb +1 -1
- data/lib/vtt2ass/ASSFile.rb +2 -2
- data/lib/vtt2ass/ASSStyle.rb +57 -31
- data/lib/vtt2ass/Application.rb +2 -2
- data/lib/vtt2ass/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b8d61e8c97eae4983b1b8b3011817d8ceaf12381a60c5ba3dfbf51e5c84ffc7
|
4
|
+
data.tar.gz: a2777f056b947249330e7f4b828172eb5e9f90d11939fcfa44c9213a5d2ac86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5c15a86a9706ea9a521ee6e719cdeb2d99e7b394df7800bd6862385e20cc8b779e63a0929b6ddf700f742b48cb07a258f01e7eda5256732331be7bc7f879995
|
7
|
+
data.tar.gz: 1b6a6da137d123e0aeca34963d8dcc1aeacc437666f1f277efe12d9747f83edc16add7ab399030017d57901d04bfceed7ac3e0caaecff10c6042577265ef03dc
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -14,18 +14,16 @@ test:
|
|
14
14
|
build:
|
15
15
|
stage: build
|
16
16
|
only:
|
17
|
-
-
|
17
|
+
- develop
|
18
18
|
artifacts:
|
19
19
|
untracked: true
|
20
20
|
script:
|
21
|
-
-
|
22
|
-
- gem build vtt2ass.gemspec -o "build/release.gem"
|
21
|
+
- gem build vtt2ass.gemspec
|
23
22
|
|
24
23
|
deploy:
|
25
24
|
stage: deploy
|
26
25
|
only:
|
27
26
|
- master
|
28
|
-
dependencies:
|
29
|
-
- build
|
30
27
|
script:
|
31
|
-
- gem
|
28
|
+
- gem install dpl --pre
|
29
|
+
- dpl rubygems --api_key $K8S_SECRET_RUBYGEMS_API_KEY
|
data/README.md
CHANGED
@@ -38,5 +38,6 @@ Usage: vtt2ass [options]
|
|
38
38
|
Specific options:
|
39
39
|
-i, --input DIRECTORY Specify a custom input directory (default: './input')
|
40
40
|
-o, --output DIRECTORY Specify a custom output directory (default: './output')
|
41
|
-
-s, --font-size SIZE Specify a font size for the subtitles (default:
|
41
|
+
-s, --font-size SIZE Specify a font size for the subtitles (default: 52)
|
42
|
+
-v, --version Show version
|
42
43
|
```
|
data/lib/vtt2ass.rb
CHANGED
@@ -23,7 +23,7 @@ module Vtt2ass
|
|
23
23
|
opts.on("-o", "--output DIRECTORY", "Specify a custom output directory (default: './output')") do |dir|
|
24
24
|
options[:output] = dir
|
25
25
|
end
|
26
|
-
opts.on("-s", "--font-size SIZE", Integer, "Specify a font size for the subtitles (default:
|
26
|
+
opts.on("-s", "--font-size SIZE", Integer, "Specify a font size for the subtitles (default: 52)") do |size|
|
27
27
|
options[:font_size] = size
|
28
28
|
end
|
29
29
|
opts.on("-v", "--version", "Show version") do
|
data/lib/vtt2ass/ASSFile.rb
CHANGED
@@ -9,12 +9,12 @@ class ASSFile
|
|
9
9
|
# * Requires +ass_subs+, a list of ASSSubtitles as input.
|
10
10
|
# * Requires a video +width+ as input.
|
11
11
|
# * Requires a video +height+ as input.
|
12
|
-
def initialize(ass_styles, ass_subs, width, height)
|
12
|
+
def initialize(title, ass_styles, ass_subs, width, height)
|
13
13
|
@width = width
|
14
14
|
@height = height
|
15
15
|
@header = [
|
16
16
|
'[Script Info]',
|
17
|
-
|
17
|
+
"Title: #{title}",
|
18
18
|
'ScriptType: v4.00+',
|
19
19
|
'Collisions: Normal',
|
20
20
|
'PlayDepth: 0',
|
data/lib/vtt2ass/ASSStyle.rb
CHANGED
@@ -15,42 +15,68 @@ class ASSStyle
|
|
15
15
|
@height = height
|
16
16
|
@font_size = font_size
|
17
17
|
@style_name = style_name
|
18
|
-
|
18
|
+
@s_params = StyleParams.new(params, width, height)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# * Requires +params+, a string of VTT styling as input.
|
25
|
-
def assignParams(params)
|
26
|
-
@alignment = "2"
|
27
|
-
@left_margin = "10"
|
28
|
-
@right_margin = "10"
|
29
|
-
@vertical_margin = "50"
|
30
|
-
|
31
|
-
if params.include? "align:middle line:7%" then
|
32
|
-
@style_name = "MainTop"
|
33
|
-
@vertical_margin = "30"
|
34
|
-
@alignment = "8"
|
35
|
-
else
|
36
|
-
param_count = 0
|
21
|
+
class StyleParams
|
22
|
+
attr_reader :horizontal_margin, :vertical_margin, :alignment
|
23
|
+
def initialize(params, width, height)
|
37
24
|
(params.split(' ').map { |p| p.split(':') }).each do |p|
|
38
25
|
case p[0]
|
39
|
-
when
|
40
|
-
@
|
41
|
-
when
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
26
|
+
when 'position'
|
27
|
+
@position = p[1].gsub(/%/, '').to_i
|
28
|
+
when 'line'
|
29
|
+
@line = p[1].gsub(/%/, '').to_i
|
30
|
+
@line = @line == -1 ? 100 : @line;
|
31
|
+
when 'alignment'
|
32
|
+
@align = p[1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
createAlignment
|
36
|
+
createHorizontalMargin(width)
|
37
|
+
createVerticalMargin(height)
|
38
|
+
end
|
39
|
+
def createAlignment
|
40
|
+
if (defined?(@line) and not defined?(@position)) then
|
41
|
+
if (defined?(@align)) then
|
42
|
+
case @align
|
43
|
+
when 'left'
|
44
|
+
when 'start'
|
45
|
+
@alignment = @line >= 50 ? 1 : 7
|
46
|
+
when 'right'
|
47
|
+
when 'end'
|
48
|
+
@alignment = @line >= 50 ? 3 : 9
|
49
|
+
when 'center'
|
50
|
+
when 'middle'
|
51
|
+
@alignment = @line >= 50 ? 2 : 8
|
49
52
|
end
|
50
|
-
|
51
|
-
@
|
53
|
+
else
|
54
|
+
@alignment = @line >= 50 ? 2 : 8 # If position is higher than 50% align to bottom center, else align to top center
|
55
|
+
end
|
56
|
+
elsif (defined?(@line) and defined?(@position)) then
|
57
|
+
@alignment = 1
|
58
|
+
else
|
59
|
+
@alignment = 2
|
60
|
+
end
|
61
|
+
end
|
62
|
+
def createHorizontalMargin(width)
|
63
|
+
steps = (width / 100).to_i
|
64
|
+
if defined?(@position) then
|
65
|
+
@horizontal_margin = @position * steps
|
66
|
+
else
|
67
|
+
@horizontal_margin = 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def createVerticalMargin(height)
|
71
|
+
steps = (height / 100).to_i
|
72
|
+
if defined?(@line) then
|
73
|
+
if (@alignment == 1) then
|
74
|
+
@vertical_margin = (100 - @line) * steps
|
75
|
+
else
|
76
|
+
@vertical_margin = @line >= 50 ? (100 - @line) * steps : @line * steps
|
52
77
|
end
|
53
|
-
|
78
|
+
else
|
79
|
+
@vertical_margin = 50
|
54
80
|
end
|
55
81
|
end
|
56
82
|
end
|
@@ -58,6 +84,6 @@ class ASSStyle
|
|
58
84
|
##
|
59
85
|
# This method assigns the object values to an ASS style line and outputs it.
|
60
86
|
def to_s
|
61
|
-
return "Style: #{@style_name},Open Sans Semibold,#{@font_size},&H00FFFFFF,&H000000FF,&H00020713,&H00000000,-1,0,0,0,100,100,0,0,1,2.0,2.0,#{@alignment},#{@
|
87
|
+
return "Style: #{@style_name},Open Sans Semibold,#{@font_size},&H00FFFFFF,&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"
|
62
88
|
end
|
63
89
|
end
|
data/lib/vtt2ass/Application.rb
CHANGED
@@ -20,7 +20,7 @@ class Application
|
|
20
20
|
@output_dir = options[:output] ? options[:output]: "./output"
|
21
21
|
@width = 1920
|
22
22
|
@height = 1080
|
23
|
-
@font_size = options[:font_size] ? options[:font_size] :
|
23
|
+
@font_size = options[:font_size] ? options[:font_size] : 52
|
24
24
|
end
|
25
25
|
|
26
26
|
##
|
@@ -77,6 +77,6 @@ class Application
|
|
77
77
|
ass_styles.push(ASSStyle.new(sub.style, sub.params, @font_size, @width, @height))
|
78
78
|
end
|
79
79
|
end
|
80
|
-
return ASSFile.new(ass_styles, ass_subs, @width, @height).to_s
|
80
|
+
return ASSFile.new(File.basename(file_path).gsub('.vtt', ''), ass_styles, ass_subs, @width, @height).to_s
|
81
81
|
end
|
82
82
|
end
|
data/lib/vtt2ass/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.2
|
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: 2021-
|
11
|
+
date: 2021-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|