]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli/lyrics_engine.rb
beacd4610490d6c17af4dc94f9c035dff08fe027
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 Lyricli
::LyricsNotFoundException
30 node
.search(".rtMatcher").each
do |n
|
34 node
.search("br").each
do |br
|