ehbrs-tools 0.25.1 → 0.28.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +60 -22
- data/lib/ehbrs/{core_ext.rb → tools/core_ext.rb} +0 -0
- data/lib/ehbrs/tools/runner/finances/bb_browser.rb +1 -1
- data/lib/ehbrs/tools/runner/fs/selected.rb +19 -26
- data/lib/ehbrs/tools/runner/music/lyrics.rb +68 -0
- data/lib/ehbrs/tools/runner/music/lyrics_book.rb +41 -0
- data/lib/ehbrs/tools/runner/music/selected.rb +6 -6
- data/lib/ehbrs/tools/runner/web_utils/videos/upload.rb +1 -1
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/user_dirs.rb +2 -2
- data/lib/ehbrs/videos/extract/package.rb +2 -2
- data/lib/ehbrs/videos/extract/package_file.rb +0 -1
- data/spec/lib/ehbrs/tools/runner/fs/used_space_spec.rb +2 -1
- data/vendor/aranha-parsers/aranha-parsers.gemspec +1 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/rspec/setup.rb +1 -1
- data/vendor/aranha-parsers/lib/aranha/parsers/rspec/{source_target_fixtures_example.rb → shared_examples/source_target_fixtures.rb} +0 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/fetch_content_error.rb +10 -0
- data/vendor/aranha-parsers/lib/aranha/parsers/source_address/http_get.rb +15 -2
- data/vendor/aranha-parsers/lib/aranha/parsers/version.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +9 -1
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +6 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help/builder.rb +3 -3
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +6 -5
- data/vendor/eac_fs/Gemfile +5 -0
- data/vendor/eac_fs/eac_fs.gemspec +20 -0
- data/vendor/{eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb → eac_fs/lib/eac_fs/cache.rb} +7 -2
- data/vendor/eac_fs/lib/eac_fs/file_info.rb +24 -0
- data/vendor/eac_fs/lib/eac_fs/patches/module/fs_cache.rb +10 -0
- data/vendor/eac_fs/lib/eac_fs/patches/module.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/patches/object/fs_cache.rb +10 -0
- data/vendor/eac_fs/lib/eac_fs/patches/object.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/patches/pathname/info.rb +12 -0
- data/vendor/eac_fs/lib/eac_fs/patches/pathname.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/patches.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/version.rb +5 -0
- data/vendor/eac_fs/lib/eac_fs.rb +7 -0
- data/vendor/{eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb → eac_fs/spec/lib/eac_fs/cache_spec.rb} +2 -2
- data/vendor/eac_fs/spec/rubocop_spec.rb +3 -0
- data/vendor/eac_fs/spec/spec_helper.rb +4 -0
- data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +2 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +3 -3
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/core_ext.rb +1 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +16 -7
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_gems_utils/Gemfile +5 -0
- data/vendor/eac_ruby_gems_utils/LICENCE +16 -0
- data/vendor/eac_ruby_gems_utils/README.rdoc +3 -0
- data/vendor/eac_ruby_gems_utils/eac_ruby_gems_utils.gemspec +30 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/command.rb +33 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +41 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +97 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb +58 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/minitest.rb +25 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +48 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/result.rb +25 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +84 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/rspec.rb +21 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests.rb +9 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +5 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils.rb +7 -0
- data/vendor/eac_ruby_gems_utils/spec/code/rubocop_check_spec.rb +3 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb +14 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb +7 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem_spec.rb +20 -0
- data/vendor/eac_ruby_gems_utils/spec/spec_helper.rb +4 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/Gemfile +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/Gemfile.lock +19 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/Rakefile +14 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/exe/myrunner +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/lib/mygem/version.rb +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/lib/mygem.rb +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/mygem.gemspec +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/compact.rb +22 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/object/compact.rb +20 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/patches/string/delimited.rb +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/string_delimited.rb +70 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/compact_spec.rb +20 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/object/compact_spec.rb +20 -0
- data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/string/delimited_spec.rb +34 -0
- data/vendor/eac_templates/Gemfile +5 -0
- data/vendor/eac_templates/eac_templates.gemspec +19 -0
- data/vendor/eac_templates/lib/eac_templates/directory.rb +108 -0
- data/vendor/eac_templates/lib/eac_templates/file.rb +48 -0
- data/vendor/eac_templates/lib/eac_templates/patches/module/erb_template.rb +9 -0
- data/vendor/eac_templates/lib/eac_templates/patches/module/template.rb +10 -0
- data/vendor/eac_templates/lib/eac_templates/patches/module.rb +4 -0
- data/vendor/eac_templates/lib/eac_templates/patches/object/erb_template.rb +9 -0
- data/vendor/eac_templates/lib/eac_templates/patches/object/template.rb +9 -0
- data/vendor/eac_templates/lib/eac_templates/patches/object.rb +4 -0
- data/vendor/eac_templates/lib/eac_templates/patches.rb +4 -0
- data/vendor/eac_templates/lib/eac_templates/searcher.rb +53 -0
- data/vendor/eac_templates/lib/eac_templates/variable_not_found_error.rb +5 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/base.rb +21 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/config_reader.rb +27 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/entries_reader.rb +23 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/generic.rb +23 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/hash.rb +27 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers.rb +23 -0
- data/vendor/eac_templates/lib/eac_templates/version.rb +5 -0
- data/vendor/eac_templates/lib/eac_templates.rb +7 -0
- data/vendor/eac_templates/spec/lib/eac_templates/file_spec.rb +35 -0
- data/vendor/eac_templates/spec/lib/eac_templates/file_spec_files/expected_content +2 -0
- data/vendor/eac_templates/spec/lib/eac_templates/file_spec_files/source.template +2 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec.rb +30 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file1.template +1 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file2 +1 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path2/subdir1/file3.template +1 -0
- data/vendor/eac_templates/spec/lib/object/template_spec.rb +23 -0
- data/vendor/eac_templates/spec/lib/object/template_spec_files/path/my_stub_with_template +1 -0
- data/vendor/eac_templates/spec/rubocop_spec.rb +3 -0
- data/vendor/eac_templates/spec/spec_helper.rb +4 -0
- data/vendor/ehbrs_ruby_utils/ehbrs_ruby_utils.gemspec +4 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/core_ext.rb +5 -0
- data/{lib/ehbrs → vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils}/fs/compressed_package.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build.rb +41 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build_file.rb +27 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected.rb +35 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs.rb +10 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/album.rb +42 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb +64 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/song.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book.rb +65 -0
- data/{lib/ehbrs/fs.rb → vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music.rb} +2 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/patches/object.rb +4 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/patches.rb +4 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/container.rb +31 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/videos/stream.rb +1 -1
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/album/inner.html.erb +3 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/custom_style.css +15 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/index.html.erb +14 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/main.html.erb +24 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/resource/main.html.erb +8 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/song/inner.html.erb +9 -0
- data/vendor/ultimate_lyrics/Gemfile +5 -0
- data/vendor/ultimate_lyrics/bin/download_parser_spec_files.rb +94 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/field.rb +83 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/lyrics.rb +13 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/parser.rb +28 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider/exclude_item.rb +17 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider/extract_item.rb +21 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider/item.rb +48 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider/replace_fields.rb +13 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider/rule.rb +52 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider/url_format.rb +21 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider.rb +96 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider_search.rb +43 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/providers_data.xml +356 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/song_metadata/field.rb +24 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/song_metadata.rb +28 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/version.rb +5 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics.rb +7 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec.rb +20 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__michael_jackson_thriller.source.html +8 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__michael_jackson_thriller.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__michael_jackson_thriller.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__milton_nascimento_rouxinol.source.html +8 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__milton_nascimento_rouxinol.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__milton_nascimento_rouxinol.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.source.html +193 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.source.html +193 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__michael_jackson_thriller.source.html +87 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__michael_jackson_thriller.target.yaml +36 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__michael_jackson_thriller.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__milton_nascimento_rouxinol.source.html +4 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__milton_nascimento_rouxinol.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__milton_nascimento_rouxinol.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__michael_jackson_thriller.source.html +2 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__michael_jackson_thriller.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__michael_jackson_thriller.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__milton_nascimento_rouxinol.source.html +2 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__milton_nascimento_rouxinol.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__milton_nascimento_rouxinol.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.source.html +101 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.source.html +29 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.source.html +29 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.source.html +1301 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.target.yaml +3 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.url +1 -0
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/provider_search_spec.rb +72 -0
- data/vendor/ultimate_lyrics/spec/rubocop_spec.rb +3 -0
- data/vendor/ultimate_lyrics/spec/spec_helper.rb +4 -0
- data/vendor/ultimate_lyrics/ultimate_lyrics.gemspec +21 -0
- metadata +170 -13
- data/lib/ehbrs/patches/module/erb_template.rb +0 -11
- data/lib/ehbrs/patches/object/erb_template.rb +0 -9
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +0 -12
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module UltimateLyrics
|
6
|
+
class Parser
|
7
|
+
common_constructor :provider, :original_content
|
8
|
+
|
9
|
+
def original_content_invalid?
|
10
|
+
provider.invalid_indicators.any? { |v| original_content.include?(v) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def result
|
14
|
+
return nil if original_content_invalid?
|
15
|
+
|
16
|
+
sanitize_text(provider.rules.inject(original_content) { |a, e| e.apply(a) })
|
17
|
+
end
|
18
|
+
|
19
|
+
def sanitize_text(text)
|
20
|
+
r = text.to_s.gsub("\t", ' ').gsub("\r", '').gsub(/ +/, ' ').gsub(/\n{2,}/m, "\n\n").strip
|
21
|
+
r.present? ? "#{r}\n" : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def url?
|
25
|
+
provider.extract_rules.any?(&:url?)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ultimate_lyrics/provider/item'
|
4
|
+
|
5
|
+
module UltimateLyrics
|
6
|
+
class Provider
|
7
|
+
class ExcludeItem < ::UltimateLyrics::Provider::Item
|
8
|
+
def apply_from_delimiters(source)
|
9
|
+
source.delimited_without_outer(begin_with, end_with)
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply_from_tag(source)
|
13
|
+
source.delimited_without_outer(tag, "</#{tag_name}>")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ultimate_lyrics/provider/item'
|
4
|
+
|
5
|
+
module UltimateLyrics
|
6
|
+
class Provider
|
7
|
+
class ExtractItem < ::UltimateLyrics::Provider::Item
|
8
|
+
def apply_from_delimiters(source)
|
9
|
+
source.delimited_inner(begin_with, end_with)
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply_from_tag(source)
|
13
|
+
source.delimited_inner(tag, "</#{tag_name}>")
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply_from_url(source)
|
17
|
+
url.gsub('{id}', source)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UltimateLyrics
|
4
|
+
class Provider
|
5
|
+
class Item
|
6
|
+
METHODS_ATTRIBUTES = { tag: :tag, begin_with: :begin, end_with: :end, url: :url }.freeze
|
7
|
+
TAG_NAME_PARSER = /<(\w+).*>/.to_parser { |m| m[1] }
|
8
|
+
|
9
|
+
common_constructor :rule, :node
|
10
|
+
|
11
|
+
METHODS_ATTRIBUTES.each do |method_name, attr|
|
12
|
+
define_method method_name do
|
13
|
+
::CGI.unescapeHTML(node.attribute(attr.to_s).if_present('', &:text)).presence
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method "#{method_name}?" do
|
17
|
+
send(method_name).present?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def delimiters?
|
22
|
+
begin_with? || end_with?
|
23
|
+
end
|
24
|
+
|
25
|
+
def apply(source)
|
26
|
+
%w[url tag delimiters].each do |m|
|
27
|
+
next unless send("#{m}?")
|
28
|
+
|
29
|
+
return send("apply_from_#{m}", source)
|
30
|
+
end
|
31
|
+
|
32
|
+
raise 'Invalid branch hit'
|
33
|
+
end
|
34
|
+
|
35
|
+
def tag_name
|
36
|
+
TAG_NAME_PARSER.parse(tag)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
self.class.name.demodulize + '[' + METHODS_ATTRIBUTES
|
41
|
+
.select { |m, _a| send(m).present? }
|
42
|
+
.map { |m, a| "#{a}: #{send(m)}" }
|
43
|
+
.join(', ') +
|
44
|
+
']'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UltimateLyrics
|
4
|
+
class Provider
|
5
|
+
class ReplaceFields
|
6
|
+
common_constructor :metadata, :source_string
|
7
|
+
|
8
|
+
def result
|
9
|
+
fields_found.inject(source_string) { |a, e| a.gsub("{#{e}}", metadata.send(e)) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UltimateLyrics
|
4
|
+
class Provider
|
5
|
+
class Rule
|
6
|
+
common_constructor :node
|
7
|
+
|
8
|
+
def items
|
9
|
+
node.xpath('./item').map { |v| item_class.new(self, v) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def item_class
|
13
|
+
::UltimateLyrics::Provider.const_get(type.camelize + 'Item')
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply(string)
|
17
|
+
url? ? apply_with_url(string) : apply_without_url(string)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"Rule[#{type} | #{items.join(', ')}]"
|
22
|
+
end
|
23
|
+
|
24
|
+
def type
|
25
|
+
node.name
|
26
|
+
end
|
27
|
+
|
28
|
+
def url?
|
29
|
+
items.any?(&:url?)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def apply_without_url(string)
|
35
|
+
items.inject(string) { |a, e| e.apply(a) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def apply_with_url(string)
|
39
|
+
url_item, id_item = url_items
|
40
|
+
id_item.apply(string).if_present { |v| url_item.apply(v) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def url_items
|
44
|
+
raise "There is more than 2 items in #{rule}" if items.count != 2
|
45
|
+
|
46
|
+
url_item = items.find(&:url?) || raise("No URL item found in #{rule}")
|
47
|
+
id_item = items.find(&:delimiters?) || raise("No ID item found in #{rule}")
|
48
|
+
[url_item, id_item]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UltimateLyrics
|
4
|
+
class Provider
|
5
|
+
class UrlFormat
|
6
|
+
common_constructor :node
|
7
|
+
|
8
|
+
def apply(value)
|
9
|
+
replace_chars.inject(value) { |a, e| a.gsub(e, with) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def replace_chars
|
13
|
+
::CGI.unescapeHTML(node.attribute('replace').text).each_char.to_a
|
14
|
+
end
|
15
|
+
|
16
|
+
def with
|
17
|
+
node.attribute('with').text
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'ultimate_lyrics/field'
|
6
|
+
|
7
|
+
module UltimateLyrics
|
8
|
+
class Provider
|
9
|
+
require_sub __FILE__
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# @return [Array<UltimateLyrics::Provider>]
|
13
|
+
def all
|
14
|
+
@all ||= ::Nokogiri::XML(
|
15
|
+
::File.new(::File.join(__dir__, 'providers_data.xml'))
|
16
|
+
).xpath('/lyricproviders/provider').map { |node| new(node) }
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [UltimateLyrics::Provider]
|
20
|
+
def by_name(name)
|
21
|
+
by_attribute('name', name)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [UltimateLyrics::Provider]
|
25
|
+
def by_identifier(identifier)
|
26
|
+
by_attribute('identifier', identifier)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [UltimateLyrics::Provider]
|
30
|
+
def by_attribute(attribute, value)
|
31
|
+
all.find { |provider| provider.send(attribute) == value } ||
|
32
|
+
raise("No provider with name \"#{value}\" (Available: " +
|
33
|
+
all.map { |p| p.send(attrbute) }.join(', ') + ')')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
common_constructor :node
|
38
|
+
|
39
|
+
def encoding
|
40
|
+
node.attribute('charset').text
|
41
|
+
end
|
42
|
+
|
43
|
+
def extract_rules
|
44
|
+
node.xpath('./extract').map do |v|
|
45
|
+
::UltimateLyrics::Provider::Rule.new(v)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def exclude_rules
|
50
|
+
node.xpath('./exclude').map do |v|
|
51
|
+
::UltimateLyrics::Provider::Rule.new(v)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def identifier
|
56
|
+
name.variableize
|
57
|
+
end
|
58
|
+
|
59
|
+
def invalid_indicators
|
60
|
+
node.xpath('/invalidIndicator/@value').map(&:text)
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String]
|
64
|
+
def name
|
65
|
+
node.attribute('name').text
|
66
|
+
end
|
67
|
+
|
68
|
+
def rules
|
69
|
+
extract_rules + exclude_rules
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [String]
|
73
|
+
def url
|
74
|
+
node.attribute('url').text
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [Array<UltimateLyrics::Field>]
|
78
|
+
def url_fields
|
79
|
+
::UltimateLyrics::Field.from_string(url)
|
80
|
+
end
|
81
|
+
|
82
|
+
def url_formats
|
83
|
+
node.xpath('./urlFormat').map do |v|
|
84
|
+
::UltimateLyrics::Provider::UrlFormat.new(v)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def title
|
89
|
+
node.attribute('text').text
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
name
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'aranha/parsers/source_address'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'ultimate_lyrics/lyrics'
|
6
|
+
require 'ultimate_lyrics/parser'
|
7
|
+
|
8
|
+
module UltimateLyrics
|
9
|
+
class ProviderSearch
|
10
|
+
common_constructor :provider, :song_metadata
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
def url
|
14
|
+
url_fields.inject(provider.url) { |a, e| e.apply(a) }
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return []
|
18
|
+
def url_fields
|
19
|
+
provider.url_fields.map { |provider_url_field| song_metadata.field(provider_url_field) }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [UltimateLyrics::Lyrics]
|
23
|
+
def lyrics
|
24
|
+
::UltimateLyrics::Lyrics.new(song_metadata, provider.name, parser.result)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [UltimateLyrics::Parser]
|
28
|
+
def lyrics_original_text
|
29
|
+
::Aranha::Parsers::SourceAddress.detect_sub(url).content.force_encoding(provider.encoding)
|
30
|
+
rescue ::Aranha::Parsers::SourceAddress::FetchContentError
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [UltimateLyrics::Parser]
|
35
|
+
def parser
|
36
|
+
::UltimateLyrics::Parser.new(provider, lyrics_original_text)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
"ProviderSearch[#{provider} | #{song_metadata}]"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|