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.
- checksums.yaml +4 -4
- data/lib/ehbrs/executables.rb +1 -1
- data/lib/ehbrs/runner.rb +10 -17
- data/lib/ehbrs/runner/finances.rb +4 -7
- data/lib/ehbrs/runner/finances/bb_browser.rb +5 -10
- data/lib/ehbrs/runner/fs.rb +4 -7
- data/lib/ehbrs/runner/fs/used_space.rb +8 -9
- data/lib/ehbrs/runner/google.rb +4 -7
- data/lib/ehbrs/runner/google/translate.rb +7 -12
- data/lib/ehbrs/runner/self.rb +4 -7
- data/lib/ehbrs/runner/self/test.rb +5 -10
- data/lib/ehbrs/runner/vg.rb +4 -7
- data/lib/ehbrs/runner/vg/ips.rb +9 -14
- data/lib/ehbrs/runner/vg/wii.rb +10 -13
- data/lib/ehbrs/runner/videos.rb +7 -14
- data/lib/ehbrs/runner/videos/extract.rb +10 -13
- data/lib/ehbrs/runner/videos/probe.rb +32 -0
- data/lib/ehbrs/runner/videos/series.rb +5 -8
- data/lib/ehbrs/runner/videos/series/rename.rb +9 -12
- data/lib/ehbrs/runner/videos/unsupported.rb +9 -13
- data/lib/ehbrs/runner/web_utils.rb +24 -0
- data/lib/ehbrs/runner/web_utils/videos.rb +18 -0
- data/lib/ehbrs/runner/web_utils/videos/download.rb +63 -0
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +75 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/videos/file.rb +2 -1
- data/lib/ehbrs/videos/series/rename/file/options.rb +3 -13
- data/lib/ehbrs/videos/unsupported/fix_profile.rb +1 -0
- data/vendor/eac_cli/eac_cli.gemspec +3 -3
- data/vendor/eac_cli/lib/eac_cli/core_ext.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/default_runner.rb +6 -14
- data/vendor/eac_cli/lib/eac_cli/definition.rb +94 -0
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +42 -0
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +13 -0
- data/vendor/eac_cli/lib/eac_cli/definition/positional_argument.rb +31 -0
- data/vendor/eac_cli/lib/eac_cli/{runner/docopt_doc.rb → docopt/doc_builder.rb} +15 -8
- data/vendor/eac_cli/lib/eac_cli/docopt/runner_extension.rb +46 -0
- data/vendor/eac_cli/lib/eac_cli/parser.rb +14 -0
- data/vendor/eac_cli/lib/eac_cli/parser/collector.rb +60 -0
- data/vendor/eac_cli/lib/eac_cli/parser/error.rb +15 -0
- data/vendor/eac_cli/lib/eac_cli/parser/options_collection.rb +127 -0
- data/vendor/eac_cli/lib/eac_cli/parser/parse_result.rb +38 -0
- data/vendor/eac_cli/lib/eac_cli/parser/positional_collection.rb +77 -0
- data/vendor/eac_cli/lib/eac_cli/patches.rb +4 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object.rb +5 -0
- data/vendor/eac_cli/lib/eac_cli/patches/object/runner_with.rb +25 -0
- data/vendor/eac_cli/lib/eac_cli/runner.rb +68 -7
- data/vendor/eac_cli/lib/eac_cli/runner/context.rb +35 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with.rb +9 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help.rb +19 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/output_file.rb +26 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/subcommands.rb +96 -0
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/docopt/runner_extension_spec.rb +25 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +78 -0
- data/vendor/eac_cli/spec/lib/eac_cli/runner_with/subcommands_spec.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/boolean.rb +31 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/common_concern.rb +4 -4
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +8 -40
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner.rb +6 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +2 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +8 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env.rb +12 -9
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/dasho_options.rb +53 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/identity_file.rb +25 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/quiet.rb +24 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/envs/ssh_env/terminal.rb +34 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/array_accessor.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/immutable/hash_accessor.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/inflector.rb +18 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +5 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/listable/value.rb +3 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/current.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/enumerator/stopped.rb +14 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/if_respond.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string.rb +4 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/inflector.rb +9 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/require_sub.rb +8 -8
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/ruby/command.rb +2 -1
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/simple_cache.rb +6 -2
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +57 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/inflector_spec.rb +15 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/current_spec.rb +26 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/enumerator/stopped_spec.rb +32 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/struct_spec.rb +46 -0
- data/vendor/ehbrs_ruby_utils/Gemfile +16 -0
- data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +20 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils.rb +7 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/executables.rb +28 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +5 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/file.rb +31 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb +21 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb +9 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb +32 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb +11 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb +40 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb +76 -0
- data/vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb +18 -0
- data/vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb +7 -0
- data/vendor/ehbrs_ruby_utils/spec/spec_helper.rb +100 -0
- metadata +77 -10
- data/vendor/eac_cli/lib/eac_cli/runner/argument_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/base_option.rb +0 -22
- data/vendor/eac_cli/lib/eac_cli/runner/boolean_option.rb +0 -13
- data/vendor/eac_cli/lib/eac_cli/runner/definition.rb +0 -64
- data/vendor/eac_cli/lib/eac_cli/runner/positional_argument.rb +0 -23
@@ -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
|
-
|
7
|
-
|
8
|
-
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
18
|
-
|
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(:
|
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
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/struct'
|
4
|
+
|
5
|
+
RSpec.describe ::EacRubyUtils::Struct do
|
6
|
+
let(:instance) { described_class.new(a: 1, b: '') }
|
7
|
+
|
8
|
+
describe '#[]' do
|
9
|
+
it { expect(instance[:a]).to eq(1) }
|
10
|
+
it { expect(instance['a']).to eq(1) }
|
11
|
+
it { expect(instance[:a?]).to eq(true) }
|
12
|
+
it { expect(instance['a?']).to eq(true) }
|
13
|
+
it { expect(instance[:b]).to eq('') }
|
14
|
+
it { expect(instance['b']).to eq('') }
|
15
|
+
it { expect(instance[:b?]).to eq(false) }
|
16
|
+
it { expect(instance['b?']).to eq(false) }
|
17
|
+
it { expect(instance[:c]).to eq(nil) }
|
18
|
+
it { expect(instance['c']).to eq(nil) }
|
19
|
+
it { expect(instance[:c?]).to eq(false) }
|
20
|
+
it { expect(instance['c?']).to eq(false) }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#fetch' do
|
24
|
+
it { expect(instance.fetch(:a)).to eq(1) }
|
25
|
+
it { expect(instance.fetch('a')).to eq(1) }
|
26
|
+
it { expect(instance.fetch(:a?)).to eq(true) }
|
27
|
+
it { expect(instance.fetch('a?')).to eq(true) }
|
28
|
+
it { expect(instance.fetch(:b)).to eq('') }
|
29
|
+
it { expect(instance.fetch('b')).to eq('') }
|
30
|
+
it { expect(instance.fetch(:b?)).to eq(false) }
|
31
|
+
it { expect(instance.fetch('b?')).to eq(false) }
|
32
|
+
it { expect { instance.fetch(:c) }.to raise_error(::KeyError) }
|
33
|
+
it { expect { instance.fetch('c') }.to raise_error(::KeyError) }
|
34
|
+
it { expect { instance.fetch(:c?) }.to raise_error(::KeyError) }
|
35
|
+
it { expect { instance.fetch('c?') }.to raise_error(::KeyError) }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#property_method' do
|
39
|
+
it { expect(instance.a).to eq(1) }
|
40
|
+
it { expect(instance.a?).to eq(true) }
|
41
|
+
it { expect(instance.b).to eq('') }
|
42
|
+
it { expect(instance.b?).to eq(false) }
|
43
|
+
it { expect { instance.c }.to raise_error(::NoMethodError) }
|
44
|
+
it { expect { instance.c? }.to raise_error(::NoMethodError) }
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Declare your gem's dependencies in users_support.gemspec.
|
6
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
7
|
+
# development dependencies will be added by default to the :development group.
|
8
|
+
gemspec
|
9
|
+
|
10
|
+
# Declare any dependencies that are still in development here instead of in
|
11
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
12
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
13
|
+
# your gem to rubygems.org.
|
14
|
+
|
15
|
+
# To use a debugger
|
16
|
+
# gem 'byebug', group: [:development, :test]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
# Maintain your gem's version:
|
6
|
+
require 'ehbrs_ruby_utils/version'
|
7
|
+
|
8
|
+
# Describe your gem and declare its dependencies:
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = 'ehbrs_ruby_utils'
|
11
|
+
s.version = ::EhbrsRubyUtils::VERSION
|
12
|
+
s.authors = ['Eduardo H. Bogoni']
|
13
|
+
s.summary = 'Utilities for EHB/RS\'s Ruby projects.'
|
14
|
+
|
15
|
+
s.files = Dir['{lib}/**/*']
|
16
|
+
|
17
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.36'
|
18
|
+
|
19
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.1', '>= 0.1.1'
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/envs'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Executables
|
8
|
+
class << self
|
9
|
+
enable_simple_cache
|
10
|
+
|
11
|
+
def env
|
12
|
+
::EacRubyUtils::Envs.local
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
{
|
18
|
+
'-version' => %w[ffprobe]
|
19
|
+
}.each do |validate_arg, commands|
|
20
|
+
commands.each do |command|
|
21
|
+
define_method("#{command}_uncached") do
|
22
|
+
env.executable(command, validate_arg)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'ehbrs_ruby_utils/executables'
|
6
|
+
require 'ehbrs_ruby_utils/videos/container/info'
|
7
|
+
|
8
|
+
module EhbrsRubyUtils
|
9
|
+
module Videos
|
10
|
+
module Container
|
11
|
+
class File
|
12
|
+
enable_simple_cache
|
13
|
+
common_constructor :path do
|
14
|
+
self.path = path.to_pathname
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def info_uncached
|
20
|
+
::EhbrsRubyUtils::Videos::Container::Info.new(
|
21
|
+
::JSON.parse(
|
22
|
+
::EhbrsRubyUtils::Executables.ffprobe.command(
|
23
|
+
'-hide_banner', '-print_format', 'json', '-show_format', '-show_streams', path
|
24
|
+
).execute!
|
25
|
+
)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/videos/container/info'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Videos
|
8
|
+
module Container
|
9
|
+
class Info
|
10
|
+
enable_simple_cache
|
11
|
+
common_constructor :ffprobe_data do
|
12
|
+
self.ffprobe_data = ffprobe_data.with_indifferent_access.freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
ffprobe_data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EhbrsRubyUtils
|
6
|
+
module Videos
|
7
|
+
class Quality
|
8
|
+
enable_simple_cache
|
9
|
+
include ::Comparable
|
10
|
+
|
11
|
+
POSITIVE_MARGIN = 0.75
|
12
|
+
LIST = [240, 480, 720, 1080, 2160].freeze
|
13
|
+
|
14
|
+
class << self
|
15
|
+
enable_simple_cache
|
16
|
+
|
17
|
+
def by_height(height)
|
18
|
+
list.find { |v| v.height == height }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def list_uncached
|
24
|
+
preceding = nil
|
25
|
+
LIST.map { |height| preceding = new(height, preceding) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :following
|
30
|
+
|
31
|
+
common_constructor :height, :preceding do
|
32
|
+
preceding&.send('following=', self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def <=>(other)
|
36
|
+
height <=> other.height
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
height.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_xs
|
44
|
+
"#{height} (Min: #{min_height}, Max: #{max_height})"
|
45
|
+
end
|
46
|
+
|
47
|
+
def resolution_match?(resolution)
|
48
|
+
(min_height.blank? || resolution.lower >= min_height) &&
|
49
|
+
(max_height.blank? || resolution.lower <= max_height)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
attr_writer :following
|
55
|
+
|
56
|
+
def max_height_uncached
|
57
|
+
following.if_present do |v|
|
58
|
+
delta = v.height - height
|
59
|
+
height + (delta * POSITIVE_MARGIN).to_i
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def min_height_uncached
|
64
|
+
preceding.if_present { |v| v.max_height + 1 }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/videos/quality'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Videos
|
8
|
+
class Resolution
|
9
|
+
enable_simple_cache
|
10
|
+
include ::Comparable
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def valid_dimension?(dimension)
|
14
|
+
dimension.is_a?(::Integer) && dimension.positive?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
common_constructor :width, :height
|
19
|
+
|
20
|
+
def <=>(other)
|
21
|
+
r = (lower <=> other.lower)
|
22
|
+
return r unless r.zero?
|
23
|
+
|
24
|
+
higher <=> other.higher
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_xs
|
28
|
+
[quality_to_s, resolution_to_s].join(' / ')
|
29
|
+
end
|
30
|
+
|
31
|
+
def higher
|
32
|
+
width > height ? width : height
|
33
|
+
end
|
34
|
+
|
35
|
+
def lower
|
36
|
+
width < height ? width : height
|
37
|
+
end
|
38
|
+
|
39
|
+
def pixels
|
40
|
+
width * height
|
41
|
+
end
|
42
|
+
|
43
|
+
def quality_to_s
|
44
|
+
quality.if_present('?', &:to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def resolution_to_s
|
48
|
+
"#{width}x#{height}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
resolution_to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def valid?
|
56
|
+
[width, height].all? { |d| self.class.valid_dimension?(d) }
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def quality_uncached
|
62
|
+
::EhbrsRubyUtils::Videos::Quality.list
|
63
|
+
.find { |quality| quality.resolution_match?(self) } ||
|
64
|
+
raise("No quality matches resolution #{resolution}")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|