]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/lyrics_engine.rb
1291d41131f497e453cba41da5862745da923777
3 # This class gets the lyrics according to a given artist and song name.
8 # Starts a new instance of LyricsEngine
10 # @param [String] artist the artist
11 # @param [String] song the song to look for
12 def initialize(artist
, song
)
13 @provider = URI("http://lyrics.wikia.com/api.php?artist=#{sanitize_param artist}&song=#{sanitize_param song}&fmt=realjson")
16 # Asks Lyrics Wiki for the lyrics, also cleans up the output a little.
18 # @return [String] the lyrics
21 response
= Net
::HTTP.get(@provider)
22 response
= MultiJson
.decode(response
)
24 doc
= Nokogiri
::HTML(open(response
['url']))
25 node
= doc
.search(".lyricbox").first
27 raise Exceptions
::LyricsNotFoundError
30 node
.search(".rtMatcher").each
do |n
|
34 node
.search("script").each
do |n
|
38 node
.search("br").each
do |br
|
42 node
.inner_text
.gsub(/\s+$/, "")