ehbrs_ruby_utils 0.11.0 → 0.13.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: 230878af735547a11e32b70f8c142dcc5adb581ea9b00ced816b7944b16ca532
4
- data.tar.gz: e28ef687a67b61e17066721e725cfdb6fe8daa62f886e513f1750f4a013a4835
3
+ metadata.gz: 5aaed3c96601c1f0e58b967d6329f6f78b9e4c4b71af95a938c7315cceaf33dd
4
+ data.tar.gz: 07aa64f3b9f8681a497e803fd6a5dd750efb8d334953b82e51ec56b96835a36b
5
5
  SHA512:
6
- metadata.gz: 9663bc98612d1f83e1654a3f518c6319d12395528c01392049360fc2eca89c727e7c5e8d4acfec04ba8062bf6601cbebc45576203ac78adf3f15b3826c303d67
7
- data.tar.gz: '0805245a0e679bfdeeb3be0d621acd8daa5765042e697922d6e75c69f9d58c8fed91e7722ea4903cf3f97106a10b737a950f5f02210c3d6d2c2d5aff2dbba752'
6
+ metadata.gz: fb8e0db71d2926730c2ac6850769bc5f93965a42480c8fabfdaaeaeef65c5317bc5bb445e38aee185fe226dcd46c6dcc0f9287ee1a3e82b576d7e2239cb173e5
7
+ data.tar.gz: 07e0d381377ba0678607414120e349211a1e09bd5ba02ac71acb4e069da6e33ca202eb383b0dc7d18306516cd987b24213c9a821e140197008743b6a09bc699c
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/patches'
5
+ require 'ehbrs_ruby_utils/patches'
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/files/info'
3
+ require 'eac_fs/file_info'
4
4
  require 'eac_ruby_utils/core_ext'
5
5
 
6
6
  module EhbrsRubyUtils
7
7
  module Fs
8
- class CompressedPackage < ::Avm::Files::Info
8
+ class CompressedPackage < ::EacFs::FileInfo
9
9
  MIME_TYPES = {
10
10
  'application/zip' => :zip,
11
11
  'application/x-7z-compressed' => :sevenzip,
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
7
7
  module Fs
8
8
  class Selected
9
9
  class Build
10
- DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |basename| basename }
10
+ DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |path| path.basename.to_path }
11
11
 
12
12
  attr_reader :selected, :target_dir, :target_basename_proc
13
13
 
@@ -19,7 +19,7 @@ module EhbrsRubyUtils
19
19
  end
20
20
 
21
21
  def target_basename
22
- build.target_basename_proc.call(path.basename.to_path)
22
+ build.target_basename_proc.call(path)
23
23
  end
24
24
  end
25
25
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_fs/traverser'
3
4
  require 'eac_ruby_utils/core_ext'
4
5
 
5
6
  module EhbrsRubyUtils
@@ -16,8 +17,8 @@ module EhbrsRubyUtils
16
17
  self.options = self.class.lists.option.hash_keys_validate!(options)
17
18
  end
18
19
 
19
- def build(target_dir)
20
- ::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir)
20
+ def build(target_dir, &directory_target_basename)
21
+ ::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir, &directory_target_basename)
21
22
  end
22
23
 
23
24
  def filename
@@ -28,7 +29,16 @@ module EhbrsRubyUtils
28
29
 
29
30
  # @return [Pathname]
30
31
  def found_uncached
31
- root_path.glob("**/#{filename}").map(&:parent).sort
32
+ r = []
33
+ ft = ::EacFs::Traverser.new(
34
+ recursive: true,
35
+ hidden_directories: true,
36
+ check_file: lambda do |file|
37
+ r << file.parent if file.basename.to_path == filename.to_s
38
+ end
39
+ )
40
+ ft.check_path(root_path)
41
+ r.sort
32
42
  end
33
43
  end
34
44
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/lyrics_book/resource'
5
+
6
+ module EhbrsRubyUtils
7
+ module Music
8
+ class LyricsBook
9
+ class Album < ::EhbrsRubyUtils::Music::LyricsBook::Resource
10
+ enable_simple_cache
11
+
12
+ def book
13
+ parent
14
+ end
15
+
16
+ def first_previous
17
+ previous.if_present { |v| v.songs.last }
18
+ end
19
+
20
+ def valid?
21
+ songs.any?
22
+ end
23
+
24
+ def header_title
25
+ "#{songs.first.number}-#{songs.last.number} | #{artist} | #{title}"
26
+ end
27
+
28
+ def artist
29
+ songs.lazy.map { |v| v.tag.artist }.find(&:present?)
30
+ end
31
+
32
+ def title
33
+ songs.lazy.map { |v| v.tag.album }.find(&:present?)
34
+ end
35
+
36
+ def songs_uncached
37
+ ::EhbrsRubyUtils::Music::LyricsBook::Song.create_list(self, path.children)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Music
7
+ class LyricsBook
8
+ class Resource
9
+ class << self
10
+ def create_list(parent, files)
11
+ r = files.sort.map { |path| new(parent, path) }.select(&:valid?)
12
+ previous = parent.first_previous
13
+ r.map do |e|
14
+ e.reset_cache
15
+ e.previous = previous
16
+ previous = e
17
+ end
18
+ end
19
+ end
20
+
21
+ enable_simple_cache
22
+ include ::Comparable
23
+ common_constructor :parent, :path
24
+ attr_accessor :previous
25
+
26
+ def filename
27
+ path.relative_path_from(parent.path)
28
+ end
29
+
30
+ def <=>(other)
31
+ path <=> other.path
32
+ end
33
+
34
+ def link_to_header
35
+ "<a href=\"\##{header_id}\" id=\"#{index_id}\">#{header_title}</a>"
36
+ end
37
+
38
+ def index_id
39
+ "index_#{header_id}"
40
+ end
41
+
42
+ def header_id
43
+ header_title.variableize
44
+ end
45
+
46
+ def header_index
47
+ parent.header_index + 1
48
+ end
49
+
50
+ def output_main
51
+ ::EhbrsRubyUtils::Music::LyricsBook::Resource.erb_template('main.html.erb', binding)
52
+ end
53
+
54
+ def output_index
55
+ erb_template('index.html.erb')
56
+ end
57
+
58
+ def type
59
+ self.class.name.demodulize.underscore
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+ require 'ehbrs_ruby_utils/music/lyrics_book/resource'
5
+
6
+ module EhbrsRubyUtils
7
+ module Music
8
+ class LyricsBook
9
+ class Song < ::EhbrsRubyUtils::Music::LyricsBook::Resource
10
+ enable_simple_cache
11
+ delegate :book, to: :album
12
+ delegate :provider, to: :book
13
+ delegate :tag, :to_s, to: :container
14
+
15
+ def album
16
+ parent
17
+ end
18
+
19
+ def lyrics
20
+ fetch_lyrics unless lyrics_cached?
21
+ cached_lyrics
22
+ end
23
+
24
+ def valid?
25
+ tag.present?
26
+ end
27
+
28
+ def lyrics_cached?
29
+ lyrics_cache.cached?
30
+ end
31
+
32
+ def cached_lyrics
33
+ ::YAML.load_file(lyrics_cache.content_path)
34
+ end
35
+
36
+ def header_title
37
+ "#{number} - #{title}"
38
+ end
39
+
40
+ delegate :title, to: :tag
41
+
42
+ private
43
+
44
+ def container_uncached
45
+ ::EhbrsRubyUtils::Videos::Container.new(path)
46
+ end
47
+
48
+ def fetch_lyrics
49
+ lyrics = fetched_lyrics
50
+ lyrics_cache.write(lyrics.to_yaml)
51
+ end
52
+
53
+ def fetched_lyrics
54
+ container.lyrics_by_provider(provider)
55
+ end
56
+
57
+ def lyrics_cache
58
+ (%w[artist album title].map { |k| tag.send(k) } + [provider.identifier])
59
+ .inject(fs_cache) { |a, e| a.child(e) }
60
+ end
61
+
62
+ def number_uncached
63
+ previous.if_present(0, &:number) + 1
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ehbrs_ruby_utils/core_ext'
4
+
5
+ module EhbrsRubyUtils
6
+ module Music
7
+ class LyricsBook
8
+ require_sub __FILE__
9
+
10
+ DEFAULT_PROVIDER_NAME = 'lyrics.com'
11
+ DEFAULT_TITLE = 'Letras de músicas'
12
+
13
+ enable_listable
14
+ lists.add_symbol :option, :provider_name, :title
15
+ enable_simple_cache
16
+ common_constructor :source_dir, :options, default: [{}] do
17
+ self.source_dir = source_dir.to_pathname
18
+ self.options = self.class.lists.option.hash_keys_validate!(options)
19
+ end
20
+
21
+ def first_previous
22
+ nil
23
+ end
24
+
25
+ def header_index
26
+ 1
27
+ end
28
+
29
+ def output
30
+ erb_template('main.html.erb')
31
+ end
32
+
33
+ def path
34
+ source_dir
35
+ end
36
+
37
+ def title
38
+ options[OPTION_TITLE].if_present(DEFAULT_TITLE)
39
+ end
40
+
41
+ private
42
+
43
+ def albums_directories_uncached
44
+ r = []
45
+ t = ::EacFs::Traverser.new
46
+ t.recursive = true
47
+ t.check_directory = ->(directory) { r << directory }
48
+ t.check_path(source_dir)
49
+ r
50
+ end
51
+
52
+ def albums_uncached
53
+ ::EhbrsRubyUtils::Music::LyricsBook::Album.create_list(self, albums_directories)
54
+ end
55
+
56
+ def provider_uncached
57
+ ::UltimateLyrics::Provider.by_name(provider_name)
58
+ end
59
+
60
+ def provider_name
61
+ options[OPTION_PROVIDER_NAME].if_present(DEFAULT_PROVIDER_NAME)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+ ::EacRubyUtils.require_sub __FILE__
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EhbrsRubyUtils
4
- VERSION = '0.11.0'
4
+ VERSION = '0.13.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
@@ -0,0 +1,3 @@
1
+ <% songs.each do |song| %>
2
+ <%= song.output_main %>
3
+ <% end %>
@@ -0,0 +1,15 @@
1
+ .album h2 {
2
+ background-color: lightgoldenrodyellow;
3
+ text-align: center;
4
+ }
5
+
6
+ .song {
7
+ margin-top: 4.0em;
8
+ }
9
+
10
+ .filename {
11
+ display: block;
12
+ font-size: small;
13
+ text-align: right;
14
+ font-style: italic;
15
+ }
@@ -0,0 +1,14 @@
1
+ <div class="index" >
2
+ <ul>
3
+ <% albums.each do |album| %>
4
+ <li>
5
+ <%= album.link_to_header %>
6
+ <ul>
7
+ <% album.songs.each do |song| %>
8
+ <li><%= song.link_to_header %></li>
9
+ <% end %>
10
+ </ul>
11
+ </li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
@@ -0,0 +1,24 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
8
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
10
+ <style>
11
+ <%= template.child('custom_style.css').content %>
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <div class="container" >
16
+ <h1><%= title %></h1>
17
+ <h2>Índice</h2>
18
+ <%= erb_template('index.html.erb') %>
19
+ <% albums.each do |album| %>
20
+ <%= album.output_main %>
21
+ <% end %>
22
+ </div>
23
+ </body>
24
+ </html>
@@ -0,0 +1,8 @@
1
+ <div class="<%= type %>">
2
+ <h<%= header_index %> id='<%= header_id %>' >
3
+ <%= header_title %>
4
+ <a href="#<%= index_id %>" ><i class="bi-arrow-up-circle-fill"></i></a>
5
+ </h<%= header_index %>>
6
+ <span class="filename"><%= filename %></span>
7
+ <%= erb_template('inner.html.erb') %>
8
+ </div>
@@ -0,0 +1,9 @@
1
+ <% if lyrics.found? %>
2
+ <p class="lyrics">
3
+ <% lyrics.text.each_line do |line| %>
4
+ <%= line.strip %><br/>
5
+ <% end %>
6
+ </p>
7
+ <% else %>
8
+ <p><em>Letra indisponível.</em></p>
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.11.0
4
+ version: 0.13.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-09-22 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -50,6 +50,20 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.3.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: eac_fs
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.5'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.5'
53
67
  - !ruby/object:Gem::Dependency
54
68
  name: eac_ruby_utils
55
69
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +163,7 @@ files:
149
163
  - ".rspec"
150
164
  - ".rubocop.yml"
151
165
  - lib/ehbrs_ruby_utils.rb
166
+ - lib/ehbrs_ruby_utils/core_ext.rb
152
167
  - lib/ehbrs_ruby_utils/executables.rb
153
168
  - lib/ehbrs_ruby_utils/finances/bb_browser/docker_image.rb
154
169
  - lib/ehbrs_ruby_utils/fs.rb
@@ -157,6 +172,12 @@ files:
157
172
  - lib/ehbrs_ruby_utils/fs/selected/build.rb
158
173
  - lib/ehbrs_ruby_utils/fs/selected/build_file.rb
159
174
  - lib/ehbrs_ruby_utils/music.rb
175
+ - lib/ehbrs_ruby_utils/music/lyrics_book.rb
176
+ - lib/ehbrs_ruby_utils/music/lyrics_book/album.rb
177
+ - lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb
178
+ - lib/ehbrs_ruby_utils/music/lyrics_book/song.rb
179
+ - lib/ehbrs_ruby_utils/patches.rb
180
+ - lib/ehbrs_ruby_utils/patches/object.rb
160
181
  - lib/ehbrs_ruby_utils/patches/object/template.rb
161
182
  - lib/ehbrs_ruby_utils/version.rb
162
183
  - lib/ehbrs_ruby_utils/videos.rb
@@ -188,6 +209,12 @@ files:
188
209
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/README.md
189
210
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/context/firefox.service
190
211
  - template/ehbrs_ruby_utils/finances/bb_browser/docker_image/context/startbrowser.sh
212
+ - template/ehbrs_ruby_utils/music/lyrics_book/album/inner.html.erb
213
+ - template/ehbrs_ruby_utils/music/lyrics_book/custom_style.css
214
+ - template/ehbrs_ruby_utils/music/lyrics_book/index.html.erb
215
+ - template/ehbrs_ruby_utils/music/lyrics_book/main.html.erb
216
+ - template/ehbrs_ruby_utils/music/lyrics_book/resource/main.html.erb
217
+ - template/ehbrs_ruby_utils/music/lyrics_book/song/inner.html.erb
191
218
  homepage:
192
219
  licenses: []
193
220
  metadata: {}