vtt2ass 0.2.12 → 0.2.13

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: 41589b113a0b7b9e79ca957027d7ffdcadc4878a3a58c6ac679de1fb381cb020
4
- data.tar.gz: 99f4dc6156626c91fce3c9fa2c8a995022eb420593bc0c59fe85a34999cf89c8
3
+ metadata.gz: 64688a982ce477a836bb7ccb206dc6b8055dc9eb264e2062114787a6cbc9b0e4
4
+ data.tar.gz: 8bca338d3f218d453c316a2676a68960a72fa3c5bd2ae6794d373cbb57412955
5
5
  SHA512:
6
- metadata.gz: 2f28df173df92ac71c61565e8f5dcc3c1eda7caf54ef9a8aa1f7a8333bfc8d96e27af5850d5a4356f99c7d5d5c41db373a334c201a085515d2f1d3b71b409b3c
7
- data.tar.gz: 2f5390f9f5bf8ae5d74a7ef0564f57ce3b93fe830cd282eaf3f4cc26211a5258b5475854b8e01975e9edf4f9b7cb8b97b3784b928de9ae1ca5d3e761a27e0685
6
+ metadata.gz: ca013fd08b2e2317b2be56ae94e71bb63e87dd5909c2662d9e880c22c00dab3903b0a56d01b5b8b737599a5368a4f7387bc2165a844fefd244e17e1ac2291749
7
+ data.tar.gz: 94e3a884c060141fea32a0fdfad566d745b0d7966dfe508992c8f14709ea869a2f6cc7ff11012a7132fdc5c12368bfd092534f4cf9f8383ef5eefba0f9efb595
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'htmlentities', '~> 4.3'
7
+ gem 'tty-option', '~> 0.1'
8
+
7
9
  gem 'yard', '~> 0.9'
8
10
  gem 'rake', '~> 12.0'
9
11
  gem 'minitest', '~> 5.0'
data/lib/vtt2ass.rb CHANGED
@@ -1,45 +1,109 @@
1
1
  # Imports
2
- require 'optparse'
2
+ require 'tty-option'
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."
71
+ end
72
+
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)"
78
+ end
79
+
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')"
85
+ 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
+
8
102
  module Vtt2ass
9
- ##
10
- # This function creates a new application instance and starts the process.
11
- #
12
- # It also defines the arguments that can be provided from the CLI.
13
103
  def main
14
- options = {}
15
-
16
- OptionParser.new do |opts|
17
- opts.banner = "Usage: vtt2ass [options]"
18
- opts.separator ""
19
- opts.separator "Specific options:"
20
- opts.on("-i", "--input PATH", "Specify a custom input file or directory (default: './')") do |file_path|
21
- options[:input] = file_path
22
- end
23
- opts.on("-o", "--output PATH", "Specify a custom output directory (default: './')") do |file_path|
24
- options[:output] = file_path
25
- end
26
- opts.on("-f", "--font-family FONT", String, "Specify a font family for the subtitles (default: 'Open Sans Semibold')") do |font_family|
27
- options[:font_family] = font_family
28
- end
29
- opts.on("-s", "--font-size SIZE", Integer, "Specify a font size for the subtitles (default: 52)") do |font_size|
30
- options[:font_size] = font_size
31
- end
32
- opts.on("-t", "--title TITLE", String, "Specify a title for you file. If the input is a directory, all files will share the same title.") do |title|
33
- options[:title] = title
34
- end
35
- opts.on("-v", "--version", "Show version") do
36
- puts Vtt2ass::VERSION
37
- exit
38
- end
39
- end.parse!
40
-
41
- app = Application.new(options)
42
- app.start
104
+ app = Command.new
105
+ app.parse
106
+ app.run
43
107
  end
44
108
 
45
109
  module_function :main
@@ -19,6 +19,8 @@ class Application
19
19
  if options[:title] then
20
20
  @title = options[:title]
21
21
  end
22
+ @quiet = options[:quiet]
23
+ @noout = options[:noout]
22
24
  end
23
25
 
24
26
  ##
@@ -28,15 +30,21 @@ class Application
28
30
  def start
29
31
  if File.directory?(@input) then
30
32
  Dir["#{@input}/*.vtt"].each do |file_path|
31
- vtt_to_ass(file_path).writeToFile(@output + '/' + File.basename(file_path).gsub('.vtt', '.ass'))
33
+ convert(file_path)
32
34
  end
33
35
  elsif File.file?(@input) then
34
- vtt_to_ass(@input).writeToFile(@output + '/' + File.basename(@input).gsub('.vtt', '.ass'))
36
+ convert(@input)
35
37
  else
36
38
  puts 'Error: input file or directory does not exist.'
37
39
  end
38
40
  end
39
41
 
42
+ def convert(input_path)
43
+ ass_file = vtt_to_ass(input_path)
44
+ ass_file.writeToFile(@output + '/' + File.basename(input_path).gsub('.vtt', '.ass')) unless @noout
45
+ puts ass_file.to_s unless @quiet
46
+ end
47
+
40
48
  ##
41
49
  # This method creates a new VTTFile object from the file path provided and convert its content
42
50
  # inside a new ASSFile object.
@@ -31,6 +31,8 @@ class VTTLine
31
31
  end
32
32
  count += 1;
33
33
  end
34
+
35
+ @text = @text.lstrip
34
36
  end
35
37
 
36
38
  ##
@@ -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.12"
7
+ VERSION = "0.2.13"
8
8
  end
data/vtt2ass.gemspec CHANGED
@@ -26,6 +26,7 @@ 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
30
 
30
31
  spec.add_development_dependency 'rake', '~> 12.0'
31
32
  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.12
4
+ version: 0.2.13
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-04-19 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlentities
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-option
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement