ehbrs-tools 0.7.0 → 0.9.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.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +7 -1
- data/lib/ehbrs/fs/compressed_package.rb +48 -0
- data/lib/ehbrs/fs.rb +9 -0
- data/lib/ehbrs/runner/videos/extract.rb +71 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/vg/wii/game_file.rb +13 -0
- data/lib/ehbrs/videos/extract/package.rb +75 -0
- data/lib/ehbrs/videos/extract/package_file.rb +54 -0
- data/lib/ehbrs/videos/extract.rb +11 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/executable.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e80eafdb451c5637bfcafbb89ccb3cb13c157d97f8e6f0098af5ff6f512837
|
4
|
+
data.tar.gz: 1580aa74f7e23b3af4a55f32499044d54a2e0e41d3f97e4dd96565f3faf10d31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad21b21deec42c02fcc510bf1fae9a6c397d96f86922db35e82dbeec98336b9d6a1790f34ca92d199c1916074a2cec29be5233a8154e2f13ead0ff8722a1bad
|
7
|
+
data.tar.gz: 7b8638979d00c8546c2b89386704bd09c2950561fb38267624357e4e640d45b6aa8685ba09d80ecf017acf8b8cdc174ac4923ee4a529b69687f875cf40b27014
|
data/lib/ehbrs/executables.rb
CHANGED
@@ -15,8 +15,10 @@ module Ehbrs
|
|
15
15
|
private
|
16
16
|
|
17
17
|
{
|
18
|
+
'-?' => %w[rar],
|
19
|
+
'-h' => %w[unzip],
|
18
20
|
'-version' => %w[ffmpeg ffprobe],
|
19
|
-
'--version' => %w[flips wit]
|
21
|
+
'--version' => %w[flips tar wit]
|
20
22
|
}.each do |validate_arg, commands|
|
21
23
|
commands.each do |command|
|
22
24
|
define_method("#{command}_uncached") do
|
@@ -24,6 +26,10 @@ module Ehbrs
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
29
|
+
|
30
|
+
def sevenzip_uncached
|
31
|
+
env.executable('7z', '--help')
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/files/info'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Fs
|
8
|
+
class CompressedPackage < ::Avm::Files::Info
|
9
|
+
MIME_TYPES = {
|
10
|
+
'application/zip' => :zip,
|
11
|
+
'application/x-7z-compressed' => :sevenzip,
|
12
|
+
'application/x-rar' => :rar,
|
13
|
+
'application/x-tar' => :tar
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
def extract_to(target)
|
17
|
+
target = target.to_pathname
|
18
|
+
target.mkpath
|
19
|
+
sub_extract_to(target)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def sub_extract_to(target)
|
25
|
+
MIME_TYPES[content_type.mime_type].if_present do |v|
|
26
|
+
return send("#{v}_extract_command", target).execute!
|
27
|
+
end
|
28
|
+
raise "Unknown how to extract \"#{path}\" (#{content_type})"
|
29
|
+
end
|
30
|
+
|
31
|
+
def sevenzip_extract_command(target_dir)
|
32
|
+
::Ehbrs::Executables.sevenzip.command('x', path, '-o', target_dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
def tar_extract_command(target_dir)
|
36
|
+
::Ehbrs::Executables.tar.command('-xf', path, '-C', target_dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
def rar_extract_command(target_dir)
|
40
|
+
::Ehbrs::Executables.rar.command('x', path.expand_path).chdir(target_dir)
|
41
|
+
end
|
42
|
+
|
43
|
+
def zip_extract_command(target_dir)
|
44
|
+
::Ehbrs::Executables.unzip.command(path, '-d', target_dir)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/ehbrs/fs.rb
ADDED
@@ -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
|
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -12,12 +12,16 @@ module Ehbrs
|
|
12
12
|
class GameFile < ::Pathname
|
13
13
|
enable_simple_cache
|
14
14
|
|
15
|
+
DISC_NUMBER_PATTERN = /disc.?(\d)/i.freeze
|
16
|
+
|
15
17
|
FORMAT = ::EacRubyUtils::CustomFormat.new(
|
16
18
|
b: :basename,
|
17
19
|
d: :dirname,
|
20
|
+
D: :disc_number,
|
18
21
|
e: :extname,
|
19
22
|
i: :id6,
|
20
23
|
n: :disc_name,
|
24
|
+
N: :nintendont_basename,
|
21
25
|
t: :database_title,
|
22
26
|
T: :disc_type
|
23
27
|
)
|
@@ -30,6 +34,10 @@ module Ehbrs
|
|
30
34
|
properties.fetch('Disc name')
|
31
35
|
end
|
32
36
|
|
37
|
+
def disc_number
|
38
|
+
DISC_NUMBER_PATTERN.if_match(basename.to_s, false) { |m| m[1].to_i }.if_present(1)
|
39
|
+
end
|
40
|
+
|
33
41
|
def disc_type
|
34
42
|
properties.fetch('File & disc type/type')
|
35
43
|
end
|
@@ -38,6 +46,11 @@ module Ehbrs
|
|
38
46
|
FORMAT.format(string).with(self)
|
39
47
|
end
|
40
48
|
|
49
|
+
def nintendont_basename
|
50
|
+
n = disc_number
|
51
|
+
n == 1 ? 'game' : "disc#{n}"
|
52
|
+
end
|
53
|
+
|
41
54
|
def id6
|
42
55
|
properties.fetch('Disc & part IDs/disc')
|
43
56
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs/fs/compressed_package'
|
5
|
+
require 'ehbrs/videos/extract/package_file'
|
6
|
+
|
7
|
+
module Ehbrs
|
8
|
+
module Videos
|
9
|
+
module Extract
|
10
|
+
class Package
|
11
|
+
enable_simple_cache
|
12
|
+
|
13
|
+
common_constructor :path, :target_dir, :qualities do
|
14
|
+
self.path = path.to_pathname
|
15
|
+
self.target_dir = target_dir.to_pathname
|
16
|
+
end
|
17
|
+
|
18
|
+
delegate :to_s, to: :path
|
19
|
+
|
20
|
+
def run(delete)
|
21
|
+
selected_files.each(&:copy_to_selected_dir)
|
22
|
+
files.each(&:move_to_quality_dir)
|
23
|
+
extract_dir.rmdir
|
24
|
+
path.unlink if delete
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def files_uncached
|
30
|
+
::Pathname.glob("#{extract_dir}/**/*").map do |file|
|
31
|
+
::Ehbrs::Videos::Extract::PackageFile.new(self, file)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_dir_uncached
|
36
|
+
r = target_dir / path.basename
|
37
|
+
raise "Extract directory \"#{r}\" is a file" if r.file?
|
38
|
+
|
39
|
+
r.rmtree if r.directory?
|
40
|
+
::Ehbrs::Fs::CompressedPackage.new(path).extract_to(r)
|
41
|
+
r
|
42
|
+
end
|
43
|
+
|
44
|
+
def files_qualities_uncached
|
45
|
+
qualities_with_default.select { |q| grouped_files.keys.include?(q) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def grouped_files_uncached
|
49
|
+
r = {}
|
50
|
+
files.each do |file|
|
51
|
+
r[file.quality] ||= []
|
52
|
+
r[file.quality] << file
|
53
|
+
end
|
54
|
+
r
|
55
|
+
end
|
56
|
+
|
57
|
+
def qualities_with_default
|
58
|
+
qualities + [::Ehbrs::Videos::Extract::PackageFile::DEFAULT_QUALITY]
|
59
|
+
end
|
60
|
+
|
61
|
+
def selected_dir_uncached
|
62
|
+
target_dir / 'selected'
|
63
|
+
end
|
64
|
+
|
65
|
+
def selected_files
|
66
|
+
files.select { |f| f.quality == selected_quality }
|
67
|
+
end
|
68
|
+
|
69
|
+
def selected_quality_uncached
|
70
|
+
files_qualities.first
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs/fs/compressed_package'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
module Videos
|
8
|
+
module Extract
|
9
|
+
class PackageFile
|
10
|
+
DEFAULT_QUALITY = '__default__'
|
11
|
+
|
12
|
+
enable_simple_cache
|
13
|
+
common_constructor :package, :path do
|
14
|
+
self.path = path.to_pathname
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_to_selected_dir
|
18
|
+
::FileUtils.cp(path.to_path, selected_dir.to_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def match_quality?(quality)
|
22
|
+
path.basename_sub { |b| b.to_s.downcase }.basename
|
23
|
+
.fnmatch?("*#{quality.downcase}*".gsub(/\A\*+/, '*').gsub(/\*+\z/, '*'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def move_to_quality_dir
|
27
|
+
::FileUtils.mv(path.to_path, quality_dir.to_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def quality_uncached
|
33
|
+
package.qualities.find { |q| match_quality?(q) } || DEFAULT_QUALITY
|
34
|
+
end
|
35
|
+
|
36
|
+
def quality_dir
|
37
|
+
r = package.target_dir / quality
|
38
|
+
r.mkpath
|
39
|
+
r
|
40
|
+
end
|
41
|
+
|
42
|
+
def selected_dir
|
43
|
+
r = nil
|
44
|
+
r = package.target_dir / 'source' if /\.torrent/ =~ path.to_path
|
45
|
+
r = package.target_dir / 'subtitle' if /\.srt/ =~ path.to_path
|
46
|
+
raise "Destination unknown: #{path}" unless r
|
47
|
+
|
48
|
+
r.mkpath
|
49
|
+
r
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: avm-tools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.44'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.44.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.44'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.44.2
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: eac_ruby_utils
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +97,8 @@ files:
|
|
77
97
|
- exe/ehbrs
|
78
98
|
- lib/ehbrs.rb
|
79
99
|
- lib/ehbrs/executables.rb
|
100
|
+
- lib/ehbrs/fs.rb
|
101
|
+
- lib/ehbrs/fs/compressed_package.rb
|
80
102
|
- lib/ehbrs/observers.rb
|
81
103
|
- lib/ehbrs/observers/base.rb
|
82
104
|
- lib/ehbrs/observers/with_persistence.rb
|
@@ -87,6 +109,7 @@ files:
|
|
87
109
|
- lib/ehbrs/runner/vg/ips.rb
|
88
110
|
- lib/ehbrs/runner/vg/wii.rb
|
89
111
|
- lib/ehbrs/runner/videos.rb
|
112
|
+
- lib/ehbrs/runner/videos/extract.rb
|
90
113
|
- lib/ehbrs/runner/videos/unsupported.rb
|
91
114
|
- lib/ehbrs/self.rb
|
92
115
|
- lib/ehbrs/self/observers/used_space.rb
|
@@ -105,6 +128,9 @@ files:
|
|
105
128
|
- lib/ehbrs/vg/wii/wit/path.rb
|
106
129
|
- lib/ehbrs/videos.rb
|
107
130
|
- lib/ehbrs/videos/convert_job.rb
|
131
|
+
- lib/ehbrs/videos/extract.rb
|
132
|
+
- lib/ehbrs/videos/extract/package.rb
|
133
|
+
- lib/ehbrs/videos/extract/package_file.rb
|
108
134
|
- lib/ehbrs/videos/file.rb
|
109
135
|
- lib/ehbrs/videos/profiles/base.rb
|
110
136
|
- lib/ehbrs/videos/profiles/same_quality.rb
|