ehbrs-tools 0.5.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ehbrs/executables.rb +7 -1
  3. data/lib/ehbrs/fs.rb +9 -0
  4. data/lib/ehbrs/fs/compressed_package.rb +48 -0
  5. data/lib/ehbrs/gems.rb +37 -0
  6. data/lib/ehbrs/observers.rb +11 -0
  7. data/lib/ehbrs/observers/base.rb +64 -0
  8. data/lib/ehbrs/observers/with_persistence.rb +34 -0
  9. data/lib/ehbrs/runner/fs.rb +19 -0
  10. data/lib/ehbrs/runner/fs/used_space.rb +161 -0
  11. data/lib/ehbrs/runner/self.rb +19 -0
  12. data/lib/ehbrs/runner/self/test.rb +30 -0
  13. data/lib/ehbrs/runner/vg/ips.rb +67 -18
  14. data/lib/ehbrs/runner/videos/extract.rb +71 -0
  15. data/lib/ehbrs/runner/videos/series.rb +21 -0
  16. data/lib/ehbrs/runner/videos/series/rename.rb +75 -0
  17. data/lib/ehbrs/self.rb +9 -0
  18. data/lib/ehbrs/self/observers/used_space.rb +22 -0
  19. data/lib/ehbrs/self/observers/with_persistence.rb +38 -0
  20. data/lib/ehbrs/tools/version.rb +1 -1
  21. data/lib/ehbrs/user_dirs.rb +34 -0
  22. data/lib/ehbrs/vg/wii/game_file.rb +13 -0
  23. data/lib/ehbrs/videos/extract.rb +11 -0
  24. data/lib/ehbrs/videos/extract/package.rb +75 -0
  25. data/lib/ehbrs/videos/extract/package_file.rb +54 -0
  26. data/lib/ehbrs/videos/series.rb +11 -0
  27. data/lib/ehbrs/videos/series/rename.rb +13 -0
  28. data/lib/ehbrs/videos/series/rename/directory_group.rb +28 -0
  29. data/lib/ehbrs/videos/series/rename/file.rb +114 -0
  30. data/lib/ehbrs/videos/series/rename/file/basename_parser.rb +44 -0
  31. data/lib/ehbrs/videos/series/rename/file/options.rb +30 -0
  32. data/lib/ehbrs/videos/series/rename/line_result.rb +26 -0
  33. data/lib/ehbrs/videos/series/rename/line_result_group.rb +39 -0
  34. data/lib/ehbrs/videos/series/rename/results_builder.rb +32 -0
  35. data/lib/ehbrs/videos/series/rename/season_group.rb +39 -0
  36. data/vendor/eac_ruby_utils/eac_ruby_utils.gemspec +1 -1
  37. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/command.rb +8 -2
  38. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +2 -2
  39. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/extname.rb +30 -0
  40. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp.rb +52 -0
  41. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/directory.rb +16 -0
  42. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/temp/file.rb +34 -0
  43. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/on_clean_ruby_environment.rb +5 -16
  44. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable.rb +4 -0
  45. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerable/boolean_combinations.rb +45 -0
  46. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/to_pathname.rb +15 -0
  47. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp.rb +4 -0
  48. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/regexp/if_match.rb +16 -0
  49. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time.rb +4 -0
  50. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/default_time_zone_set.rb +5 -0
  51. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/time/local_time_zone.rb +25 -0
  52. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby.rb +9 -0
  53. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +31 -0
  54. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/on_clean_environment.rb +26 -0
  55. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  56. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/extname_spec.rb +18 -0
  57. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp/temp_spec.rb +12 -0
  58. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/fs/temp_spec.rb +52 -0
  59. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerable/boolean_combinations_spec.rb +39 -0
  60. metadata +85 -2
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'ehbrs/gems'
5
+ require 'eac_ruby_gems_utils/tests/multiple'
6
+ require 'eac_ruby_utils/core_ext'
7
+ require 'eac_ruby_utils/console/docopt_runner'
8
+
9
+ module Ehbrs
10
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
11
+ class Self < ::EacRubyUtils::Console::DocoptRunner
12
+ class Test < ::EacRubyUtils::Console::DocoptRunner
13
+ require_sub __FILE__
14
+ include ::EacCli::DefaultRunner
15
+
16
+ runner_definition do
17
+ desc 'Test core and local gems.'
18
+ end
19
+
20
+ def run
21
+ fatal_error 'Some test did not pass' unless tests.ok?
22
+ end
23
+
24
+ def tests_uncached
25
+ ::EacRubyGemsUtils::Tests::Multiple.new(::Ehbrs::Gems.all)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -4,6 +4,7 @@ require 'eac_cli/runner'
4
4
  require 'eac_cli/default_runner'
5
5
  require 'eac_ruby_utils/core_ext'
6
6
  require 'eac_ruby_utils/console/docopt_runner'
7
+ require 'eac_ruby_utils/fs/temp'
7
8
  require 'ehbrs/executables'
8
9
 
9
10
  module Ehbrs
@@ -17,71 +18,119 @@ module Ehbrs
17
18
  arg_opt '-o', '--output-file', ' Saída no arquivo <output-file>.'
18
19
  bool_opt '-w', '--overwrite', 'Sobrescreve o arquivo de saída se existente.'
19
20
  pos_arg 'source-file'
20
- pos_arg 'ips-file'
21
+ pos_arg 'ips-files', repeat: true
21
22
  end
22
23
 
23
24
  def run
24
25
  validate
26
+ start_banner
27
+ run_patches
28
+ infov 'Concluído'
25
29
  end
26
30
 
27
31
  private
28
32
 
29
- def run_patch
30
- ::Ehbrs::Executables.floating_ips.command
31
- .append(['--apply', ips_file, source_file, output_file]).system!
33
+ def on_temp_files
34
+ ::EacRubyUtils::Fs::Temp.on_file do |input|
35
+ ::EacRubyUtils::Fs::Temp.on_file do |output|
36
+ yield TempFiles.new(source_file, input, output)
37
+ end
38
+ end
39
+ end
40
+
41
+ def run_patch(source_path, ips_path, output_path)
42
+ ::Ehbrs::Executables.flips.command
43
+ .append(['--apply', ips_path, source_path, output_path]).system!
44
+ end
45
+
46
+ def run_patches
47
+ on_temp_files do |temp|
48
+ ips_files.each do |ips_file|
49
+ run_patch(temp.input, ips_file, temp.output)
50
+ temp.swap
51
+ end
52
+ temp.move_result_to(output_file)
53
+ end
32
54
  end
33
55
 
34
56
  def source_file
35
- options.fetch('<source-file>')
57
+ options.fetch('<source-file>').to_pathname
36
58
  end
37
59
 
38
60
  def start_banner
39
61
  infov 'Source file', source_file
40
- infov 'IPS file', ips_file
41
62
  infov 'Output file', output_file
63
+ infov 'IPS files', ips_files.count
64
+ ips_files.each { |ips_file| infov ' * ', ips_file }
42
65
  end
43
66
 
44
- def ips_file
45
- options.fetch('<ips-file>')
67
+ def ips_files
68
+ options.fetch('<ips-files>').map(&:to_pathname)
46
69
  end
47
70
 
48
71
  def output_file
49
- options.fetch('--output-file') || default_output_file
72
+ options.fetch('--output-file').to_pathname || default_output_file
50
73
  end
51
74
 
52
75
  def default_output_file
53
- ::File.join(
54
- ::File.dirname(ips_file),
55
- ::File.basename(ips_file, '.*') + ::File.extname(source_file)
76
+ ips_files.last.parent.join(
77
+ ips_files.map { |f| f.basename('.*').to_path }.join('_') + source_file.extname
56
78
  )
57
79
  end
58
80
 
59
81
  def validate
60
82
  validate_source_file
61
- validate_ips_file
83
+ ips_files.each { |ips_file| validate_ips_file(ips_file) }
62
84
  validate_output_file
63
- start_banner
64
- run_patch
65
85
  end
66
86
 
67
87
  def validate_source_file
68
- return if ::File.exist?(source_file)
88
+ return if source_file.exist?
69
89
 
70
90
  fatal_error("Arquivo fonte \"#{source_file}\" não existe")
71
91
  end
72
92
 
73
- def validate_ips_file
93
+ def validate_ips_file(ips_file)
74
94
  return if ::File.exist?(ips_file)
75
95
 
76
96
  fatal_error("Arquivo IPS \"#{ips_file}\" não existe")
77
97
  end
78
98
 
79
99
  def validate_output_file
80
- return unless ::File.exist?(output_file)
100
+ return unless output_file.exist?
81
101
  return if options.fetch('--overwrite')
82
102
 
83
103
  fatal_error("Arquivo de saída \"#{output_file}\" já existe")
84
104
  end
105
+
106
+ class TempFiles
107
+ common_constructor :initial, :temp0, :temp1
108
+
109
+ def input
110
+ swaped? ? temp0 : initial
111
+ end
112
+
113
+ def move_result_to(dest)
114
+ return unless swaped?
115
+
116
+ ::FileUtils.mv(temp0.to_path, dest.to_path)
117
+ end
118
+
119
+ def output
120
+ temp1
121
+ end
122
+
123
+ def swap
124
+ temp0_current = temp0
125
+ self.temp0 = temp1
126
+ self.temp1 = temp0_current
127
+ @swaped = true
128
+ end
129
+
130
+ def swaped?
131
+ @swaped ? true : false
132
+ end
133
+ end
85
134
  end
86
135
  end
87
136
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'ehbrs/videos/extract/package'
7
+
8
+ module Ehbrs
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Videos < ::EacRubyUtils::Console::DocoptRunner
11
+ class Extract < ::EacRubyUtils::Console::DocoptRunner
12
+ include ::EacCli::DefaultRunner
13
+ require_sub __FILE__
14
+
15
+ DEFAULT_QUALITIES = %w[1080 720 web webrip hdtv].freeze
16
+
17
+ runner_definition do
18
+ desc 'Extrai arquivos de seriados.'
19
+ arg_opt '-d', '--dir', 'Extraí para diretório.'
20
+ bool_opt '-D', '--delete', 'Remove o pacote após o processamento.'
21
+ arg_opt '-q', '--qualities', 'Lista de qualidades.'
22
+ pos_arg 'packages', repeat: true
23
+ end
24
+
25
+ def run
26
+ start_banner
27
+ packages.each do |package|
28
+ infov 'Package', package
29
+ package.run(options.fetch('--delete'))
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def packages_uncached
36
+ options.fetch('<packages>').map do |p|
37
+ ::Ehbrs::Videos::Extract::Package.new(p, target_dir, qualities)
38
+ end
39
+ end
40
+
41
+ def qualities_uncached
42
+ (options.fetch('--qualities').to_s.split(',') + DEFAULT_QUALITIES).uniq
43
+ end
44
+
45
+ def start_banner
46
+ infov 'Packages', packages.count
47
+ infov 'Qualities', qualities
48
+ infov 'Target directory', target_dir
49
+ end
50
+
51
+ def target_dir_uncached
52
+ options.fetch('--dir').if_present(&:to_pathname) || default_target_dir
53
+ end
54
+
55
+ def default_target_dir
56
+ r = options.fetch('<packages>').first.to_pathname.basename('.*')
57
+ return r unless r.exist?
58
+
59
+ r = r.basename_sub { |b| "#{b}_extract" }
60
+ index = 0
61
+ loop do
62
+ return r unless r.exist?
63
+
64
+ index += 1
65
+ r = r.basename_sub { |b| "#{b}_#{index}" }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+
7
+ module Ehbrs
8
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
9
+ class Videos < ::EacRubyUtils::Console::DocoptRunner
10
+ class Series < ::EacRubyUtils::Console::DocoptRunner
11
+ include ::EacCli::DefaultRunner
12
+ require_sub __FILE__
13
+
14
+ runner_definition do
15
+ desc 'Ferramentas para seriados.'
16
+ subcommands
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/default_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/console/docopt_runner'
6
+ require 'ehbrs/videos/series/rename/file'
7
+ require 'ehbrs/videos/series/rename/file/options'
8
+ require 'ehbrs/videos/series/rename/results_builder'
9
+
10
+ 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
16
+ include ::EacRubyUtils::Fs::Traversable
17
+
18
+ runner_definition do
19
+ desc 'Renomeia arquivos de séries.'
20
+ bool_opt '-r', '--recursive', 'Recursivo.'
21
+ bool_opt '-c', '--confirm', 'Confirmação a renomeação.'
22
+ arg_opt '-k', '--kernel', 'Determina o kernel para os nomes dos arquivos.'
23
+ arg_opt '-E', '--extension', 'Substitui a extensão dos arquivos.'
24
+ arg_opt '-e', '--episode-increment', 'Aumenta o número do episódio.'
25
+ pos_arg 'paths', repeat: true, optional: true
26
+ end
27
+
28
+ def run
29
+ banner
30
+ show_results
31
+ rename_files
32
+ end
33
+
34
+ def banner
35
+ infov 'Paths', paths.count
36
+ infov 'Files found', files.count
37
+ end
38
+
39
+ def files_uncached
40
+ @files = []
41
+ paths.each { |path| traverser_check_path(path) }
42
+ @files
43
+ end
44
+
45
+ def paths
46
+ options.fetch('<paths>').if_present(['.'])
47
+ end
48
+
49
+ def traverser_recursive
50
+ options.fetch('--recursive')
51
+ end
52
+
53
+ def traverser_check_file(path)
54
+ @files << ::Ehbrs::Videos::Series::Rename::File.new(path, series_file_options)
55
+ end
56
+
57
+ def series_file_options_uncached
58
+ ::Ehbrs::Videos::Series::Rename::File::Options.new(options)
59
+ end
60
+
61
+ def show_results
62
+ ::Ehbrs::Videos::Series::Rename::ResultsBuilder.new(files).show(0)
63
+ end
64
+
65
+ def rename_files
66
+ return unless series_file_options.confirm
67
+
68
+ infom 'Renaming files...'
69
+ files.each(&:rename)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Ehbrs
6
+ module Self
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs/self/observers/with_persistence'
4
+
5
+ module Ehbrs
6
+ module Self
7
+ module Observers
8
+ class UsedSpace < ::Ehbrs::Self::Observers::WithPersistence
9
+ def path
10
+ label
11
+ end
12
+
13
+ def calculate_value
14
+ env = ::EacRubyUtils::Envs.local
15
+ env.command('du', '-sb', path.to_s).pipe(
16
+ env.command('cut', '-f', '-1')
17
+ ).execute!.strip.to_i
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs/observers/with_persistence'
4
+ require 'ehbrs/user_dirs'
5
+
6
+ module Ehbrs
7
+ module Self
8
+ module Observers
9
+ class WithPersistence
10
+ enable_simple_cache
11
+ common_constructor :label
12
+
13
+ def check_current_value
14
+ observer.check(current_value)
15
+ end
16
+
17
+ def changing_value?
18
+ observer.changing_value?(current_value)
19
+ end
20
+
21
+ private
22
+
23
+ def current_value_uncached
24
+ calculate_value
25
+ end
26
+
27
+ def observer_uncached
28
+ ::Ehbrs::Observers::WithPersistence.new(persistence_path, blank_value: :raise)
29
+ end
30
+
31
+ def persistence_path_uncached
32
+ ::Ehbrs::UserDirs.data.child('observers', label.to_s.parameterize)
33
+ .content_path.to_pathname
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ehbrs
4
4
  module Tools
5
- VERSION = '0.5.0'
5
+ VERSION = '0.11.0'
6
6
  end
7
7
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/filesystem_cache'
4
+ require 'eac_ruby_utils/simple_cache'
5
+
6
+ module Ehbrs
7
+ module UserDirs
8
+ class << self
9
+ include ::EacRubyUtils::SimpleCache
10
+
11
+ def application_id
12
+ 'ehbrs-tools'
13
+ end
14
+
15
+ private
16
+
17
+ def user_home_dir_uncached
18
+ ::EacRubyUtils::FilesystemCache.new(ENV['HOME'])
19
+ end
20
+
21
+ def cache_uncached
22
+ user_home_dir.child('.cache', application_id)
23
+ end
24
+
25
+ def config_uncached
26
+ user_home_dir.child('.config', application_id)
27
+ end
28
+
29
+ def data_uncached
30
+ user_home_dir.child('.local', 'share', application_id)
31
+ end
32
+ end
33
+ end
34
+ end