lyrics_finder 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lyrics_finder.rb +20 -10
- data/lib/lyrics_finder/cli.rb +2 -1
- data/lib/lyrics_finder/providers.rb +43 -41
- data/lib/lyrics_finder/version.rb +1 -1
- data/lyrics_finder.gemspec +4 -2
- metadata +30 -45
- data/lib/lyrics_finder/dependencies.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe831ea20170d0451bfb2daa9d6b4c8666d2c80c
|
4
|
+
data.tar.gz: 8636a535164d07b04de269c70d33a492196567b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24747ff3be16a9d9846839856f7b7f1dfe3f5417c4e119c9fe379453ac685fa4eaa50e511301ded74951f59a4d39441999b6578dbf2bb2c865dc073ee603462d
|
7
|
+
data.tar.gz: 88b0073309bcc4ae1debe10cade8bbad92f6184812dd9a557676cc8f3cf340c96223bf8949c517bb33cea3ffe4f97eb2b344ab7554e2681e386be31d72f7d08d
|
data/lib/lyrics_finder.rb
CHANGED
@@ -1,21 +1,31 @@
|
|
1
|
-
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
require 'i18n'
|
5
|
+
I18n.enforce_available_locales = false
|
6
|
+
require 'lyrics_finder/version'
|
7
|
+
require 'lyrics_finder/song'
|
8
|
+
require 'lyrics_finder/providers'
|
9
|
+
|
2
10
|
|
3
11
|
module LyricsFinder
|
4
12
|
def self.search(author, title)
|
5
13
|
Providers.list.each do |provider|
|
6
14
|
url = Providers.provider_url_for_song(provider, Song.new(author, title))
|
7
15
|
data = perform_request(url)
|
8
|
-
result = Providers.extract_lyric_from_data(data)
|
16
|
+
result = Providers.extract_lyric_from_data(data) unless data.nil?
|
9
17
|
return result unless result.nil?
|
10
18
|
end
|
11
|
-
return nil #
|
19
|
+
return nil # song not found
|
12
20
|
end
|
13
21
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.perform_request(url)
|
25
|
+
begin
|
26
|
+
open(url)
|
27
|
+
rescue Exception => ex
|
28
|
+
# puts "ERROR: " + ex.message
|
29
|
+
end
|
19
30
|
end
|
20
|
-
|
21
|
-
end
|
31
|
+
end
|
data/lib/lyrics_finder/cli.rb
CHANGED
@@ -7,7 +7,8 @@ module Lyrics
|
|
7
7
|
method_option 'author', :aliases => '-a', :type => :string
|
8
8
|
method_option 'title', :aliases => '-t', :type => :string
|
9
9
|
def search
|
10
|
-
|
10
|
+
result = LyricsFinder.search(options[:author], options[:title])
|
11
|
+
puts result.nil? ? "Song not found." : result
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,54 +1,56 @@
|
|
1
|
-
module LyricsFinder
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module LyricsFinder
|
2
|
+
module Providers
|
3
|
+
def self.list
|
4
|
+
[LyricsWikia, LyricsMania, SongLyrics, Azlyrics]
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def self.provider_url_for_song(provider, song)
|
8
|
+
@current_provider = provider.new(song)
|
9
|
+
@current_provider.format_url
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def self.extract_lyric_from_data(data)
|
13
|
+
html = Nokogiri::HTML(data)
|
14
|
+
lyrics_container = html.css(@current_provider.css_element).first
|
15
|
+
unless lyrics_container.nil?
|
16
|
+
elements = lyrics_container.children.to_a
|
17
|
+
phrases = elements.select { |el| el.text? && el.text != "\n" && !el.blank? }
|
18
|
+
phrases.map! { |element| element.text.strip }
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
+
# Providers Structs
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
LyricsWikia = Struct.new(:song) do
|
25
|
+
def format_url
|
26
|
+
song.format_attributes_with_separator!("_")
|
27
|
+
"http://lyrics.wikia.com/#{song.author}:#{song.title}"
|
28
|
+
end
|
29
|
+
def css_element; ".lyricbox"; end
|
27
30
|
end
|
28
|
-
def css_element; ".lyricbox"; end
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
LyricsMania = Struct.new(:song) do
|
33
|
+
def format_url
|
34
|
+
song.format_attributes_with_separator!("_")
|
35
|
+
"http://www.lyricsmania.com/#{song.title}_lyrics_#{song.author}.html"
|
36
|
+
end
|
37
|
+
def css_element; ".lyrics-body"; end
|
35
38
|
end
|
36
|
-
def css_element; ".lyrics-body"; end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
SongLyrics = Struct.new(:song) do
|
41
|
+
def format_url
|
42
|
+
song.format_attributes_with_separator!("-")
|
43
|
+
"http://www.songlyrics.com/#{song.author}/#{song.title}-lyrics/"
|
44
|
+
end
|
45
|
+
def css_element; "#songLyricsDiv"; end
|
43
46
|
end
|
44
|
-
def css_element; "#songLyricsDiv"; end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
Azlyrics = Struct.new(:song) do
|
49
|
+
def format_url
|
50
|
+
song.format_attributes_with_separator!("")
|
51
|
+
"http://www.azlyrics.com/lyrics/#{song.author}/#{song.title}.html"
|
52
|
+
end
|
53
|
+
def css_element; "div:nth-child(7)"; end
|
51
54
|
end
|
52
|
-
def css_element; "div:nth-child(7)"; end
|
53
55
|
end
|
54
|
-
end
|
56
|
+
end
|
data/lyrics_finder.gemspec
CHANGED
@@ -22,9 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'rake'
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
24
24
|
spec.add_development_dependency 'vcr', '~> 2.9.2'
|
25
|
-
spec.add_development_dependency 'webmock', '~> 1.
|
25
|
+
spec.add_development_dependency 'webmock', '~> 1.19.0'
|
26
26
|
spec.add_development_dependency 'coveralls', '~> 0.7.0'
|
27
|
-
spec.add_development_dependency 'pry', '~> 0.
|
27
|
+
# spec.add_development_dependency 'pry', '~> 0.10'
|
28
|
+
# spec.add_development_dependency 'pry-byebug', '~> 2.0.0'
|
29
|
+
# spec.add_development_dependency 'awesome_print', '~> 1.2.0'
|
28
30
|
|
29
31
|
spec.add_dependency 'nokogiri', '~> 1.6.0'
|
30
32
|
spec.add_dependency 'activesupport', '~> 4.1.0'
|
metadata
CHANGED
@@ -1,167 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lyrics_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Romero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: vcr
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.9.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.9.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
75
|
+
version: 1.19.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
82
|
+
version: 1.19.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: coveralls
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 0.7.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.7.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ~>
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0.9'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ~>
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0.9'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: nokogiri
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - ~>
|
101
|
+
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: 1.6.0
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- - ~>
|
108
|
+
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: 1.6.0
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: activesupport
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- - ~>
|
115
|
+
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
117
|
version: 4.1.0
|
132
118
|
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
|
-
- - ~>
|
122
|
+
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: 4.1.0
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: i18n
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
|
-
- - ~>
|
129
|
+
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
131
|
version: 0.6.9
|
146
132
|
type: :runtime
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
|
-
- - ~>
|
136
|
+
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: 0.6.9
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: thor
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
|
-
- - ~>
|
143
|
+
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
145
|
version: 0.19.1
|
160
146
|
type: :runtime
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
|
-
- - ~>
|
150
|
+
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: 0.19.1
|
167
153
|
description: Simple library for finding song lyrics
|
@@ -172,10 +158,10 @@ executables:
|
|
172
158
|
extensions: []
|
173
159
|
extra_rdoc_files: []
|
174
160
|
files:
|
175
|
-
- .coveralls.yml
|
176
|
-
- .gitignore
|
177
|
-
- .rspec
|
178
|
-
- .travis.yml
|
161
|
+
- ".coveralls.yml"
|
162
|
+
- ".gitignore"
|
163
|
+
- ".rspec"
|
164
|
+
- ".travis.yml"
|
179
165
|
- Gemfile
|
180
166
|
- Guardfile
|
181
167
|
- LICENSE.txt
|
@@ -184,7 +170,6 @@ files:
|
|
184
170
|
- bin/lyricsfinder
|
185
171
|
- lib/lyrics_finder.rb
|
186
172
|
- lib/lyrics_finder/cli.rb
|
187
|
-
- lib/lyrics_finder/dependencies.rb
|
188
173
|
- lib/lyrics_finder/providers.rb
|
189
174
|
- lib/lyrics_finder/song.rb
|
190
175
|
- lib/lyrics_finder/version.rb
|
@@ -207,12 +192,12 @@ require_paths:
|
|
207
192
|
- lib
|
208
193
|
required_ruby_version: !ruby/object:Gem::Requirement
|
209
194
|
requirements:
|
210
|
-
- -
|
195
|
+
- - ">="
|
211
196
|
- !ruby/object:Gem::Version
|
212
197
|
version: '0'
|
213
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
199
|
requirements:
|
215
|
-
- -
|
200
|
+
- - ">="
|
216
201
|
- !ruby/object:Gem::Version
|
217
202
|
version: '0'
|
218
203
|
requirements: []
|