ehbrs-tools 0.13.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +1 -1
  3. data/lib/ehbrs/runner.rb +10 -17
  4. data/lib/ehbrs/runner/finances.rb +4 -7
  5. data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
  6. data/lib/ehbrs/runner/fs.rb +4 -7
  7. data/lib/ehbrs/runner/fs/used_space.rb +8 -9
  8. data/lib/ehbrs/runner/google.rb +4 -7
  9. data/lib/ehbrs/runner/google/translate.rb +7 -12
  10. data/lib/ehbrs/runner/self.rb +4 -7
  11. data/lib/ehbrs/runner/self/test.rb +5 -10
  12. data/lib/ehbrs/runner/vg.rb +4 -7
  13. data/lib/ehbrs/runner/vg/ips.rb +9 -14
  14. data/lib/ehbrs/runner/vg/wii.rb +10 -13
  15. data/lib/ehbrs/runner/videos.rb +7 -14
  16. data/lib/ehbrs/runner/videos/extract.rb +10 -13
  17. data/lib/ehbrs/runner/videos/probe.rb +32 -0
  18. data/lib/ehbrs/runner/videos/series.rb +5 -8
  19. data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
  20. data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
  21. data/lib/ehbrs/runner/web_utils.rb +24 -0
  22. data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
  23. data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
  24. data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
  25. data/lib/ehbrs/tools/version.rb +1 -1
  26. data/lib/ehbrs/videos/file.rb +2 -1
  27. data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
  28. data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
  29. data/vendor/eac_cli/eac_cli.gemspec +3 -3
  30. data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
  31. data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
  32. data/vendor/eac_cli/lib/eac_cli/definition.rb +94 -0
  33. data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
  34. data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +42 -0
  35. data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
  36. data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +31 -0
  37. data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
  38. data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +46 -0
  39. data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
  40. data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +60 -0
  41. data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
  42. data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +127 -0
  43. data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +38 -0
  44. data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +77 -0
  45. data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
  46. data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
  47. data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
  48. data/vendor/eac_cli/lib/eac_cli/runner.rb +68 -7
  49. data/vendor/eac_cli/lib/eac_cli/runner/context.rb +35 -0
  50. data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
  51. data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
  52. data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
  53. data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
  54. data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
  55. data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
  56. data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +78 -0
  57. data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
  58. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  59. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
  60. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
  61. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  62. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  63. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +8 -40
  64. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
  65. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
  66. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +2 -2
  67. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
  68. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
  69. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
  70. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
  71. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
  72. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
  73. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  74. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +4 -0
  75. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +4 -0
  76. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
  77. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +5 -0
  78. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
  79. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
  80. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
  81. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
  82. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
  83. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
  84. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
  85. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  86. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  87. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  88. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  89. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +8 -8
  90. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
  91. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
  92. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +57 -0
  93. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  94. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  95. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  96. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
  97. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
  98. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
  99. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  100. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
  101. data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
  102. data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
  103. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
  104. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
  105. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
  106. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
  107. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
  108. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
  109. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
  110. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
  111. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
  112. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
  113. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
  114. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
  115. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
  116. data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
  117. data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
  118. data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
  119. data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
  120. metadata +77 -10
  121. data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
  122. data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +0 -22
  123. data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
  124. data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
  125. data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +0 -23
@@ -1,20 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/default_runner'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_ruby_utils/console/docopt_runner'
3
+ require 'eac_cli/core_ext'
6
4
  require 'ehbrs/videos/extract/package'
7
5
 
8
6
  module Ehbrs
9
- class Runner < ::EacRubyUtils::Console::DocoptRunner
10
- class Videos < ::EacRubyUtils::Console::DocoptRunner
11
- class Extract < ::EacRubyUtils::Console::DocoptRunner
12
- include ::EacCli::DefaultRunner
7
+ class Runner
8
+ class Videos
9
+ class Extract
13
10
  require_sub __FILE__
14
11
 
15
12
  DEFAULT_QUALITIES = %w[1080 720 web webrip hdtv].freeze
16
13
 
17
- runner_definition do
14
+ runner_with :help do
18
15
  desc 'Extrai arquivos de seriados.'
19
16
  arg_opt '-d', '--dir', 'Extraí para diretório.'
20
17
  bool_opt '-D', '--delete', 'Remove o pacote após o processamento.'
@@ -26,20 +23,20 @@ module Ehbrs
26
23
  start_banner
27
24
  packages.each do |package|
28
25
  infov 'Package', package
29
- package.run(options.fetch('--delete'))
26
+ package.run(parsed.delete?)
30
27
  end
31
28
  end
32
29
 
33
30
  private
34
31
 
35
32
  def packages_uncached
36
- options.fetch('<packages>').map do |p|
33
+ parsed.packages?.map do |p|
37
34
  ::Ehbrs::Videos::Extract::Package.new(p, target_dir, qualities)
38
35
  end
39
36
  end
40
37
 
41
38
  def qualities_uncached
42
- (options.fetch('--qualities').to_s.split(',') + DEFAULT_QUALITIES).uniq
39
+ (parsed.qualities.to_s.split(',') + DEFAULT_QUALITIES).uniq
43
40
  end
44
41
 
45
42
  def start_banner
@@ -49,11 +46,11 @@ module Ehbrs
49
46
  end
50
47
 
51
48
  def target_dir_uncached
52
- options.fetch('--dir').if_present(&:to_pathname) || default_target_dir
49
+ parsed.dir.if_present(&:to_pathname) || default_target_dir
53
50
  end
54
51
 
55
52
  def default_target_dir
56
- r = options.fetch('<packages>').first.to_pathname.basename('.*')
53
+ r = parsed.packages.first.to_pathname.basename('.*')
57
54
  return r unless r.exist?
58
55
 
59
56
  r = r.basename_sub { |b| "#{b}_extract" }
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'ehbrs_ruby_utils/videos/container/file'
5
+ require 'eac_ruby_utils/yaml'
6
+
7
+ module Ehbrs
8
+ class Runner
9
+ class Videos
10
+ class Probe
11
+ runner_with :help, :output_file do
12
+ desc 'FFProbe em um arquivo de vídeo.'
13
+ pos_arg :file_path
14
+ end
15
+
16
+ def run
17
+ run_output
18
+ end
19
+
20
+ def output_content
21
+ ::EacRubyUtils::Yaml.dump(container_file.info.to_h)
22
+ end
23
+
24
+ private
25
+
26
+ def container_file_uncached
27
+ ::EhbrsRubyUtils::Videos::Container::File.new(parsed.file_path)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,17 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/default_runner'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_ruby_utils/console/docopt_runner'
3
+ require 'eac_cli/core_ext'
6
4
 
7
5
  module Ehbrs
8
- class Runner < ::EacRubyUtils::Console::DocoptRunner
9
- class Videos < ::EacRubyUtils::Console::DocoptRunner
10
- class Series < ::EacRubyUtils::Console::DocoptRunner
11
- include ::EacCli::DefaultRunner
6
+ class Runner
7
+ class Videos
8
+ class Series
12
9
  require_sub __FILE__
13
10
 
14
- runner_definition do
11
+ runner_with :help, :subcommands do
15
12
  desc 'Ferramentas para seriados.'
16
13
  subcommands
17
14
  end
@@ -1,21 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/default_runner'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_ruby_utils/console/docopt_runner'
3
+ require 'eac_cli/core_ext'
6
4
  require 'ehbrs/videos/series/rename/file'
7
5
  require 'ehbrs/videos/series/rename/file/options'
8
6
  require 'ehbrs/videos/series/rename/results_builder'
9
7
 
10
8
  module Ehbrs
11
- class Runner < ::EacRubyUtils::Console::DocoptRunner
12
- class Videos < ::EacRubyUtils::Console::DocoptRunner
13
- class Series < ::EacRubyUtils::Console::DocoptRunner
14
- class Rename < ::EacRubyUtils::Console::DocoptRunner
15
- include ::EacCli::DefaultRunner
9
+ class Runner
10
+ class Videos
11
+ class Series
12
+ class Rename
16
13
  include ::EacRubyUtils::Fs::Traversable
17
14
 
18
- runner_definition do
15
+ runner_with :help do
19
16
  desc 'Renomeia arquivos de séries.'
20
17
  bool_opt '-r', '--recursive', 'Recursivo.'
21
18
  bool_opt '-c', '--confirm', 'Confirmação a renomeação.'
@@ -43,11 +40,11 @@ module Ehbrs
43
40
  end
44
41
 
45
42
  def paths
46
- options.fetch('<paths>').if_present(['.'])
43
+ parsed.paths.if_present(['.'])
47
44
  end
48
45
 
49
46
  def traverser_recursive
50
- options.fetch('--recursive')
47
+ parsed.recursive
51
48
  end
52
49
 
53
50
  def traverser_check_file(path)
@@ -55,7 +52,7 @@ module Ehbrs
55
52
  end
56
53
 
57
54
  def series_file_options_uncached
58
- ::Ehbrs::Videos::Series::Rename::File::Options.new(options)
55
+ ::Ehbrs::Videos::Series::Rename::File::Options.new(parsed)
59
56
  end
60
57
 
61
58
  def show_results
@@ -1,21 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_cli/default_runner'
4
- require 'eac_ruby_utils/core_ext'
5
- require 'eac_ruby_utils/console/docopt_runner'
3
+ require 'eac_cli/core_ext'
6
4
  require 'ehbrs/videos/unsupported/check_set'
7
5
  require 'ehbrs/videos/unsupported/search'
8
6
  require 'ehbrs/videos/unsupported/profiles'
9
7
 
10
8
  module Ehbrs
11
- class Runner < ::EacRubyUtils::Console::DocoptRunner
12
- class Videos < ::EacRubyUtils::Console::DocoptRunner
13
- class Unsupported < ::EacRubyUtils::Console::DocoptRunner
14
- include ::EacCli::DefaultRunner
15
-
9
+ class Runner
10
+ class Videos
11
+ class Unsupported
16
12
  PROFILES = %w[philco samsung].freeze
17
13
 
18
- runner_definition do
14
+ runner_with :help do
19
15
  desc 'Procura e converte vídeos não suportados pelas TVs de EHB/RS.'
20
16
  bool_opt '-f', '--fix', 'Converte vídeos para o formato apropriado.'
21
17
  arg_opt '-p', '--profiles', "Seleciona os perfis (#{PROFILES.join(', ')})."
@@ -41,17 +37,17 @@ module Ehbrs
41
37
  end
42
38
 
43
39
  def paths
44
- options.fetch('<paths>')
40
+ parsed.paths
45
41
  end
46
42
 
47
43
  def file_options
48
44
  { file_check_set: file_check_set, track_check_set: track_check_set,
49
- fix: options.fetch('--fix') }
45
+ fix: parsed.fix? }
50
46
  end
51
47
 
52
48
  def profiles_uncached
53
- options.fetch('--profiles').if_present(PROFILES) { |v| v.split(',').map(&:strip) }
54
- .map { |name| profile_class(name).instance }
49
+ parsed.profiles.if_present(PROFILES) { |v| v.split(',').map(&:strip) }
50
+ .map { |name| profile_class(name).instance }
55
51
  end
56
52
 
57
53
  def profile_class(profile_name)
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'ehbrs_ruby_utils/web_utils/instance'
5
+
6
+ module Ehbrs
7
+ class Runner
8
+ class WebUtils
9
+ require_sub __FILE__
10
+
11
+ runner_with :help, :subcommands do
12
+ desc 'Ferramentas para EHB/RS Utils.'
13
+ pos_arg :instance_id
14
+ subcommands
15
+ end
16
+
17
+ private
18
+
19
+ def instance_uncached
20
+ ::EhbrsRubyUtils::WebUtils::Instance.by_id(parsed.instance_id)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+
5
+ module Ehbrs
6
+ class Runner
7
+ class WebUtils
8
+ class Videos
9
+ require_sub __FILE__
10
+
11
+ runner_with :help, :subcommands do
12
+ desc 'Ferramentas de vídeos para EHB/RS Utils.'
13
+ subcommands
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'ehbrs_ruby_utils/web_utils/videos/file'
5
+
6
+ module Ehbrs
7
+ class Runner
8
+ class WebUtils
9
+ class Videos
10
+ class Download
11
+ runner_with :help do
12
+ desc 'Importa informações de arquivos de vídeo de uma instância EHB/RS Utils.'
13
+ bool_opt '-c', '--confirm', 'Confirma as mudanças'
14
+ end
15
+
16
+ def run
17
+ start_banner
18
+ to_rename.each { |file| process_rename_file(file) }
19
+ to_delete.each { |file| process_delete_file(file) }
20
+ end
21
+
22
+ private
23
+
24
+ def start_banner
25
+ infov 'Files downloaded', files.count
26
+ infov 'To rename', to_rename.count
27
+ infov 'To delete', to_delete.count
28
+ end
29
+
30
+ def process_rename_file(file)
31
+ infov " * #{file.new_path}", file.original_path
32
+ file.rename if parsed.confirm?
33
+ end
34
+
35
+ def process_delete_file(file)
36
+ infov " * #{file.new_path}", 'REMOVE'
37
+ file.remove if parsed.confirm?
38
+ end
39
+
40
+ def files_uncached
41
+ data.map { |file_data| ::EhbrsRubyUtils::WebUtils::Videos::File.new(file_data) }
42
+ end
43
+
44
+ def to_rename_uncached
45
+ files.select(&:path_changed?)
46
+ end
47
+
48
+ def to_delete_uncached
49
+ files.reject { |f| f.type == 'Videos::SeriesDirectory' }.select(&:unwanted)
50
+ end
51
+
52
+ def data_uncached
53
+ ::JSON.parse(raw_content)
54
+ end
55
+
56
+ def raw_content
57
+ runner_context.call(:instance).http_request('/videos/files/export').body
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'ehbrs_ruby_utils/web_utils/videos/files_list'
5
+ require 'json'
6
+ require 'yaml'
7
+
8
+ module Ehbrs
9
+ class Runner
10
+ class WebUtils
11
+ class Videos
12
+ class Upload
13
+ runner_with :help do
14
+ desc 'Exporta informações de arquivos de vídeo para uma instância EHB/RS Utils.'
15
+ bool_opt '-P', '--no-ffprobe', 'Não recupera dados com "ffprobe".'
16
+ end
17
+
18
+ def run
19
+ %w[movies series].each { |type| upload_files_list(type) }
20
+ end
21
+
22
+ def upload_files_list(type)
23
+ infom "Uploading \"#{type}\" files list..."
24
+ files_list_path = send("#{type}_files_list")
25
+ infov 'Path', files_list_path
26
+ process_response(upload_request(files_list_path))
27
+ end
28
+
29
+ def upload_request(files_list_path)
30
+ runner_context.call(:instance).http_request(
31
+ '/videos/files/import',
32
+ method: :put,
33
+ body: {
34
+ 'videos_tableless_local_import_list[list_file]' => ::File.new(files_list_path)
35
+ },
36
+ header: {
37
+ 'Accept' => 'application/json'
38
+ }
39
+ )
40
+ end
41
+
42
+ def process_response(response)
43
+ infov 'Response status', response.status
44
+ if response.status == 200
45
+ pp ::JSON.parse(response.body) # rubocop:disable Rails/Output
46
+ else
47
+ error_file = '/tmp/ehbrsutils.html'
48
+ ::File.write(error_file, response.body)
49
+ system('firefox', error_file)
50
+ fatal_error('Retornou com status de erro: ' + error_file)
51
+ end
52
+ end
53
+
54
+ def series_files_list_uncached
55
+ write_files_list('Videos::SeriesDirectory', :series_directory)
56
+ end
57
+
58
+ def movies_files_list_uncached
59
+ write_files_list('Videos::MovieFile', :movies_directory)
60
+ end
61
+
62
+ def write_files_list(file_class, read_entry)
63
+ files_list = ::EhbrsRubyUtils::WebUtils::Videos::FilesList.new(
64
+ file_class,
65
+ runner_context.call(:instance).read_entry(read_entry),
66
+ ffprobe: !parsed.no_ffprobe?
67
+ )
68
+ infov 'Files found', files_list.data.fetch(:files).count
69
+ files_list.write_to
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ehbrs
4
4
  module Tools
5
- VERSION = '0.13.0'
5
+ VERSION = '0.16.0'
6
6
  end
7
7
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'ehbrs/videos/track'
5
+ require 'ehbrs_ruby_utils/executables'
5
6
 
6
7
  module Ehbrs
7
8
  module Videos
@@ -52,7 +53,7 @@ module Ehbrs
52
53
  end
53
54
 
54
55
  def content_uncached
55
- EacRubyUtils::Envs.local.command('ffprobe', path).execute!(output: :stderr).scrub
56
+ ::EhbrsRubyUtils::Executables.ffprobe.command(path).execute!(output: :stderr).scrub
56
57
  end
57
58
 
58
59
  def duration_uncached
@@ -6,21 +6,11 @@ module Ehbrs
6
6
  module Rename
7
7
  class File
8
8
  class Options
9
- def initialize(docopt_runner_options)
10
- @options = docopt_runner_options
11
- end
12
-
13
- %w[kernel confirm recursive extension].each do |method|
14
- class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
15
- def #{method}
16
- @options.fetch('--#{method}')
17
- end
18
- RUBY_EVAL
19
- end
9
+ common_constructor :options
10
+ delegate :kernel, :confirm, :recursive, :extension, to: :options
20
11
 
21
12
  def episode_increment
22
- r = @options.fetch('--episode-increment')
23
- r.present? ? r.to_i : 0
13
+ options.episode_increment.if_present(0, &:to_i)
24
14
  end
25
15
  end
26
16
  end