ehbrs-tools 0.14.1 → 0.16.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) 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/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 +16 -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 +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 +56 -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. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  153. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  154. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  155. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  156. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  157. metadata +91 -7
  158. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +0 -21
  159. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +0 -49
  160. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +0 -31
  161. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +0 -21
@@ -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.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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module WebUtils
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/instances/base'
5
+ require 'httpclient'
6
+
7
+ module EhbrsRubyUtils
8
+ module WebUtils
9
+ class Instance < ::Avm::Instances::Base
10
+ def root_url
11
+ read_entry(:url)
12
+ end
13
+
14
+ def resource_url(resource_url_suffix)
15
+ root_url + '/' + resource_url_suffix.gsub(%r{\A/+}, '')
16
+ end
17
+
18
+ def http_request(resource_url_suffix, options = {})
19
+ method = options.delete(:method) || 'get'
20
+ url = resource_url(resource_url_suffix)
21
+ http_client.request(method, url, options)
22
+ end
23
+
24
+ def http_client_uncached
25
+ client = HTTPClient.new
26
+ client.force_basic_auth = true
27
+ client.set_basic_auth(root_url, read_entry(:admin_username), read_entry(:admin_password))
28
+ client
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module WebUtils
7
+ module Videos
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module EhbrsRubyUtils
6
+ module WebUtils
7
+ module Videos
8
+ class File < ::SimpleDelegator
9
+ def initialize(data)
10
+ super(::OpenStruct.new(data))
11
+ end
12
+
13
+ def exist?
14
+ ::File.exist?(original_path)
15
+ end
16
+
17
+ def path_changed?
18
+ original_path != new_path
19
+ end
20
+
21
+ def can_rename?
22
+ ::File.exist?(original_path) && !::File.exist?(new_path)
23
+ end
24
+
25
+ def remove
26
+ return unless exist?
27
+
28
+ ::File.unlink(original_path)
29
+ end
30
+
31
+ def rename
32
+ return unless can_rename?
33
+
34
+ ::FileUtils.mkdir_p(::File.dirname(new_path))
35
+ ::FileUtils.mv(original_path, new_path)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/json'
4
+ require 'eac_ruby_utils/fs/temp'
5
+ require 'ehbrs_ruby_utils/executables'
6
+
7
+ module EhbrsRubyUtils
8
+ module WebUtils
9
+ module Videos
10
+ class FilesList
11
+ enable_console_speaker
12
+ enable_simple_cache
13
+
14
+ common_constructor :type_class, :root_path, :options do
15
+ self.root_path = root_path.to_pathname
16
+ raise "\"#{root_path}\" is not a directory" unless root_path.directory?
17
+
18
+ self.options = options.with_indifferent_access.freeze
19
+ end
20
+
21
+ def write_to(path = nil)
22
+ path ||= ::EacRubyUtils::Fs::Temp.file.to_path
23
+ ::File.write(path, data.to_json)
24
+ path
25
+ end
26
+
27
+ def data
28
+ {
29
+ root_path: root_path.to_path,
30
+ type: type_class,
31
+ files: files_data
32
+ }
33
+ end
34
+
35
+ def files_data
36
+ case type_class
37
+ when 'Videos::MovieFile' then movies_files_data
38
+ when 'Videos::SeriesDirectory' then series_files_data
39
+ else raise "Unknown type class: \"#{type_class}\""
40
+ end
41
+ end
42
+
43
+ def movies_files_data
44
+ r = []
45
+ Dir["#{root_path}/**/*"].each do |path|
46
+ r << file_data(path) if ::File.file?(path)
47
+ end
48
+ r
49
+ end
50
+
51
+ def series_files_data
52
+ r = []
53
+ Dir["#{root_path}/*"].each do |path|
54
+ r << file_data(path) if ::File.directory?(path)
55
+ end
56
+ r
57
+ end
58
+
59
+ def file_data(path)
60
+ r = { original_path: path }
61
+ r[:ffprobe_data] = file_ffprobe_data(path) if ::File.file?(path)
62
+ r
63
+ end
64
+
65
+ def file_ffprobe_data(path)
66
+ return {} unless options.fetch(:ffprobe)
67
+
68
+ infom "Probing \"#{path}\"..."
69
+ ::JSON.parse(::EhbrsRubyUtils::Executables.ffprobe.command(
70
+ '-hide_banner', '-print_format', 'json', '-show_format', '-show_streams', path
71
+ ).execute!)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end