]> git.r.bdr.sh - rbdr/lyricli.rb/blame - lib/lyricli/lyrics_engine.rb
Implements the lrc executable
[rbdr/lyricli.rb] / lib / lyricli / lyrics_engine.rb
CommitLineData
823e558b
BB
1module Lyricli
2 class LyricsEngine
3
4 include Util
5
6 def initialize(artist, song)
7 @provider = URI("http://lyrics.wikia.com/api.php?artist=#{sanitize_param artist}&song=#{sanitize_param song}&fmt=realjson")
8 end
9
10 def get_lyrics
11 begin
12 response = Net::HTTP.get(@provider)
13 response = MultiJson.decode(response)
14
15 doc = Nokogiri::HTML(open(response['url']))
16 node = doc.search(".lyricbox").first
17 rescue
18 raise Lyricli::LyricsNotFoundException
19 end
20
21 node.search(".rtMatcher").each do |n|
22 n.remove
23 end
24
25 node.search("br").each do |br|
26 br.replace "\n"
27 end
28
29 node.inner_text
30 end
31
32 end
33end