vtt2ass 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b13c0f4e714b058d076bddda1685ba4007429a2c9c0dc065073926bee9dd2dad
4
- data.tar.gz: acbfd744b30cd214f174ec4fe991a6983cb206b89a65956115be803cf005b22c
3
+ metadata.gz: 5b8d61e8c97eae4983b1b8b3011817d8ceaf12381a60c5ba3dfbf51e5c84ffc7
4
+ data.tar.gz: a2777f056b947249330e7f4b828172eb5e9f90d11939fcfa44c9213a5d2ac86e
5
5
  SHA512:
6
- metadata.gz: 99c2d00e1d03c7e8ae463266ea500ad0ebf10f0b7eeae972b4d2776887a1a0936f5707633832c26fc6bc66fdd13e0bd53ff73200c2f5ae128517266a29d46a31
7
- data.tar.gz: 17d541540f391fe95e5aeea3d0795ee36b5856f1cc6d69de4bcf6ac59b7a647e1cc3509e57b291a80c0a753b058a01d291944e435a9dd917358a99c5f69ed574
6
+ metadata.gz: e5c15a86a9706ea9a521ee6e719cdeb2d99e7b394df7800bd6862385e20cc8b779e63a0929b6ddf700f742b48cb07a258f01e7eda5256732331be7bc7f879995
7
+ data.tar.gz: 1b6a6da137d123e0aeca34963d8dcc1aeacc437666f1f277efe12d9747f83edc16add7ab399030017d57901d04bfceed7ac3e0caaecff10c6042577265ef03dc
data/.gitignore CHANGED
@@ -1,6 +1,9 @@
1
1
  # Lock file
2
2
  Gemfile.lock
3
3
 
4
+ # gems
5
+ /*.gem
6
+
4
7
  # Temporary files for yard documentation
5
8
  .yardoc/
6
9
 
data/.gitlab-ci.yml CHANGED
@@ -14,18 +14,16 @@ test:
14
14
  build:
15
15
  stage: build
16
16
  only:
17
- - master
17
+ - develop
18
18
  artifacts:
19
19
  untracked: true
20
20
  script:
21
- - mkdir build
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 push build/release.gem -k rubygems_b54a36e70dba06b9a9c7268807eb2bbb896cdba924c67289
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: 72)
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: 72)") do |size|
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
@@ -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
- 'Title: DKB Team',
17
+ "Title: #{title}",
18
18
  'ScriptType: v4.00+',
19
19
  'Collisions: Normal',
20
20
  'PlayDepth: 0',
@@ -15,42 +15,68 @@ class ASSStyle
15
15
  @height = height
16
16
  @font_size = font_size
17
17
  @style_name = style_name
18
- assignParams(params)
18
+ @s_params = StyleParams.new(params, width, height)
19
19
  end
20
20
 
21
- ##
22
- # This method converts the string of VTT styling in values used for ASS styling.
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 "position"
40
- @left_margin = (@width * ((p[1].gsub(/%/, '').to_f - 7) / 100)).to_i.to_s
41
- when "align"
42
- case p[1]
43
- when "left"
44
- @alignment = 1
45
- when "middle"
46
- @alignment = 2
47
- when "right"
48
- @alignment = 3
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
- when "line"
51
- @vertical_margin = (@height - (@height * ((p[1].gsub(/%/, '').to_f + 7) / 100))).to_i.to_s
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
- param_count += 1
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},#{@left_margin},#{@right_margin},#{@vertical_margin},1"
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
@@ -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] : 72
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
@@ -1,3 +1,3 @@
1
1
  module Vtt2ass
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.2.1
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-01-16 00:00:00.000000000 Z
11
+ date: 2021-02-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: