vtt2ass 0.2.13 → 0.3.1

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.
@@ -0,0 +1,22 @@
1
+ class CSSRule
2
+ attr_reader :name, :properties
3
+
4
+ def initialize(selector, declarations)
5
+ @name = reduce_selector(selector)
6
+ @properties = []
7
+ declarations.split(/;\s?/).each do |dec|
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
@@ -13,10 +13,18 @@ class VTTFile
13
13
  @lines = []
14
14
  separator = determine_line_ending(file_path) ? "\n\n" : "\r\n\r\n"
15
15
  count = 0
16
+ style_count = 1
16
17
  File.foreach(file_path, separator) do |paragraph|
17
18
  paragraph = paragraph.rstrip.gsub(/[\r\n]/, "\n")
18
19
  if not paragraph.eql? "" then
19
20
  vtt_line = VTTLine.new(paragraph, width, height)
21
+ if vtt_line.style.eql? 'Main' and
22
+ not vtt_line.params.to_s.empty? and
23
+ (not vtt_line.params.to_s.eql? 'align:middle' and
24
+ not vtt_line.params.to_s.eql? 'align:center') then
25
+ vtt_line.style = "Style#{style_count}"
26
+ style_count += 1
27
+ end
20
28
  @lines.push(vtt_line)
21
29
  count += 1
22
30
  end
@@ -24,6 +32,8 @@ class VTTFile
24
32
  @lines.shift
25
33
  end
26
34
 
35
+ ##
36
+ # This method determines the line ending character to use as a separator.
27
37
  def determine_line_ending(file_path)
28
38
  File.open(file_path, 'r') do |file|
29
39
  return file.readline[/\r?\n$/] == "\n"
@@ -1,7 +1,8 @@
1
1
  ##
2
2
  # This class defines a VTT subtile line.
3
3
  class VTTLine
4
- attr_reader :style, :time_start, :time_end, :params, :text
4
+ attr_accessor :style
5
+ attr_reader :time_start, :time_end, :params, :text
5
6
 
6
7
  ##
7
8
  # This method creates an instance of an VTTLine.
@@ -24,7 +25,7 @@ class VTTLine
24
25
  @params = m[3]
25
26
  ass_style = ASSStyleParams.new(@params, width, height)
26
27
  if @style.eql? 'Main' and ass_style.alignment == 8 then
27
- @style = "MainTop"
28
+ @style = 'MainTop'
28
29
  end
29
30
  else
30
31
  @text += line + "\n"
@@ -0,0 +1,10 @@
1
+ class Validator
2
+ def self.hex?(value)
3
+ hex = true
4
+ value.gsub!('#', '')
5
+ value.chars.each do |digit|
6
+ hex = false unless digit.match(/\h/)
7
+ end
8
+ return hex
9
+ end
10
+ end
@@ -4,5 +4,5 @@ module Vtt2ass
4
4
  ##
5
5
  # This is the version of the application.
6
6
  # This needs to be changed for each gem release.
7
- VERSION = "0.2.13"
7
+ VERSION = "0.3.1"
8
8
  end
data/lib/vtt2ass.rb CHANGED
@@ -1,110 +1,29 @@
1
1
  # Imports
2
- require 'tty-option'
2
+ require 'thor'
3
3
 
4
4
  # Relative imports
5
5
  require_relative 'vtt2ass/version'
6
6
  require_relative 'vtt2ass/Application'
7
7
 
8
- class Command
9
- include TTY::Option
10
-
11
- usage do
12
- header 'VTT2ASS'
13
- program 'vtt2ass'
14
- command ''
15
- desc 'Convert VTT subtitles to ASS subtitles'
16
- example "Convert files in a specific directory",
17
- " $ vtt2ass ./path/to/file_input ./path/to/file_output"
18
- end
19
-
20
- # ------------------------------
21
- # Arguments
22
- # ------------------------------
23
-
24
- argument :input do
25
- optional
26
- desc "Input directory or file (default: current directory)"
27
- end
28
-
29
- argument :output do
30
- optional
31
- desc "Output directory (default: console output)"
32
- end
33
-
34
- # ------------------------------
35
- # Flags
36
- # ------------------------------
37
-
38
- flag :help do
39
- short "-h"
40
- long "--help"
41
- desc "Print usage"
42
- end
43
-
44
- flag :version do
45
- short "-v"
46
- long "--version"
47
- desc "Show version"
48
- end
49
-
50
- flag :quiet do
51
- short "-q"
52
- long "--quiet"
53
- desc "Prevent the command from outputing to the console"
54
- end
55
-
56
- flag :noout do
57
- short "-x"
58
- long "--noout"
59
- desc "Prevents the command from writing the resulting file(s) to the output folder"
60
- end
61
-
62
- # ------------------------------
63
- # Options
64
- # ------------------------------
65
-
66
- option :title do
67
- optional
68
- short "-t STRING"
69
- long "--title STRING"
70
- desc "Specify a title for you file. If the input is a directory, all files will share the same title."
8
+ class MainCommand < Thor
9
+ def self.exit_on_failure?
10
+ true
71
11
  end
72
12
 
73
- option :font_size do
74
- optional
75
- short "-s INTEGER"
76
- long "--font-size INTEGER"
77
- desc "Specify a font size for the subtitles (default: 52)"
13
+ desc 'convert INPUT', 'Run the VTT to ASS conversion for the specified file(s)'
14
+ method_option :output, :aliases => '-o', :desc => 'Output directory of the converted file' , :lazy_default => './', :type => :string
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
+ method_option :font_size, :aliases => '-s', :desc => 'Specify a font size for the subtitles', :default => 52, :type => :numeric
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
19
+ method_option :quiet, :aliases => '-q', :desc => 'Don\'t output to the console', :type => :boolean
20
+ def convert(input)
21
+ app = Application.new(input, options)
22
+ app.start
78
23
  end
79
24
 
80
- option :font_family do
81
- optional
82
- short "-f STRING"
83
- long "--font-family STRING"
84
- desc "Specify a font family for the subtitles (default: 'Open Sans Semibold')"
25
+ desc 'version', 'Show version'
26
+ def version
27
+ puts Vtt2ass::VERSION
85
28
  end
86
-
87
- def run
88
- if params[:help] then
89
- print help
90
- exit
91
- elsif params[:version] then
92
- puts Vtt2ass::VERSION
93
- exit
94
- else
95
- runner = Application.new(params)
96
- # pp params.to_h
97
- runner.start
98
- end
99
- end
100
- end
101
-
102
- module Vtt2ass
103
- def main
104
- app = Command.new
105
- app.parse
106
- app.run
107
- end
108
-
109
- module_function :main
110
29
  end
data/vtt2ass.gemspec CHANGED
@@ -26,7 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_dependency 'htmlentities', '~> 4.3'
29
- spec.add_dependency 'tty-option', '~> 0.1'
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.2.13
4
+ version: 0.3.1
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-05-30 00:00:00.000000000 Z
11
+ date: 2022-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -25,19 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: tty-option
28
+ name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: '1.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.1'
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
@@ -94,14 +122,16 @@ files:
94
122
  - LICENSE.txt
95
123
  - README.md
96
124
  - Rakefile
97
- - bin/run
98
125
  - bin/setup
126
+ - bin/vtt2ass
99
127
  - doc/ASSFile.html
100
128
  - doc/ASSLine.html
101
129
  - doc/ASSStyle.html
102
130
  - doc/ASSStyleParams.html
103
131
  - doc/ASSSubtitle.html
104
132
  - doc/Application.html
133
+ - doc/Command.html
134
+ - doc/MainCommand.html
105
135
  - doc/VTTFile.html
106
136
  - doc/VTTLine.html
107
137
  - doc/VTTSubtitle.html
@@ -128,8 +158,11 @@ files:
128
158
  - lib/vtt2ass/ASSStyle.rb
129
159
  - lib/vtt2ass/ASSStyleParams.rb
130
160
  - lib/vtt2ass/Application.rb
161
+ - lib/vtt2ass/CSSFile.rb
162
+ - lib/vtt2ass/CSSRule.rb
131
163
  - lib/vtt2ass/VTTFile.rb
132
164
  - lib/vtt2ass/VTTLine.rb
165
+ - lib/vtt2ass/Validator.rb
133
166
  - lib/vtt2ass/version.rb
134
167
  - vtt2ass.gemspec
135
168
  homepage: https://gitlab.com/dkb-weeblets/vtt2ass