ehbrs-tools 0.14.0 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) 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 +24 -0
  21. data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
  22. data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
  23. data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
  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/fix_profile.rb +1 -0
  35. data/lib/ehbrs/videos/unsupported/fixes/supported_codec.rb +1 -1
  36. data/lib/ehbrs/videos/unsupported/profiles/base.rb +17 -3
  37. data/lib/ehbrs/videos/unsupported/profiles/philco.rb +5 -4
  38. data/vendor/aranha-parsers/Gemfile +5 -0
  39. data/vendor/aranha-parsers/aranha-parsers.gemspec +23 -0
  40. data/vendor/aranha-parsers/lib/aranha/parsers.rb +9 -0
  41. data/vendor/aranha-parsers/lib/aranha/parsers/base.rb +79 -0
  42. data/vendor/aranha-parsers/lib/aranha/parsers/html.rb +11 -0
  43. data/vendor/aranha-parsers/lib/aranha/parsers/html/base.rb +47 -0
  44. data/vendor/aranha-parsers/lib/aranha/parsers/html/item.rb +24 -0
  45. data/vendor/aranha-parsers/lib/aranha/parsers/html/item_list.rb +29 -0
  46. data/vendor/aranha-parsers/lib/aranha/parsers/html/node.rb +13 -0
  47. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/base.rb +36 -0
  48. data/vendor/aranha-parsers/lib/aranha/parsers/html/node/default.rb +126 -0
  49. data/vendor/aranha-parsers/lib/aranha/parsers/invalid_state_exception.rb +8 -0
  50. data/vendor/aranha-parsers/lib/aranha/parsers/patches.rb +11 -0
  51. data/vendor/aranha-parsers/lib/aranha/parsers/patches/ofx_parser.rb +38 -0
  52. data/vendor/aranha-parsers/lib/aranha/parsers/source_address.rb +55 -0
  53. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/file.rb +31 -0
  54. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_get.rb +25 -0
  55. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/hash_http_post.rb +45 -0
  56. data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +49 -0
  57. data/vendor/aranha-parsers/lib/aranha/parsers/source_target_fixtures.rb +77 -0
  58. data/vendor/aranha-parsers/lib/aranha/parsers/spec/source_target_fixtures_example.rb +78 -0
  59. data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +7 -0
  60. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address/http_get_spec.rb +21 -0
  61. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_address_spec.rb +74 -0
  62. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec.rb +27 -0
  63. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.source.txt +1 -0
  64. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub1.target.html +1 -0
  65. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub2.source.html +1 -0
  66. data/vendor/aranha-parsers/spec/lib/aranha/parsers/source_target_fixtures_spec_files/stub3.target.yaml +1 -0
  67. data/vendor/aranha-parsers/spec/lib/rubocop_check_spec.rb +7 -0
  68. data/vendor/aranha-parsers/spec/spec_helper.rb +8 -0
  69. data/vendor/eac_cli/eac_cli.gemspec +1 -1
  70. data/vendor/eac_cli/lib/eac_cli/definition.rb +49 -22
  71. data/vendor/eac_cli/lib/eac_cli/definition/alternative.rb +83 -0
  72. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +17 -1
  73. data/vendor/eac_cli/lib/eac_cli/{parser/options_collection.rb → definition/help_formatter.rb} +20 -49
  74. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +21 -4
  75. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder.rb +18 -40
  76. data/vendor/eac_cli/lib/eac_cli/docopt/doc_builder/alternative.rb +50 -0
  77. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +1 -0
  78. data/vendor/eac_cli/lib/eac_cli/parser.rb +21 -3
  79. data/vendor/eac_cli/lib/eac_cli/parser/alternative.rb +88 -0
  80. data/vendor/eac_cli/lib/eac_cli/parser/alternative/argv.rb +17 -0
  81. data/vendor/eac_cli/lib/eac_cli/parser/alternative/double_dash.rb +24 -0
  82. data/vendor/eac_cli/lib/eac_cli/parser/alternative/options.rb +58 -0
  83. data/vendor/eac_cli/lib/eac_cli/parser/alternative/positionals.rb +30 -0
  84. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +4 -0
  85. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +2 -1
  86. data/vendor/eac_cli/lib/eac_cli/runner.rb +7 -3
  87. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +19 -2
  88. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +1 -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 +96 -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 +57 -40
  96. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/output_file_spec.rb +53 -0
  97. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/abstract_methods.rb +60 -0
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +7 -104
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/entry_reader.rb +81 -0
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +18 -0
  105. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +46 -0
  106. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +27 -0
  107. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  108. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  109. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  110. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  111. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/module/abstract_methods.rb +10 -0
  112. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb +17 -0
  113. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  114. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  115. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  116. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  117. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  118. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +4 -0
  119. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  120. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/yaml.rb +3 -2
  121. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/abstract_methods_spec.rb +28 -0
  122. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  123. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  124. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  125. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  126. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  127. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
  128. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +30 -2
  129. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/convert_job.rb +91 -0
  130. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +51 -0
  131. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  132. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  133. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  134. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  135. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  136. metadata +78 -7
  137. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  138. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
  139. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  140. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacRubyUtils
4
+ class PathsHash
5
+ class PathSearch
6
+ class << self
7
+ def parse_entry_key(string)
8
+ new(::EacRubyUtils::PathsHash.parse_entry_key(string), [])
9
+ end
10
+ end
11
+
12
+ common_constructor :current, :previous do
13
+ self.current = current.assert_argument(Array, 'current').freeze
14
+ self.previous = previous.assert_argument(Array, 'previous')
15
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Current is empty' if current.empty?
16
+ end
17
+
18
+ def cursor
19
+ current.first
20
+ end
21
+
22
+ def ended?
23
+ current.count <= 1
24
+ end
25
+
26
+ def raise_error(message)
27
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, "#{message} (#{self})"
28
+ end
29
+
30
+ def succeeding
31
+ self.class.new(current[1..-1], previous + [cursor])
32
+ end
33
+
34
+ def to_s
35
+ "#{self.class}[Current: #{current}, Previous: #{previous}]"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -8,7 +8,8 @@ module EacRubyUtils
8
8
  # A [EacRubyUtils::Envs::Command] which runs in a clean Ruby environment.
9
9
  class Command < ::EacRubyUtils::Envs::Command
10
10
  def initialize(bundle_args, extra_options = {})
11
- super(::EacRubyUtils::Envs.local, bundle_args, extra_options)
11
+ host_env = extra_options.delete(:host_env)
12
+ super(host_env || ::EacRubyUtils::Envs.local, bundle_args, extra_options)
12
13
  end
13
14
 
14
15
  %w[system execute].each do |method_prefix|
@@ -27,6 +27,10 @@ module EacRubyUtils
27
27
  property_method?(method_name) || super
28
28
  end
29
29
 
30
+ def slice_fetch(*keys)
31
+ self.class.new(keys.map { |key| [key, fetch(key)] }.to_h)
32
+ end
33
+
30
34
  def to_h
31
35
  data.dup
32
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.46.0'
4
+ VERSION = '0.53.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
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/blank_not_blank'
4
+
5
+ RSpec.describe ::EacRubyUtils::BlankNotBlank do
6
+ let(:instance) { described_class.instance }
7
+
8
+ it do
9
+ expect { described_class.new }.to raise_error(::NoMethodError)
10
+ end
11
+
12
+ it { expect(instance).to be_present }
13
+ it { expect(instance).not_to be_blank }
14
+ it { expect(instance).to be_truthy }
15
+ it { expect(instance).to eq('') }
16
+ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.2.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