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 +4 -4
- data/Gemfile +2 -0
- data/lib/vtt2ass.rb +98 -34
- data/lib/vtt2ass/Application.rb +10 -2
- data/lib/vtt2ass/VTTLine.rb +2 -0
- data/lib/vtt2ass/version.rb +1 -1
- 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: 64688a982ce477a836bb7ccb206dc6b8055dc9eb264e2062114787a6cbc9b0e4
|
4
|
+
data.tar.gz: 8bca338d3f218d453c316a2676a68960a72fa3c5bd2ae6794d373cbb57412955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca013fd08b2e2317b2be56ae94e71bb63e87dd5909c2662d9e880c22c00dab3903b0a56d01b5b8b737599a5368a4f7387bc2165a844fefd244e17e1ac2291749
|
7
|
+
data.tar.gz: 94e3a884c060141fea32a0fdfad566d745b0d7966dfe508992c8f14709ea869a2f6cc7ff11012a7132fdc5c12368bfd092534f4cf9f8383ef5eefba0f9efb595
|
data/Gemfile
CHANGED
data/lib/vtt2ass.rb
CHANGED
@@ -1,45 +1,109 @@
|
|
1
1
|
# Imports
|
2
|
-
require '
|
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
|
-
|
15
|
-
|
16
|
-
|
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
|
data/lib/vtt2ass/Application.rb
CHANGED
@@ -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
|
-
|
33
|
+
convert(file_path)
|
32
34
|
end
|
33
35
|
elsif File.file?(@input) then
|
34
|
-
|
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.
|
data/lib/vtt2ass/VTTLine.rb
CHANGED
data/lib/vtt2ass/version.rb
CHANGED
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.
|
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-
|
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
|