lyrics_finder 0.0.3.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/README.md +5 -0
- data/lib/lyrics_finder.rb +2 -4
- data/lib/lyrics_finder/dependencies.rb +2 -1
- data/lib/lyrics_finder/providers/lyrics_mania.rb +16 -0
- data/lib/lyrics_finder/version.rb +1 -1
- data/spec/lyrics_finder/lyrics_finder_spec.rb +16 -18
- data/spec/lyrics_finder/providers/azlyrics_spec.rb +13 -1
- data/spec/lyrics_finder/providers/lyrics_mania_spec.rb +27 -0
- data/spec/lyrics_finder/providers/song_lyrics_spec.rb +13 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/support/lyrics_mania_sample_songs.rb +52 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24d30590b3b2ea3bca2df02b6f094d6765b567c8
|
4
|
+
data.tar.gz: 9958bc037c98e13ae04be1c389f94b537cbde463
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56c43572f530c4beffc7420eb077e008abfd6eb46e30cb185e845da7d763089a30e44e7d3f455efa3783105f5f64cd11101101dd683fe03bff947ba934a46b54
|
7
|
+
data.tar.gz: 9931a17d85fba8980ef222de6d1ed8cc53a2339e389015875b681153d4ecbfc42a31aaf89cc48c259cc813e3cd858fd4272f8e89a6e20dd847ff1bf95dbe14db
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,7 @@ You can choose among the following:
|
|
44
44
|
- LyricsWikia (`:lyrics_wikia`)
|
45
45
|
- SongLyrics (`:song_lyrics`)
|
46
46
|
- AZLyrics (`:azlyrics`)
|
47
|
+
- LyricsMania (`:lyrics_mania`)
|
47
48
|
|
48
49
|
## Example
|
49
50
|
|
@@ -64,6 +65,10 @@ LyricsFinder is also available as a command-line tool.
|
|
64
65
|
|
65
66
|
## Changelog
|
66
67
|
|
68
|
+
v 0.0.4
|
69
|
+
|
70
|
+
- Added lyrics mania as a valid website to get your lyrics from.
|
71
|
+
|
67
72
|
v 0.0.3
|
68
73
|
|
69
74
|
- Wrapped everything into a `Lyrics` module.
|
data/lib/lyrics_finder.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative 'lyrics_finder/dependencies'
|
|
3
3
|
module Lyrics
|
4
4
|
class Finder
|
5
5
|
include Contracts
|
6
|
-
PROVIDERS_LIST = [:lyrics_wikia, :song_lyrics, :azlyrics]
|
6
|
+
PROVIDERS_LIST = [:lyrics_wikia, :lyrics_mania, :song_lyrics, :azlyrics]
|
7
7
|
|
8
8
|
def initialize(*args)
|
9
9
|
@providers = filter_providers(args)
|
@@ -24,14 +24,12 @@ module Lyrics
|
|
24
24
|
@providers.each do |provider|
|
25
25
|
klass = Providers.build_klass(provider)
|
26
26
|
url = klass.format_url(song)
|
27
|
-
|
28
27
|
data = perform_request(url)
|
29
28
|
result = klass.extract_lyric(data) if data
|
30
29
|
throw :song_lyric, result unless result.nil?
|
31
30
|
end
|
31
|
+
throw :song_lyric, nil # because song cannot be found.
|
32
32
|
}
|
33
|
-
# because if it doesn't find anything returns @providers by default
|
34
|
-
song_lyric != @providers ? song_lyric : nil
|
35
33
|
end
|
36
34
|
|
37
35
|
private
|
@@ -9,4 +9,5 @@ require_relative 'version'
|
|
9
9
|
require_relative 'providers'
|
10
10
|
require_relative 'providers/lyrics_wikia'
|
11
11
|
require_relative 'providers/azlyrics'
|
12
|
-
require_relative 'providers/song_lyrics'
|
12
|
+
require_relative 'providers/song_lyrics'
|
13
|
+
require_relative 'providers/lyrics_mania'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Lyrics
|
2
|
+
module Providers::LyricsMania
|
3
|
+
include Contracts
|
4
|
+
|
5
|
+
Contract Lyrics::Song => String
|
6
|
+
def self.format_url(song)
|
7
|
+
song.format_attributes_with_separator!("_")
|
8
|
+
"http://www.lyricsmania.com/#{song.title}_lyrics_#{song.author}.html"
|
9
|
+
end
|
10
|
+
|
11
|
+
Contract Tempfile => Or[Array, nil]
|
12
|
+
def self.extract_lyric(data)
|
13
|
+
Lyrics::Providers.extract_lyrics_at_css_from_data('.lyrics-body', data)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -95,24 +95,22 @@ describe Lyrics::Finder do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
# end
|
115
|
-
# end
|
98
|
+
describe 'using LyricsMania as the provider' do
|
99
|
+
before :each do
|
100
|
+
@finder = Lyrics::Finder.new(:lyrics_mania)
|
101
|
+
VCR.use_cassette 'LyricsMania 200 search' do
|
102
|
+
@song = @finder.search("american authors", "best day of my life")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns an instance of Array' do
|
107
|
+
expect(@song.class).to eq Array
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns the desired song' do
|
111
|
+
expect(@song).to eq LyricsManiaSampleSongs::BEST_DAY_OF_MY_LIFE
|
112
|
+
end
|
113
|
+
end
|
116
114
|
|
117
115
|
describe 'with a song that cannot be found' do
|
118
116
|
before :each do
|
@@ -11,5 +11,17 @@ describe Lyrics::Providers::Azlyrics do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
describe '.extract_lyric' do
|
16
|
+
# with valid data it's already tested in lyrics_finder_spec.rb
|
17
|
+
context 'with invalid data' do
|
18
|
+
let(:klass) { Lyrics::Providers::Azlyrics }
|
19
|
+
|
20
|
+
it 'raises a ContractError Exception' do
|
21
|
+
expect{
|
22
|
+
klass.extract_lyric(3.14)
|
23
|
+
}.to raise_error ContractError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
describe Lyrics::Providers::LyricsMania do
|
3
|
+
describe '.format_url' do
|
4
|
+
context 'with valid author and title' do
|
5
|
+
let(:klass) { Lyrics::Providers::LyricsMania }
|
6
|
+
let(:song) { Lyrics::Song.new("amêricàn authors", "best day of my life") }
|
7
|
+
let(:valid_url) { "http://www.lyricsmania.com/best_day_of_my_life_lyrics_american_authors.html" }
|
8
|
+
|
9
|
+
it 'returns a properly formatted url' do
|
10
|
+
expect(klass.format_url(song)).to eq valid_url
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.extract_lyric' do
|
16
|
+
# with valid data it's already tested in lyrics_finder_spec.rb
|
17
|
+
context 'with invalid data' do
|
18
|
+
let(:klass) { Lyrics::Providers::LyricsMania }
|
19
|
+
|
20
|
+
it 'raises a ContractError Exception' do
|
21
|
+
expect{
|
22
|
+
klass.extract_lyric({})
|
23
|
+
}.to raise_error ContractError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -11,5 +11,17 @@ describe Lyrics::Providers::SongLyrics do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
|
+
describe '.extract_lyric' do
|
16
|
+
# with valid data it's already tested in lyrics_finder_spec.rb
|
17
|
+
context 'with invalid data' do
|
18
|
+
let(:klass) { Lyrics::Providers::SongLyrics }
|
19
|
+
|
20
|
+
it 'raises a ContractError Exception' do
|
21
|
+
expect{
|
22
|
+
klass.extract_lyric([])
|
23
|
+
}.to raise_error ContractError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,4 +7,5 @@ require 'lyrics_finder'
|
|
7
7
|
require_relative 'support/vcr_setup'
|
8
8
|
require_relative 'support/lyrics_wikia_sample_songs'
|
9
9
|
require_relative 'support/azlyrics_sample_songs'
|
10
|
-
require_relative 'support/song_lyrics_sample_songs'
|
10
|
+
require_relative 'support/song_lyrics_sample_songs'
|
11
|
+
require_relative 'support/lyrics_mania_sample_songs'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module LyricsManiaSampleSongs
|
2
|
+
BEST_DAY_OF_MY_LIFE = ["Wo-o-o-o-o-oh Wooh",
|
3
|
+
"I had a dream so big and loud",
|
4
|
+
"I jumped so high I touched the clouds",
|
5
|
+
"Wo-o-o-o-o-oh",
|
6
|
+
"Wo-o-o-o-o-oh",
|
7
|
+
"I stretched my hands out to the sky",
|
8
|
+
"We danced with monsters through the night",
|
9
|
+
"Wo-o-o-o-o-oh",
|
10
|
+
"Wo-o-o-o-o-oh",
|
11
|
+
"I'm never gonna look back",
|
12
|
+
"Woah, I'm never gonna give it up",
|
13
|
+
"No, please don't wake me now",
|
14
|
+
"Oo-o-o-o-oo",
|
15
|
+
"This is gonna be the best day of my life",
|
16
|
+
"My li-i-i-i-i-ife",
|
17
|
+
"Oo-o-o-o-oo",
|
18
|
+
"This is gonna be the best day of my life",
|
19
|
+
"My li-i-i-i-i-ife",
|
20
|
+
"I howled at the moon with friends",
|
21
|
+
"And then the sun came crashing in",
|
22
|
+
"Wo-o-o-o-o-oh",
|
23
|
+
"Wo-o-o-o-o-oh",
|
24
|
+
"But all the possibilities",
|
25
|
+
"No limits just epiphanies",
|
26
|
+
"Wo-o-o-o-o-oh",
|
27
|
+
"Wo-o-o-o-o-oh",
|
28
|
+
"I'm never gonna look back",
|
29
|
+
"Woah, I'm never gonna give it up",
|
30
|
+
"No, just don't wake me now",
|
31
|
+
"Oo-o-o-o-oo",
|
32
|
+
"This is gonna be the best day of my life",
|
33
|
+
"My li-i-i-i-i-ife",
|
34
|
+
"Oo-o-o-o-oo",
|
35
|
+
"This is gonna be the best day of my life",
|
36
|
+
"My li-i-i-i-i-ife",
|
37
|
+
"I hear it calling outside my window",
|
38
|
+
"I feel it in my soul (soul)",
|
39
|
+
"The stars were burning so bright",
|
40
|
+
"The sun was out 'til midnight",
|
41
|
+
"I say we lose control (control)",
|
42
|
+
"This is gonna be the best day of my life",
|
43
|
+
"My li-i-i-i-i-ife",
|
44
|
+
"Oo-o-o-o-o",
|
45
|
+
"This is gonna be the best day of my life",
|
46
|
+
"My li-i-i-i-i-ife",
|
47
|
+
"This is gonna be, this is gonna be, this is gonna be",
|
48
|
+
"The best day of my life",
|
49
|
+
"Everything is looking up, everybody up now",
|
50
|
+
"This is gonna be the best day of my life",
|
51
|
+
"My li-i-i-i-i-ife"]
|
52
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lyrics_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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-06-
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -201,6 +201,7 @@ files:
|
|
201
201
|
- lib/lyrics_finder/dependencies.rb
|
202
202
|
- lib/lyrics_finder/providers.rb
|
203
203
|
- lib/lyrics_finder/providers/azlyrics.rb
|
204
|
+
- lib/lyrics_finder/providers/lyrics_mania.rb
|
204
205
|
- lib/lyrics_finder/providers/lyrics_wikia.rb
|
205
206
|
- lib/lyrics_finder/providers/song_lyrics.rb
|
206
207
|
- lib/lyrics_finder/song.rb
|
@@ -208,11 +209,13 @@ files:
|
|
208
209
|
- lyrics_finder.gemspec
|
209
210
|
- spec/lyrics_finder/lyrics_finder_spec.rb
|
210
211
|
- spec/lyrics_finder/providers/azlyrics_spec.rb
|
212
|
+
- spec/lyrics_finder/providers/lyrics_mania_spec.rb
|
211
213
|
- spec/lyrics_finder/providers/lyrics_wikia_spec.rb
|
212
214
|
- spec/lyrics_finder/providers/song_lyrics_spec.rb
|
213
215
|
- spec/lyrics_finder/providers_spec.rb
|
214
216
|
- spec/spec_helper.rb
|
215
217
|
- spec/support/azlyrics_sample_songs.rb
|
218
|
+
- spec/support/lyrics_mania_sample_songs.rb
|
216
219
|
- spec/support/lyrics_wikia_sample_songs.rb
|
217
220
|
- spec/support/song_lyrics_sample_songs.rb
|
218
221
|
- spec/support/vcr_setup.rb
|
@@ -243,11 +246,13 @@ summary: Solution for finding song lyrics
|
|
243
246
|
test_files:
|
244
247
|
- spec/lyrics_finder/lyrics_finder_spec.rb
|
245
248
|
- spec/lyrics_finder/providers/azlyrics_spec.rb
|
249
|
+
- spec/lyrics_finder/providers/lyrics_mania_spec.rb
|
246
250
|
- spec/lyrics_finder/providers/lyrics_wikia_spec.rb
|
247
251
|
- spec/lyrics_finder/providers/song_lyrics_spec.rb
|
248
252
|
- spec/lyrics_finder/providers_spec.rb
|
249
253
|
- spec/spec_helper.rb
|
250
254
|
- spec/support/azlyrics_sample_songs.rb
|
255
|
+
- spec/support/lyrics_mania_sample_songs.rb
|
251
256
|
- spec/support/lyrics_wikia_sample_songs.rb
|
252
257
|
- spec/support/song_lyrics_sample_songs.rb
|
253
258
|
- spec/support/vcr_setup.rb
|