ehbrs-tools 0.15.0 → 0.16.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/runner.rb +4 -7
  3. data/lib/ehbrs/runner/finances.rb +4 -7
  4. data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
  5. data/lib/ehbrs/runner/fs.rb +4 -7
  6. data/lib/ehbrs/runner/fs/used_space.rb +4 -5
  7. data/lib/ehbrs/runner/google.rb +4 -7
  8. data/lib/ehbrs/runner/google/translate.rb +7 -12
  9. data/lib/ehbrs/runner/self.rb +4 -7
  10. data/lib/ehbrs/runner/self/test.rb +5 -10
  11. data/lib/ehbrs/runner/vg.rb +4 -7
  12. data/lib/ehbrs/runner/vg/ips.rb +9 -14
  13. data/lib/ehbrs/runner/vg/wii.rb +10 -13
  14. data/lib/ehbrs/runner/videos.rb +3 -5
  15. data/lib/ehbrs/runner/videos/extract.rb +10 -13
  16. data/lib/ehbrs/runner/videos/probe.rb +6 -9
  17. data/lib/ehbrs/runner/videos/series.rb +5 -8
  18. data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
  19. data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
  20. data/lib/ehbrs/runner/web_utils.rb +5 -7
  21. data/lib/ehbrs/runner/web_utils/videos.rb +4 -6
  22. data/lib/ehbrs/runner/web_utils/videos/download.rb +8 -11
  23. data/lib/ehbrs/runner/web_utils/videos/upload.rb +8 -11
  24. data/lib/ehbrs/tools/version.rb +1 -1
  25. data/lib/ehbrs/vg/wii/wit/parsers/dump.rb +10 -5
  26. data/lib/ehbrs/videos/file.rb +4 -8
  27. data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
  28. data/lib/ehbrs/videos/track.rb +20 -10
  29. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unlisted.rb +2 -0
  30. data/lib/ehbrs/videos/unsupported/checks/codec_extra_unsupported.rb +2 -0
  31. data/lib/ehbrs/videos/unsupported/checks/codec_unlisted.rb +2 -0
  32. data/lib/ehbrs/videos/unsupported/checks/codec_unsupported.rb +2 -0
  33. data/lib/ehbrs/videos/unsupported/checks/invalid_extension.rb +2 -0
  34. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
  35. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  36. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  37. data/vendor/aranha-parsers/Gemfile +5 -0
  38. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  39. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  40. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  41. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  42. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  43. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  44. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  45. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  46. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  47. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  48. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  49. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  50. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  51. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  52. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  53. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  54. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  55. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  56. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  57. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  58. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  59. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  60. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  61. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  62. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  63. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  64. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  65. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  66. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  67. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  68. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  69. data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
  70. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  71. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  72. data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
  73. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  74. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  75. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  76. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  77. data/vendor/eac_cli/lib/eac_cli/parser.rb +23 -3
  78. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +92 -0
  79. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  80. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  81. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  82. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  83. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  84. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  85. data/vendor/eac_cli/lib/eac_cli/runner.rb +17 -5
  86. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
  87. data/vendor/eac_cli/lib/eac_cli/runner/exit.rb +13 -0
  88. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +18 -1
  89. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +5 -1
  90. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +101 -0
  91. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  92. data/vendor/eac_cli/spec/lib/eac_cli/definition/alternative_spec.rb +14 -0
  93. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +35 -0
  94. data/vendor/eac_cli/spec/lib/eac_cli/parser/alternative_spec.rb +140 -0
  95. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +59 -39
  96. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/help_spec.rb +42 -0
  97. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  98. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +85 -0
  99. data/vendor/eac_docker/lib/eac_docker/container.rb +24 -0
  100. data/vendor/eac_docker/lib/eac_docker/images/coded.rb +39 -0
  101. data/vendor/eac_docker/lib/eac_docker/images/templatized.rb +26 -0
  102. data/vendor/eac_docker/lib/eac_docker/registry.rb +17 -0
  103. data/vendor/eac_docker/lib/eac_docker/version.rb +1 -1
  104. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec.rb +12 -0
  105. data/vendor/eac_docker/spec/lib/eac_docker/images/coded_spec_files/image1/Dockerfile +1 -0
  106. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec.rb +17 -0
  107. data/vendor/eac_docker/spec/lib/eac_docker/images/templatized_spec_files/stub_docker_image/Dockerfile +1 -0
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +2 -50
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/class_setup.rb +52 -0
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern/module_setup.rb +31 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_constructor.rb +53 -0
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
  117. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  118. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  119. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
  120. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  121. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +4 -6
  122. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/concat.rb +33 -0
  123. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/envvars.rb +24 -0
  124. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command/extra_options.rb +0 -21
  125. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  126. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  127. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  128. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  129. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  130. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  131. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  132. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  133. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  134. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  135. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  136. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +11 -1
  137. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  138. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  139. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  140. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  141. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_concern_spec.rb +30 -17
  142. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/common_constructor_spec.rb +66 -8
  143. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  144. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  145. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  146. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  147. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +12 -1
  148. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  149. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  150. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  151. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  152. metadata +108 -13
  153. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  154. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
  155. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  156. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -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
@@ -28,4 +28,19 @@ RSpec.describe ::EacRubyUtils::Configs do
28
28
 
29
29
  it { expect(::YAML.load_file(storage_path)).to eq(parent: { child: 'value1' }) }
30
30
  end
31
+
32
+ describe '#read' do
33
+ let(:present_key) { 'a.present.key' }
34
+ let(:blank_key) { 'a.blank.key' }
35
+
36
+ before do
37
+ instance[present_key] = 'A value'
38
+ instance[blank_key] = ''
39
+ instance.save
40
+ instance.load
41
+ end
42
+
43
+ it { expect(instance[present_key]).to be_present }
44
+ it { expect(instance[blank_key]).to be_present }
45
+ end
31
46
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/enumerator/current'
4
+
5
+ RSpec.describe ::Enumerator do
6
+ let(:list) { %w[a b] }
7
+ let(:instance) { list.each }
8
+
9
+ it { expect(instance).to be_a(described_class) }
10
+ it { expect(instance.current).to eq('a') }
11
+
12
+ context 'with first next' do
13
+ before { instance.next }
14
+
15
+ it { expect(instance.current).to eq('b') }
16
+ end
17
+
18
+ context 'with last next' do
19
+ before do
20
+ instance.next
21
+ instance.next
22
+ end
23
+
24
+ it { expect(instance.current).to eq(nil) }
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/patches/enumerator/stopped'
4
+
5
+ RSpec.describe ::Enumerator do
6
+ let(:list) { %w[a b] }
7
+ let(:instance) { list.each }
8
+
9
+ it { expect(instance).to be_a(described_class) }
10
+ it { expect(instance.peek).to eq('a') }
11
+ it { expect(instance).to be_ongoing }
12
+ it { expect(instance).not_to be_stopped }
13
+
14
+ context 'with first next' do
15
+ before { instance.next }
16
+
17
+ it { expect(instance.peek).to eq('b') }
18
+ it { expect(instance).to be_ongoing }
19
+ it { expect(instance).not_to be_stopped }
20
+ end
21
+
22
+ context 'with last next' do
23
+ before do
24
+ instance.next
25
+ instance.next
26
+ end
27
+
28
+ it { expect { instance.peek }.to raise_error(::StopIteration) }
29
+ it { expect(instance).not_to be_ongoing }
30
+ it { expect(instance).to be_stopped }
31
+ end
32
+ end
@@ -3,20 +3,20 @@
3
3
  require 'eac_ruby_utils/paths_hash'
4
4
 
5
5
  RSpec.describe ::EacRubyUtils::PathsHash do
6
- describe '#[]' do
7
- let(:source_hash) do
8
- {
9
- parent: {
10
- child1: {
11
- child1_1: 'v1_1',
12
- child1_2: 'v1_2'
13
- },
14
- child2: 'v2'
15
- }
6
+ let(:source_hash) do
7
+ {
8
+ parent: {
9
+ child1: {
10
+ child1_1: 'v1_1',
11
+ child1_2: 'v1_2'
12
+ },
13
+ child2: 'v2'
16
14
  }
17
- end
18
- let(:instance) { described_class.new(source_hash) }
15
+ }
16
+ end
17
+ let(:instance) { described_class.new(source_hash) }
19
18
 
19
+ describe '#[]' do
20
20
  {
21
21
  'parent.child1.child1_1' => 'v1_1',
22
22
  'parent.child1.child1_2' => 'v1_2',
@@ -38,7 +38,7 @@ RSpec.describe ::EacRubyUtils::PathsHash do
38
38
  end
39
39
 
40
40
  describe '#[]=' do
41
- let(:instance) { described_class.new }
41
+ let(:source_hash) { {} }
42
42
 
43
43
  before do
44
44
  instance['a.b.c'] = '123'
@@ -46,4 +46,43 @@ RSpec.describe ::EacRubyUtils::PathsHash do
46
46
 
47
47
  it { expect(instance.to_h).to eq(a: { b: { c: '123' } }) }
48
48
  end
49
+
50
+ describe '#fetch' do
51
+ {
52
+ 'parent.child1.child1_1' => 'v1_1',
53
+ 'parent.child1.child1_2' => 'v1_2',
54
+ 'parent.child1.child1_2.no_exist' => ::EacRubyUtils::PathsHash::EntryKeyError,
55
+ 'parent.child1.child1_3' => ::EacRubyUtils::PathsHash::EntryKeyError,
56
+ 'parent.child2' => 'v2',
57
+ 'no_exist' => ::EacRubyUtils::PathsHash::EntryKeyError,
58
+ 'parent.child1' => {
59
+ child1_1: 'v1_1',
60
+ child1_2: 'v1_2'
61
+ }
62
+ }.each do |entry_key, expected_value|
63
+ if expected_value.is_a?(::Class) && expected_value < ::Exception
64
+ it "raise error #{expected_value}" do
65
+ expect { instance.fetch(entry_key) }.to raise_error(expected_value)
66
+ end
67
+ else
68
+ it "\#fetch return \"#{expected_value}\"" do
69
+ expect(instance.fetch(entry_key)).to eq(expected_value)
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ describe '#key?' do
76
+ {
77
+ 'parent.child1.child1_1' => true,
78
+ 'parent.child1.child1_2' => true,
79
+ 'parent.child1.child1_2.no_exist' => false,
80
+ 'parent.child1.child1_3' => false,
81
+ 'parent.child2' => true,
82
+ 'no_exist' => false,
83
+ 'parent.child1' => true
84
+ }.each do |entry_key, expected_value|
85
+ it { expect(instance.key?(entry_key)).to eq(expected_value) }
86
+ end
87
+ end
49
88
  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.0'
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
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ class Stream
8
+ enable_simple_cache
9
+ enable_listable
10
+
11
+ lists.add_symbol :codec_type, :audio, :video, :subtitle, :data
12
+
13
+ common_constructor :ffprobe_data do
14
+ self.ffprobe_data = ffprobe_data.symbolize_keys.freeze
15
+ self.class.lists.codec_type.value_validate!(codec_type)
16
+ end
17
+
18
+ lists.codec_type.each_value do |v|
19
+ define_method "#{v}?" do
20
+ codec_type == v
21
+ end
22
+ end
23
+
24
+ def to_s
25
+ "#{index}|#{codec_type}|#{codec_name}|#{language}"
26
+ end
27
+
28
+ def to_h
29
+ ffprobe_data
30
+ end
31
+
32
+ %i[index codec_name codec_long_name].each do |method_name|
33
+ define_method method_name do
34
+ ffprobe_data.fetch(method_name)
35
+ end
36
+ end
37
+
38
+ def codec_type
39
+ ffprobe_data.fetch(:codec_type).to_sym
40
+ end
41
+
42
+ def tags
43
+ ffprobe_data[:tags].if_present({}, &:symbolize_keys)
44
+ end
45
+
46
+ def language
47
+ tags[:language]
48
+ end
49
+ end
50
+ end
51
+ end