ehbrs_ruby_utils 0.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 537e2854c248f49dd052e8c5d147e91bdec158c87e5a3f4e3512ccffb6f582c0
4
- data.tar.gz: 4e30ebb27a74323b21dddbc54664f3d35a0be79855296ac533945fa4eac0bf40
3
+ metadata.gz: a8add7dac8ffbafbd80e94b7fe4646a995ba5d9c5d9333fabb6e7286b13be99c
4
+ data.tar.gz: e354d52bd8717b180766dfb93204f599b2444c48aad6ff134f2de99d8b9f6288
5
5
  SHA512:
6
- metadata.gz: 21a5946909bd01741b5f921ce5d7570a3279dd09e3b1d1c40a36d2d4418ceb2eb6663087ed9d1d29a87d3e640ca75d8799722ef462a4bc312d1a56839417f299
7
- data.tar.gz: 50a2e1bf0b0b5cd786a91ea9002183ac41f8026a46787fe4d1a162c3a1e134901b9fcd49e0a587b602d38530fad1dc524d420288b3ba96e539fc576e67358a7c
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.1'
4
+ VERSION = '0.3.0'
5
5
  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,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,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
@@ -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,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
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.1
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: 2021-06-28 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
@@ -30,14 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '0.1'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 0.1.1
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
41
  - - "~>"
39
42
  - !ruby/object:Gem::Version
40
- version: '0.2'
43
+ version: '0.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.1.1
41
47
  description:
42
48
  email:
43
49
  executables: []
@@ -45,10 +51,19 @@ extensions: []
45
51
  extra_rdoc_files: []
46
52
  files:
47
53
  - lib/ehbrs_ruby_utils.rb
54
+ - lib/ehbrs_ruby_utils/executables.rb
48
55
  - lib/ehbrs_ruby_utils/version.rb
49
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
50
60
  - lib/ehbrs_ruby_utils/videos/quality.rb
51
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
52
67
  homepage:
53
68
  licenses: []
54
69
  metadata: {}
@@ -67,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
82
  - !ruby/object:Gem::Version
68
83
  version: '0'
69
84
  requirements: []
70
- rubygems_version: 3.0.9
85
+ rubygems_version: 3.0.8
71
86
  signing_key:
72
87
  specification_version: 4
73
88
  summary: Utilities for EHB/RS's Ruby projects.