ehbrs-tools 0.14.1 → 0.15.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/runner/web_utils.rb +26 -0
- data/lib/ehbrs/runner/web_utils/videos.rb +20 -0
- data/lib/ehbrs/runner/web_utils/videos/download.rb +66 -0
- data/lib/ehbrs/runner/web_utils/videos/upload.rb +78 -0
- data/lib/ehbrs/tools/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- 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
- metadata +10 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87fd9ce05b53ed04fcdfdc72f50a9aee263e95816935bfdb796239c2a0312f6
|
4
|
+
data.tar.gz: 3b1374c1fdc8d761ac9a23632f16ba132bcab34f08541f5eab7a28d5138fedad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c2621390f1c3cffff8f0bfe37f5a0569b0e4458558eedb7031a39274429f14e10a882be05d6abfbbc65c1eec776f3bf47be806b25ca649b650bc933a216f1a
|
7
|
+
data.tar.gz: 0df896b884307cbddddb8949e88c3f4125c8b4e4c2ddd88c42561e00bf632bb29a5308a94bdf5cff5a57abbce93339c8df36839940ee616d2e98c6b3de3f5862
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
require 'ehbrs_ruby_utils/web_utils/instance'
|
6
|
+
|
7
|
+
module Ehbrs
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class WebUtils < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
runner_with
|
11
|
+
require_sub __FILE__
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
desc 'Ferramentas para EHB/RS Utils.'
|
15
|
+
pos_arg :'instance-id'
|
16
|
+
subcommands
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def instance_uncached
|
22
|
+
::EhbrsRubyUtils::WebUtils::Instance.by_id(options.fetch('<instance-id>'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
|
6
|
+
module Ehbrs
|
7
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
8
|
+
class WebUtils < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class Videos < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
runner_with
|
11
|
+
require_sub __FILE__
|
12
|
+
|
13
|
+
runner_definition do
|
14
|
+
desc 'Ferramentas de vídeos para EHB/RS Utils.'
|
15
|
+
subcommands
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/web_utils/videos/file'
|
5
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
6
|
+
|
7
|
+
module Ehbrs
|
8
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
9
|
+
class WebUtils < ::EacRubyUtils::Console::DocoptRunner
|
10
|
+
class Videos < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
class Download < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
runner_with
|
13
|
+
|
14
|
+
runner_definition do
|
15
|
+
desc 'Importa informações de arquivos de vídeo de uma instância EHB/RS Utils.'
|
16
|
+
bool_opt '-c', '--confirm', 'Confirma as mudanças'
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
start_banner
|
21
|
+
to_rename.each { |file| process_rename_file(file) }
|
22
|
+
to_delete.each { |file| process_delete_file(file) }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def start_banner
|
28
|
+
infov 'Files downloaded', files.count
|
29
|
+
infov 'To rename', to_rename.count
|
30
|
+
infov 'To delete', to_delete.count
|
31
|
+
end
|
32
|
+
|
33
|
+
def process_rename_file(file)
|
34
|
+
infov " * #{file.new_path}", file.original_path
|
35
|
+
file.rename if options.fetch('--confirm')
|
36
|
+
end
|
37
|
+
|
38
|
+
def process_delete_file(file)
|
39
|
+
infov " * #{file.new_path}", 'REMOVE'
|
40
|
+
file.remove if options.fetch('--confirm')
|
41
|
+
end
|
42
|
+
|
43
|
+
def files_uncached
|
44
|
+
data.map { |file_data| ::EhbrsRubyUtils::WebUtils::Videos::File.new(file_data) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_rename_uncached
|
48
|
+
files.select(&:path_changed?)
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_delete_uncached
|
52
|
+
files.reject { |f| f.type == 'Videos::SeriesDirectory' }.select(&:unwanted)
|
53
|
+
end
|
54
|
+
|
55
|
+
def data_uncached
|
56
|
+
::JSON.parse(raw_content)
|
57
|
+
end
|
58
|
+
|
59
|
+
def raw_content
|
60
|
+
context(:instance).http_request('/videos/files/export').body
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_cli/core_ext'
|
4
|
+
require 'eac_ruby_utils/console/docopt_runner'
|
5
|
+
require 'ehbrs_ruby_utils/web_utils/videos/files_list'
|
6
|
+
require 'json'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
module Ehbrs
|
10
|
+
class Runner < ::EacRubyUtils::Console::DocoptRunner
|
11
|
+
class WebUtils < ::EacRubyUtils::Console::DocoptRunner
|
12
|
+
class Videos < ::EacRubyUtils::Console::DocoptRunner
|
13
|
+
class Upload < ::EacRubyUtils::Console::DocoptRunner
|
14
|
+
runner_with
|
15
|
+
|
16
|
+
runner_definition do
|
17
|
+
desc 'Exporta informações de arquivos de vídeo para uma instância EHB/RS Utils.'
|
18
|
+
bool_opt '-P', '--no-ffprobe', 'Não recupera dados com "ffprobe".'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
%w[movies series].each { |type| upload_files_list(type) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def upload_files_list(type)
|
26
|
+
infom "Uploading \"#{type}\" files list..."
|
27
|
+
files_list_path = send("#{type}_files_list")
|
28
|
+
infov 'Path', files_list_path
|
29
|
+
process_response(upload_request(files_list_path))
|
30
|
+
end
|
31
|
+
|
32
|
+
def upload_request(files_list_path)
|
33
|
+
context(:instance).http_request(
|
34
|
+
'/videos/files/import',
|
35
|
+
method: :put,
|
36
|
+
body: {
|
37
|
+
'videos_tableless_local_import_list[list_file]' => ::File.new(files_list_path)
|
38
|
+
},
|
39
|
+
header: {
|
40
|
+
'Accept' => 'application/json'
|
41
|
+
}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_response(response)
|
46
|
+
infov 'Response status', response.status
|
47
|
+
if response.status == 200
|
48
|
+
pp ::JSON.parse(response.body) # rubocop:disable Rails/Output
|
49
|
+
else
|
50
|
+
error_file = '/tmp/ehbrsutils.html'
|
51
|
+
::File.write(error_file, response.body)
|
52
|
+
system('firefox', error_file)
|
53
|
+
fatal_error('Retornou com status de erro: ' + error_file)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def series_files_list_uncached
|
58
|
+
write_files_list('Videos::SeriesDirectory', :series_directory)
|
59
|
+
end
|
60
|
+
|
61
|
+
def movies_files_list_uncached
|
62
|
+
write_files_list('Videos::MovieFile', :movies_directory)
|
63
|
+
end
|
64
|
+
|
65
|
+
def write_files_list(file_class, read_entry)
|
66
|
+
files_list = ::EhbrsRubyUtils::WebUtils::Videos::FilesList.new(
|
67
|
+
file_class,
|
68
|
+
context(:instance).read_entry(read_entry),
|
69
|
+
ffprobe: !options.fetch('--no-ffprobe')
|
70
|
+
)
|
71
|
+
infov 'Files found', files_list.data.fetch(:files).count
|
72
|
+
files_list.write_to
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/ehbrs/tools/version.rb
CHANGED
@@ -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,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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ehbrs-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
@@ -124,6 +124,10 @@ files:
|
|
124
124
|
- lib/ehbrs/runner/videos/series.rb
|
125
125
|
- lib/ehbrs/runner/videos/series/rename.rb
|
126
126
|
- lib/ehbrs/runner/videos/unsupported.rb
|
127
|
+
- lib/ehbrs/runner/web_utils.rb
|
128
|
+
- lib/ehbrs/runner/web_utils/videos.rb
|
129
|
+
- lib/ehbrs/runner/web_utils/videos/download.rb
|
130
|
+
- lib/ehbrs/runner/web_utils/videos/upload.rb
|
127
131
|
- lib/ehbrs/self.rb
|
128
132
|
- lib/ehbrs/self/observers/used_space.rb
|
129
133
|
- lib/ehbrs/self/observers/with_persistence.rb
|
@@ -415,6 +419,11 @@ files:
|
|
415
419
|
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container/info.rb
|
416
420
|
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/quality.rb
|
417
421
|
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/resolution.rb
|
422
|
+
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils.rb
|
423
|
+
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/instance.rb
|
424
|
+
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos.rb
|
425
|
+
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/file.rb
|
426
|
+
- vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb
|
418
427
|
- vendor/ehbrs_ruby_utils/spec/lib/ehbrs_ruby_utils/videos/resolution_spec.rb
|
419
428
|
- vendor/ehbrs_ruby_utils/spec/rubocop_check_spec.rb
|
420
429
|
- vendor/ehbrs_ruby_utils/spec/spec_helper.rb
|