ehbrs_ruby_utils 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c9c60e0e61be16ec0c161bf3b4d90f730801e7f6db236eb77ea9fd866064d84
4
- data.tar.gz: 007b8112c7699c7558bc04a58a1b1a96ea3c6092c985f342a9d6af68006ea6de
3
+ metadata.gz: a8add7dac8ffbafbd80e94b7fe4646a995ba5d9c5d9333fabb6e7286b13be99c
4
+ data.tar.gz: e354d52bd8717b180766dfb93204f599b2444c48aad6ff134f2de99d8b9f6288
5
5
  SHA512:
6
- metadata.gz: 13745fd4234de95f716e1403a2e18394b8db6fdb6a0440dd12038a08842f64c1b988c418466331e8a6c1540576b42ac112c68e69e8570a38414454f204e830e0
7
- data.tar.gz: 5be54f132eb69c59096313862e0a3a5b332db85712aa818c8a53e66d714c40d19233da33eb1323cb33bc501ae28d9dd8763cb88c808d4754da857c9b89eba387
6
+ metadata.gz: 26d1cf45a73c8789e61566f18ff183cc15788865d347b57901e521baadc94a7919818b795d132d9a53fdb4efd3c2ab363171ffdf4477c2416f75ed7551fde906
7
+ data.tar.gz: ea2f124e1923f2ef17b35e78b4b72a5ba6bef3715c9fca7ce547901f31fe8267d477cec229fcbc7cb8e293f88d64bfe393b177dd5d231fdccf66d39b82662505
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Videos
7
+ module Container
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ 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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module WebUtils
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -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,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module WebUtils
7
+ module Videos
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ 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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ehbrs_ruby_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_ruby_utils
@@ -51,10 +51,19 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - lib/ehbrs_ruby_utils.rb
54
+ - lib/ehbrs_ruby_utils/executables.rb
54
55
  - lib/ehbrs_ruby_utils/version.rb
55
56
  - lib/ehbrs_ruby_utils/videos.rb
57
+ - lib/ehbrs_ruby_utils/videos/container.rb
58
+ - lib/ehbrs_ruby_utils/videos/container/file.rb
59
+ - lib/ehbrs_ruby_utils/videos/container/info.rb
56
60
  - lib/ehbrs_ruby_utils/videos/quality.rb
57
61
  - lib/ehbrs_ruby_utils/videos/resolution.rb
62
+ - lib/ehbrs_ruby_utils/web_utils.rb
63
+ - lib/ehbrs_ruby_utils/web_utils/instance.rb
64
+ - lib/ehbrs_ruby_utils/web_utils/videos.rb
65
+ - lib/ehbrs_ruby_utils/web_utils/videos/file.rb
66
+ - lib/ehbrs_ruby_utils/web_utils/videos/files_list.rb
58
67
  homepage:
59
68
  licenses: []
60
69
  metadata: {}
@@ -73,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
82
  - !ruby/object:Gem::Version
74
83
  version: '0'
75
84
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.7.7
85
+ rubygems_version: 3.0.8
78
86
  signing_key:
79
87
  specification_version: 4
80
88
  summary: Utilities for EHB/RS's Ruby projects.