ehbrs_ruby_utils 0.12.2 → 0.16.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: 54140d1a239396122b8554925ae4a09d63baa410518ed9c01dad2af0095dd1f5
4
- data.tar.gz: 22068ffc417f96c492fce8681727556acc12a8e92109492daa6f6ea6d957dcb3
3
+ metadata.gz: c3ac8dd5975edfd0256392ab446b01e88a5f61887efa7bdeea37bb58df6f7333
4
+ data.tar.gz: 8a603c090ffd6c675b9a7309da25277ac708c5840688c41a6f393a7bf6045c87
5
5
  SHA512:
6
- metadata.gz: 7f7178cf59de3f899897637b64598c81a842e0a3fb0029e411395a74049cf9a4f9aaaed7e4fba2a59fe7677b113de5d4e2543cdb2811eea018fb1fcdeb23adb0
7
- data.tar.gz: d80204e45d77da1402fd1ed65298952645c1ef22e2ae136ebda3086be5681e5861078c6dafbfb2b8832532bc5d853d0b609ad95dc5cceeb2cb03dfa2fca49c7f
6
+ metadata.gz: 15f99e542444ea740ae45d87fc2609cbf6b2142b0bdbf44740bb056934c0108459e88a75d262f8eb18fabf37575e623e7ec4e9e24a796d3a13557c55c6c192a7
7
+ data.tar.gz: 486d71cc7b0f0a62ac98c0fcc03424c01c7d43494276d24228402592262f76304bb7593a7345ff5f01aa6c7eb4a1a5a511dd143f3355f3e758a377659ee9d5fc
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/ous/artist'
5
+ require 'ehbrs_ruby_utils/music/ous/node'
6
+
7
+ module EhbrsRubyUtils
8
+ module Music
9
+ module Ous
10
+ class Album < ::EhbrsRubyUtils::Music::Ous::Node
11
+ include ::Comparable
12
+
13
+ def <=>(other)
14
+ to_a <=> other.to_a
15
+ end
16
+
17
+ def to_a
18
+ [language, category.name, artist.name, name]
19
+ end
20
+
21
+ def to_spreader_t1_path
22
+ to_a
23
+ end
24
+
25
+ def to_label
26
+ (to_a + [id]).map(&:light_white).join(' | '.blue)
27
+ end
28
+
29
+ delegate :to_path, to: :path
30
+
31
+ def id
32
+ [artist.name, name].join('_').variableize
33
+ end
34
+
35
+ # @return [EhbrsRubyUtils::Music::Ous::Artist]
36
+ def artist
37
+ parent_node
38
+ end
39
+
40
+ def category
41
+ artist.parent_node
42
+ end
43
+
44
+ def parent_node_class
45
+ ::EhbrsRubyUtils::Music::Ous::Artist
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/ous/category'
5
+ require 'ehbrs_ruby_utils/music/ous/node'
6
+
7
+ module EhbrsRubyUtils
8
+ module Music
9
+ module Ous
10
+ class Artist < ::EhbrsRubyUtils::Music::Ous::Node
11
+ def parent_node_class
12
+ ::EhbrsRubyUtils::Music::Ous::Category
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/ous/node'
5
+
6
+ module EhbrsRubyUtils
7
+ module Music
8
+ module Ous
9
+ class Category < ::EhbrsRubyUtils::Music::Ous::Node
10
+ def parent_node_class
11
+ nil
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Music
7
+ module Ous
8
+ class Node
9
+ DEFAULT_LANGUAGE = 'unk'
10
+ LANGUAGE_FILE_BASENAME = '.language'
11
+
12
+ enable_simple_cache
13
+ common_constructor :path do
14
+ self.path = path.to_pathname.expand_path
15
+ end
16
+
17
+ def name
18
+ real_path.basename.to_s
19
+ end
20
+
21
+ def language
22
+ self_language || parent_language || DEFAULT_LANGUAGE
23
+ end
24
+
25
+ def language_file
26
+ path.join(LANGUAGE_FILE_BASENAME)
27
+ end
28
+
29
+ def parent_language
30
+ parent_node.if_present(&:language)
31
+ end
32
+
33
+ def real_path
34
+ path.readlink_r
35
+ end
36
+
37
+ def self_language
38
+ language_file.if_exist('', &:read).strip.presence
39
+ end
40
+
41
+ def to_s
42
+ name
43
+ end
44
+
45
+ private
46
+
47
+ def parent_node_uncached
48
+ parent_node_class.if_present { |v| v.new(real_path.parent) }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ class SpreaderT1
7
+ module BaseLevel
8
+ extend ::Comparable
9
+
10
+ def <=>(other)
11
+ s = remaining_f <=> other.remaining_f
12
+ return s unless s.zero?
13
+
14
+ s = total_i <=> other.total_i
15
+ return s unless s.zero?
16
+
17
+ other.label <=> label
18
+ end
19
+
20
+ def remaining?
21
+ remaining_i.positive?
22
+ end
23
+
24
+ def remaining_f
25
+ remaining_i.to_f / total_i
26
+ end
27
+
28
+ def remaining_fs
29
+ ((remaining_f * 1000).round / 10.0).to_s + '%'
30
+ end
31
+
32
+ def debugs
33
+ [label, remaining_fs, total_i].join(' / ')
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/spreader_t1/base_level'
5
+ require 'ehbrs_ruby_utils/spreader_t1/item_level'
6
+
7
+ module EhbrsRubyUtils
8
+ class SpreaderT1
9
+ class GroupLevel
10
+ include ::EhbrsRubyUtils::SpreaderT1::BaseLevel
11
+ enable_simple_cache
12
+
13
+ common_constructor :label
14
+
15
+ def push(path, item)
16
+ child_path = path.dup
17
+ current = child_path.shift
18
+ if child_path.any?
19
+ push_group_level(current, child_path, item)
20
+ else
21
+ push_item_level(current, item)
22
+ end
23
+ end
24
+
25
+ def pop
26
+ children.values.max.pop
27
+ end
28
+
29
+ def pop_all
30
+ r = []
31
+ while remaining?; r << pop; end
32
+ r
33
+ end
34
+
35
+ def remaining_i
36
+ children.values.inject(0) { |a, e| a + e.remaining_i }
37
+ end
38
+
39
+ def total_i
40
+ children.values.inject(0) { |a, e| a + e.total_i }
41
+ end
42
+
43
+ private
44
+
45
+ attr_accessor :item
46
+
47
+ def push_group_level(current, child_path, item)
48
+ children[current] ||= self.class.new(current)
49
+ children[current].push(child_path, item)
50
+ end
51
+
52
+ def children
53
+ @children ||= {}
54
+ end
55
+
56
+ def push_item_level(current, item)
57
+ raise "Key \"#{current}\" already used" if children[current].present?
58
+
59
+ children[current] = ::EhbrsRubyUtils::SpreaderT1::ItemLevel.new(item)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/spreader_t1/base_level'
5
+
6
+ module EhbrsRubyUtils
7
+ class SpreaderT1
8
+ class ItemLevel
9
+ include ::EhbrsRubyUtils::SpreaderT1::BaseLevel
10
+
11
+ common_constructor :item do
12
+ self.removed = false
13
+ end
14
+
15
+ def label
16
+ item.to_s
17
+ end
18
+
19
+ def pop
20
+ raise 'Item already removed' if removed?
21
+
22
+ self.removed = true
23
+ item
24
+ end
25
+
26
+ def remaining_i
27
+ removed? ? 0 : 1
28
+ end
29
+
30
+ def removed?
31
+ @removed
32
+ end
33
+
34
+ def total_i
35
+ 1
36
+ end
37
+
38
+ private
39
+
40
+ attr_writer :removed
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ class SpreaderT1
7
+ require_sub __FILE__
8
+ common_constructor :items
9
+
10
+ # @return [Array]
11
+ def result
12
+ root_level = ::EhbrsRubyUtils::SpreaderT1::GroupLevel.new('ROOT')
13
+ items.each { |item| root_level.push(item.to_spreader_t1_path, item) }
14
+ root_level.pop_all
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.12.2'
4
+ VERSION = '0.16.0'
5
5
  end
@@ -8,7 +8,8 @@ module EhbrsRubyUtils
8
8
  module Videos
9
9
  class ConvertJob
10
10
  FORMATS_TO_EXTENSIONS = {
11
- 'matroska' => '.mkv'
11
+ 'matroska' => '.mkv',
12
+ 'mp4' => '.mp4'
12
13
  }.freeze
13
14
 
14
15
  enable_speaker
@@ -53,6 +53,10 @@ module EhbrsRubyUtils
53
53
  tags[:language]
54
54
  end
55
55
 
56
+ def language_with_title
57
+ [language, title].reject(&:blank?).if_present { |v| v.join('_').variableize }
58
+ end
59
+
56
60
  def title
57
61
  tags[:title]
58
62
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/result'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module EhbrsRubyUtils
8
+ module WebUtils
9
+ class Instance < ::Avm::Instances::Base
10
+ class Finances
11
+ class Bills
12
+ class Consume
13
+ class File
14
+ enable_speaker
15
+ enable_simple_cache
16
+ common_constructor(:bills, :path) { perform }
17
+ delegate :instance, to: :bills
18
+
19
+ protected
20
+
21
+ def perform
22
+ infov 'Relative path', relative_path
23
+ process_response
24
+ end
25
+
26
+ def relative_path
27
+ path.relative_path_from(bills.pending_directory.to_path)
28
+ end
29
+
30
+ def process_response
31
+ if response_status_result.success?
32
+ move_to_registered
33
+ else
34
+ warn(" * Retornou com status de erro:\n\n#{response.body}")
35
+ end
36
+ infov ' * Response status', response_status_result.label
37
+ end
38
+
39
+ def move_to_registered
40
+ ::FileUtils.mkdir_p(::File.dirname(target_path))
41
+ ::File.rename(path, target_path)
42
+ end
43
+
44
+ def target_path
45
+ ::File.join(bills.registered_directory, relative_path)
46
+ end
47
+
48
+ def response_uncached
49
+ bills.instance.http_request(
50
+ '/finances/file_imports',
51
+ method: :post,
52
+ body: {
53
+ 'record[file]' => ::File.new(path)
54
+ },
55
+ header: {
56
+ 'Accept' => 'application/json'
57
+ }
58
+ )
59
+ end
60
+
61
+ def response_status_result
62
+ ::Avm::Result.success_or_error(
63
+ response.status.to_s.match?(/\A2\d{2}\z/),
64
+ response.status
65
+ )
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ class Bills
11
+ class Consume
12
+ require_sub __FILE__
13
+ common_constructor(:bills)
14
+ delegate :instance, :pending_directory, :registered_directory, to: :bills
15
+
16
+ def perform
17
+ bills.pending_directory.glob('**/*').each do |path|
18
+ next unless path.file?
19
+
20
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume::File.new(self, path)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ class Bills
11
+ require_sub __FILE__
12
+ common_constructor :finances
13
+ delegate :instance, to: :finances
14
+
15
+ # @return [Pathname]
16
+ def bills_directory(suffix)
17
+ instance.read_entry('finances.bills.directory').to_pathname.join(suffix)
18
+ end
19
+
20
+ # @return [EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume]
21
+ def consume
22
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills::Consume.new(self)
23
+ end
24
+
25
+ # @return [Pathname]
26
+ def pending_directory
27
+ bills_directory('pending')
28
+ end
29
+
30
+ # @return [Pathname]
31
+ def registered_directory
32
+ bills_directory('registered')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module EhbrsRubyUtils
7
+ module WebUtils
8
+ class Instance < ::Avm::Instances::Base
9
+ class Finances
10
+ require_sub __FILE__
11
+ enable_simple_cache
12
+ common_constructor :instance
13
+
14
+ private
15
+
16
+ def bills_uncached
17
+ ::EhbrsRubyUtils::WebUtils::Instance::Finances::Bills.new(self)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -7,8 +7,14 @@ require 'httpclient'
7
7
  module EhbrsRubyUtils
8
8
  module WebUtils
9
9
  class Instance < ::Avm::Instances::Base
10
+ require_sub __FILE__
11
+
12
+ def finances
13
+ @finances ||= ::EhbrsRubyUtils::WebUtils::Instance::Finances.new(self)
14
+ end
15
+
10
16
  def root_url
11
- read_entry(:url)
17
+ read_entry(::Avm::Instances::EntryKeys::WEB_URL)
12
18
  end
13
19
 
14
20
  def resource_url(resource_url_suffix)
@@ -7,7 +7,7 @@ RSpec.describe ::EhbrsRubyUtils::Videos::Stream do
7
7
 
8
8
  def source_data(source_file)
9
9
  instance = described_class.new(::YAML.load_file(source_file))
10
- %w[codec_name codec_long_name codec_type index language title]
10
+ %w[codec_name codec_long_name codec_type index language language_with_title title]
11
11
  .map { |k| [k.to_sym, instance.send(k)] }.sort.to_h
12
12
  end
13
13
  end
@@ -4,4 +4,5 @@
4
4
  :codec_type: :attachment
5
5
  :index: 19
6
6
  :language:
7
+ :language_with_title:
7
8
  :title:
@@ -4,4 +4,5 @@
4
4
  :codec_type: :audio
5
5
  :index: 18
6
6
  :language: jpn
7
+ :language_with_title: jpn_animerg_tenshi_no_tamago_1080p_scavvykid
7
8
  :title: "[AnimeRG] Tenshi No Tamago [1080p] [ScavvyKiD]"
@@ -4,4 +4,5 @@
4
4
  :codec_type: :subtitle
5
5
  :index: 0
6
6
  :language: fre
7
+ :language_with_title: fre_french_subs
7
8
  :title: French Subs
@@ -4,4 +4,5 @@
4
4
  :codec_type: :video
5
5
  :index: 17
6
6
  :language: eng
7
+ :language_with_title: eng_animerg_tenshi_no_tamago_1080p_scavvykid
7
8
  :title: "[AnimeRG] Tenshi No Tamago [1080p] [ScavvyKiD]"
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.12.2
4
+ version: 0.16.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-11-16 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -176,9 +176,17 @@ files:
176
176
  - lib/ehbrs_ruby_utils/music/lyrics_book/album.rb
177
177
  - lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb
178
178
  - lib/ehbrs_ruby_utils/music/lyrics_book/song.rb
179
+ - lib/ehbrs_ruby_utils/music/ous/album.rb
180
+ - lib/ehbrs_ruby_utils/music/ous/artist.rb
181
+ - lib/ehbrs_ruby_utils/music/ous/category.rb
182
+ - lib/ehbrs_ruby_utils/music/ous/node.rb
179
183
  - lib/ehbrs_ruby_utils/patches.rb
180
184
  - lib/ehbrs_ruby_utils/patches/object.rb
181
185
  - lib/ehbrs_ruby_utils/patches/object/template.rb
186
+ - lib/ehbrs_ruby_utils/spreader_t1.rb
187
+ - lib/ehbrs_ruby_utils/spreader_t1/base_level.rb
188
+ - lib/ehbrs_ruby_utils/spreader_t1/group_level.rb
189
+ - lib/ehbrs_ruby_utils/spreader_t1/item_level.rb
182
190
  - lib/ehbrs_ruby_utils/version.rb
183
191
  - lib/ehbrs_ruby_utils/videos.rb
184
192
  - lib/ehbrs_ruby_utils/videos/container.rb
@@ -188,6 +196,10 @@ files:
188
196
  - lib/ehbrs_ruby_utils/videos/stream.rb
189
197
  - lib/ehbrs_ruby_utils/web_utils.rb
190
198
  - lib/ehbrs_ruby_utils/web_utils/instance.rb
199
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances.rb
200
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills.rb
201
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume.rb
202
+ - lib/ehbrs_ruby_utils/web_utils/instance/finances/bills/consume/file.rb
191
203
  - lib/ehbrs_ruby_utils/web_utils/videos.rb
192
204
  - lib/ehbrs_ruby_utils/web_utils/videos/file.rb
193
205
  - lib/ehbrs_ruby_utils/web_utils/videos/file/rename.rb