ehbrs-tools 0.16.0 → 0.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner/videos/probe.rb +3 -3
  3. data/lib/ehbrs/tools/version.rb +1 -1
  4. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  5. data/lib/ehbrs/videos/file.rb +4 -8
  6. data/lib/ehbrs/videos/track.rb +5 -13
  7. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +3 -1
  8. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +3 -1
  9. data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +4 -2
  10. data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +3 -1
  11. data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
  12. data/lib/ehbrs/videos/unsupported/fix_profile.rb +0 -13
  13. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +10 -10
  14. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  15. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  16. data/vendor/aranha-parsers/Gemfile +5 -0
  17. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  18. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  19. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  20. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  21. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  22. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  23. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  24. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  25. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  26. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  27. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  28. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  29. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  30. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  31. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  32. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  33. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  34. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  35. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  36. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  37. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  38. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  39. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  40. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  41. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  42. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  43. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  44. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  45. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  46. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  47. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  48. data/vendor/eac_cli/lib/eac_cli/definition.rb +36 -31
  49. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  50. data/vendor/eac_cli/lib/eac_cli/definition/help_formatter.rb +76 -0
  51. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +15 -2
  52. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  53. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  54. data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
  55. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
  56. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  57. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  58. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  59. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  60. data/vendor/eac_cli/lib/eac_cli/runner.rb +12 -4
  61. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  62. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
  63. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  64. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +6 -1
  65. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  66. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  67. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +10 -0
  68. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  69. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +17 -5
  70. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  71. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  72. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +29 -1
  73. data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
  74. data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
  75. data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
  76. data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
  77. data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
  78. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
  79. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
  80. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
  81. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +4 -69
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +7 -2
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  94. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
  96. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  97. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/basename_sub.rb +2 -2
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +7 -1
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  102. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  103. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  104. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
  105. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  106. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  107. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  108. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  109. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  110. metadata +92 -13
  111. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +0 -127
  112. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -38
  113. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -77
  114. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  115. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ module Envs
5
+ class Command
6
+ module Envvars
7
+ def envvar(name, value)
8
+ duplicate_by_extra_options(envvars: envvars.merge(name => value))
9
+ end
10
+
11
+ private
12
+
13
+ def append_envvars(command)
14
+ e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
15
+ e.present? ? "#{e} #{command}" : command
16
+ end
17
+
18
+ def envvars
19
+ extra_options[:envvars] ||= {}.with_indifferent_access
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -12,39 +12,18 @@ module EacRubyUtils
12
12
  duplicate_by_extra_options(chdir: dir)
13
13
  end
14
14
 
15
- def envvar(name, value)
16
- duplicate_by_extra_options(envvars: envvars.merge(name => value))
17
- end
18
-
19
15
  def status_result(status_code, result)
20
16
  duplicate_by_extra_options(status_results: status_results.merge(status_code => result))
21
17
  end
22
18
 
23
- def pipe(other_command)
24
- duplicate_by_extra_options(pipe: other_command)
25
- end
26
-
27
19
  private
28
20
 
29
21
  attr_reader :extra_options
30
22
 
31
- def envvars
32
- extra_options[:envvars] ||= {}.with_indifferent_access
33
- end
34
-
35
23
  def status_results
36
24
  extra_options[:status_results] ||= {}.with_indifferent_access
37
25
  end
38
26
 
39
- def append_envvars(command)
40
- e = envvars.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(' ')
41
- e.present? ? "#{e} #{command}" : command
42
- end
43
-
44
- def append_pipe(command)
45
- extra_options[:pipe].present? ? "#{command} | #{extra_options[:pipe].command}" : command
46
- end
47
-
48
27
  def append_chdir(command)
49
28
  extra_options[:chdir].present? ? "(cd '#{extra_options[:chdir]}' ; #{command} )" : command
50
29
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/abstract_methods'
4
+
5
+ class Module
6
+ def enable_abstract_methods(*methods)
7
+ include ::EacRubyUtils::AbstractMethods
8
+ abstract_methods(*methods)
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ def print_debug
5
+ STDERR.write(to_debug + "\n")
6
+
7
+ self
8
+ end
9
+
10
+ def to_debug
11
+ "|#{self.class}|#{self}|"
12
+ end
13
+
14
+ def raise_debug
15
+ raise to_debug
16
+ end
17
+ end
@@ -3,7 +3,7 @@
3
3
  require 'pathname'
4
4
 
5
5
  class Pathname
6
- def basename_sub
7
- parent.join(yield(basename))
6
+ def basename_sub(suffix = '')
7
+ parent.join(yield(basename(suffix)))
8
8
  end
9
9
  end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/hash_with_indifferent_access'
4
+ require 'active_support/core_ext/module/delegation'
4
5
  require 'active_support/core_ext/object/blank'
5
6
 
6
7
  module EacRubyUtils
7
8
  class Struct
8
9
  def initialize(initial_data = {})
9
- self.data = ::ActiveSupport::HashWithIndifferentAccess.new(initial_data)
10
+ self.data = initial_data.symbolize_keys
10
11
  end
11
12
 
12
13
  def [](key)
@@ -19,6 +20,11 @@ module EacRubyUtils
19
20
  bool ? fetch(key).present? : data.fetch(key)
20
21
  end
21
22
 
23
+ def merge(other)
24
+ other = self.class.new(other) unless other.is_a?(self.class)
25
+ self.class.new(to_h.merge(other.to_h))
26
+ end
27
+
22
28
  def method_missing(method_name, *arguments, &block)
23
29
  property_method?(method_name) ? fetch(method_name) : super
24
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.50.0'
4
+ VERSION = '0.56.0'
5
5
  end
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
3
4
  require 'yaml'
4
5
 
5
6
  module EacRubyUtils
6
7
  # A safe YAML loader/dumper with common types included.
7
8
  class Yaml
8
9
  class << self
9
- DEFAULT_PERMITTED_CLASSES = [::Array, ::Date, ::FalseClass, ::Hash, ::NilClass, ::Numeric,
10
- ::String, ::Symbol, ::Time, ::TrueClass].freeze
10
+ DEFAULT_PERMITTED_CLASSES = [::Array, ::Date, ::DateTime, ::FalseClass, ::Hash, ::NilClass,
11
+ ::Numeric, ::String, ::Symbol, ::Time, ::TrueClass].freeze
11
12
 
12
13
  def dump(object)
13
14
  ::YAML.dump(sanitize(object))
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/abstract_methods'
4
+
5
+ RSpec.describe(::EacRubyUtils::AbstractMethods) do
6
+ let(:base_class) do
7
+ the_module = described_class
8
+ ::Class.new do
9
+ include the_module
10
+
11
+ abstract_methods :method1, :method2
12
+ end
13
+ end
14
+ let(:base_instance) { base_class.new }
15
+ let(:sub_class) do
16
+ ::Class.new(base_class) do
17
+ def method1
18
+ 'a result'
19
+ end
20
+ end
21
+ end
22
+ let(:sub_instance) { sub_class.new }
23
+
24
+ it { expect { base_instance.method1 }.to raise_error(::NoMethodError) }
25
+ it { expect { base_instance.method2 }.to raise_error(::NoMethodError) }
26
+ it { expect(sub_instance.method1).to eq('a result') }
27
+ it { expect { sub_instance.method2 }.to raise_error(::NoMethodError) }
28
+ end
@@ -9,34 +9,47 @@ RSpec.describe ::EacRubyUtils::CommonConcern do
9
9
  end
10
10
  end
11
11
 
12
- module MyModule
13
- module ClassMethods
14
- def my_class_method
15
- 'class'
12
+ let(:stub_module) do
13
+ ::Module.new do
14
+ module ClassMethods # rubocop:disable RSpec/LeakyConstantDeclaration
15
+ def my_class_method
16
+ 'class'
17
+ end
16
18
  end
17
- end
18
19
 
19
- module InstanceMethods
20
- def my_instance_method
21
- 'instance'
20
+ module InstanceMethods # rubocop:disable RSpec/LeakyConstantDeclaration
21
+ def my_instance_method
22
+ 'instance'
23
+ end
22
24
  end
23
25
  end
24
26
  end
25
27
 
26
- class MyClass
27
- class << self
28
- attr_accessor :valor
28
+ let(:stub_class) do
29
+ ::Class.new do
30
+ class << self
31
+ attr_accessor :valor
32
+ end
33
+
34
+ def method1
35
+ 'from_stub_module'
36
+ end
29
37
  end
30
38
  end
31
39
 
32
- let(:subject) { MyClass.new }
40
+ let(:stub_class_instance) { stub_class.new }
33
41
 
34
42
  before do
35
- instance.setup(MyModule)
36
- MyClass.include MyModule
43
+ instance.setup(stub_module)
37
44
  end
38
45
 
39
- it { expect(subject.my_instance_method).to eq('instance') }
40
- it { expect(subject.class.my_class_method).to eq('class') }
41
- it { expect(subject.class.valor).to eq('changed') }
46
+ context 'when included' do
47
+ before do
48
+ stub_class.include stub_module
49
+ end
50
+
51
+ it { expect(stub_class_instance.my_instance_method).to eq('instance') }
52
+ it { expect(stub_class_instance.class.my_class_method).to eq('class') }
53
+ it { expect(stub_class_instance.class.valor).to eq('changed') }
54
+ end
42
55
  end
@@ -3,34 +3,92 @@
3
3
  require 'eac_ruby_utils/common_constructor'
4
4
 
5
5
  RSpec.describe ::EacRubyUtils::CommonConstructor do
6
- ARG_LIST = %i[a b c d].freeze
6
+ ARG_LIST = %i[a b c d].freeze # rubocop:disable RSpec/LeakyConstantDeclaration
7
+
7
8
  let(:instance) do
8
9
  described_class.new(*ARG_LIST, default: %w[Vcc Vd]) do
9
10
  @z = 'Vz'
10
11
  end
11
12
  end
12
13
 
13
- class MyClass
14
- attr_reader :z
14
+ let(:a_class) do
15
+ ::Class.new do
16
+ attr_reader :z
17
+ end
15
18
  end
16
19
 
17
- let(:subject) { MyClass.new('Va', 'Vb', 'Vc') }
20
+ let(:a_class_instance) { a_class.new('Va', 'Vb', 'Vc') }
18
21
 
19
22
  before do
20
- instance.setup_class(::MyClass)
23
+ instance.setup_class(a_class)
21
24
  end
22
25
 
23
- it { expect(subject.z).to eq('Vz') }
26
+ it { expect(a_class_instance.z).to eq('Vz') }
24
27
 
25
28
  ARG_LIST.each do |attr|
26
29
  expected_value = "V#{attr}"
27
30
  it "attribute \"#{attr}\" equal to \"#{expected_value}\"" do
28
- expect(subject.send(attr)).to eq(expected_value)
31
+ expect(a_class_instance.send(attr)).to eq(expected_value)
29
32
  end
30
33
 
31
34
  [false, true].each do |include_all|
32
35
  it "respond_to?('#{attr}', #{include_all}) == #{include_all}" do
33
- expect(subject.respond_to?("#{attr}=", include_all)).to eq(include_all)
36
+ expect(a_class_instance.respond_to?("#{attr}=", include_all)).to eq(include_all)
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'with super class' do
42
+ let(:super_class) do
43
+ ::Class.new do
44
+ attr_reader :super_a, :super_b
45
+
46
+ def initialize(a, b) # rubocop:disable Naming/MethodParameterName
47
+ @super_a = a
48
+ @super_b = b
49
+ end
50
+ end
51
+ end
52
+
53
+ let(:sub_class) do
54
+ sub_constructor.setup_class(::Class.new(super_class))
55
+ end
56
+
57
+ let(:sub_object) { sub_class.new(1, 2, 3, 4) }
58
+
59
+ context 'with super_args parameter' do
60
+ let(:sub_constructor) do
61
+ described_class.new(:c, :a, :b, :d, super_args: -> { [c, a] })
62
+ end
63
+
64
+ it { expect(sub_object.a).to eq(2) }
65
+ it { expect(sub_object.b).to eq(3) }
66
+ it { expect(sub_object.c).to eq(1) }
67
+ it { expect(sub_object.d).to eq(4) }
68
+ it { expect(sub_object.super_a).to eq(1) }
69
+ it { expect(sub_object.super_b).to eq(2) }
70
+ end
71
+
72
+ context 'without super_args parameter' do
73
+ let(:sub_constructor) do
74
+ described_class.new(:c, :a, :b, :d)
75
+ end
76
+
77
+ it { expect(sub_object.a).to eq(2) }
78
+ it { expect(sub_object.b).to eq(3) }
79
+ it { expect(sub_object.c).to eq(1) }
80
+ it { expect(sub_object.d).to eq(4) }
81
+ it { expect(sub_object.super_a).to eq(2) }
82
+ it { expect(sub_object.super_b).to eq(3) }
83
+ end
84
+
85
+ context 'with undefined super arguments' do
86
+ let(:sub_constructor) do
87
+ described_class.new(:x, :y, :w, :a)
88
+ end
89
+
90
+ it do
91
+ expect { sub_object }.to raise_error(::ArgumentError)
34
92
  end
35
93
  end
36
94
  end
@@ -3,7 +3,8 @@
3
3
  require 'eac_ruby_utils/struct'
4
4
 
5
5
  RSpec.describe ::EacRubyUtils::Struct do
6
- let(:instance) { described_class.new(a: 1, b: '') }
6
+ let(:instance) { described_class.new('a' => 1, b: '') }
7
+ let(:other) { described_class.new('a' => 'm1', c: 'm2') }
7
8
 
8
9
  describe '#[]' do
9
10
  it { expect(instance[:a]).to eq(1) }
@@ -35,6 +36,12 @@ RSpec.describe ::EacRubyUtils::Struct do
35
36
  it { expect { instance.fetch('c?') }.to raise_error(::KeyError) }
36
37
  end
37
38
 
39
+ describe '#merge' do
40
+ let(:merged) { instance.merge(other) }
41
+
42
+ it { expect(merged.to_h).to eq(a: 'm1', b: '', c: 'm2') }
43
+ end
44
+
38
45
  describe '#property_method' do
39
46
  it { expect(instance.a).to eq(1) }
40
47
  it { expect(instance.a?).to eq(true) }
@@ -43,4 +50,8 @@ RSpec.describe ::EacRubyUtils::Struct do
43
50
  it { expect { instance.c }.to raise_error(::NoMethodError) }
44
51
  it { expect { instance.c? }.to raise_error(::NoMethodError) }
45
52
  end
53
+
54
+ describe '#to_h' do
55
+ it { expect(instance.to_h).to eq(a: 1, b: '') }
56
+ end
46
57
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.3.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -1,11 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/executables'
5
+ require 'ehbrs_ruby_utils/videos/stream'
6
+ require 'json'
4
7
 
5
8
  module EhbrsRubyUtils
6
9
  module Videos
7
- module Container
8
- require_sub __FILE__
10
+ class Container
11
+ enable_simple_cache
12
+ common_constructor :path do
13
+ self.path = path.to_pathname
14
+ end
15
+
16
+ ::EhbrsRubyUtils::Videos::Stream.lists.codec_type.each_value do |stream_type|
17
+ define_method stream_type.to_s.pluralize do
18
+ streams.select { |stream| stream.codec_type == stream_type }
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def probe_data_uncached
25
+ ::JSON.parse(
26
+ ::EhbrsRubyUtils::Executables.ffprobe.command(
27
+ '-hide_banner', '-print_format', 'json', '-show_format', '-show_streams', path
28
+ ).execute!
29
+ ).deep_symbolize_keys.freeze
30
+ end
31
+
32
+ def streams_uncached
33
+ probe_data.fetch(:streams).map do |stream_ffprobe_data|
34
+ ::EhbrsRubyUtils::Videos::Stream.new(stream_ffprobe_data)
35
+ end
36
+ end
9
37
  end
10
38
  end
11
39
  end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs/executables'
5
+ require 'fileutils'
6
+
7
+ module EhbrsRubyUtils
8
+ module Videos
9
+ class ConvertJob
10
+ FORMATS_TO_EXTENSIONS = {
11
+ 'matroska' => '.mkv'
12
+ }.freeze
13
+
14
+ enable_console_speaker
15
+ enable_simple_cache
16
+ common_constructor :input, :ffmpeg_convert_args do
17
+ self.input = input.to_pathname.expand_path
18
+ raise "Input file \"#{input}\" does not exist or is not a file" unless input.file?
19
+ end
20
+
21
+ def run
22
+ if converted.exist?
23
+ warn("Converted file already exist: \"#{converted}\"")
24
+ else
25
+ convert
26
+ swap
27
+ end
28
+ end
29
+
30
+ def target
31
+ input.dirname.join("#{input.basename('.*')}#{target_extension}")
32
+ end
33
+
34
+ private
35
+
36
+ def command_args_uncached
37
+ r = ['-i', input] + ffmpeg_convert_args
38
+ r += ['-f', format_by_input] if format_by_args.blank?
39
+ r + [converting]
40
+ end
41
+
42
+ def convert
43
+ infov 'Input', input
44
+ infov 'Target', target
45
+ infov 'Convert args', command_args.shelljoin
46
+ ::Ehbrs::Executables.ffmpeg.command.append(command_args).system!
47
+ end
48
+
49
+ def format_by_args_uncached
50
+ ffmpeg_convert_args.rindex('-f').if_present do |option_index|
51
+ ffmpeg_convert_args[option_index + 1]
52
+ end
53
+ end
54
+
55
+ def format_by_input
56
+ FORMATS_TO_EXTENSIONS.invert[target_extension_by_input].if_present { |v| return v }
57
+
58
+ raise 'Unknonwn target format'
59
+ end
60
+
61
+ def format_to_extension(format)
62
+ FORMATS_TO_EXTENSIONS[format].if_present(".#{format}")
63
+ end
64
+
65
+ def swap
66
+ ::FileUtils.mv(input, converted)
67
+ ::FileUtils.mv(converting, target)
68
+ end
69
+
70
+ def converting
71
+ target.basename_sub { |b| "#{b}.converting" }
72
+ end
73
+
74
+ def converted
75
+ input.basename_sub { |b| "#{b}.converted" }
76
+ end
77
+
78
+ def target_extension
79
+ target_extension_by_args || target_extension_by_input
80
+ end
81
+
82
+ def target_extension_by_args
83
+ format_by_args.if_present { |v| format_to_extension(v) }
84
+ end
85
+
86
+ def target_extension_by_input
87
+ ::File.extname(input)
88
+ end
89
+ end
90
+ end
91
+ end