]>
git.r.bdr.sh - rbdr/lyricli.rb/blob - lib/lyricli.rb
928adadd19c1087e1a334fa680a9f4d92cfc6fcf
10 # This shit causes a lot of warnings. Quick Hack.
11 original_verbosity
= $VERBOSE
14 $VERBOSE = original_verbosity
18 # TODO: Change the whole fucking thing
20 @rdio_key = "sddac5t8akqrzh5b6kg53jfm"
21 @rdio_secret = "PRcB8TggFr"
22 @token_path = File
.expand_path("~/.rdio_token")
24 #Expand the symlink and get the path
25 if File
.symlink
?(__FILE__
) then
26 path
= File
.dirname(File
.readlink(__FILE__
))
28 path
= File
.dirname(__FILE__
)
31 # Get the current rdio track
35 #Get the current iTunes track
36 current
= `osascript #{path}/current_song.scpt`
37 if current
and not current
.empty
? then
38 current
= current
.split("<-SEP->")
39 @artist ||= current
[0]
46 if File
.exists
?(@token_path)
47 f
= File
.new(@token_path, "r")
49 token
= MultiJson
.decode(f
.read
)
51 token
= create_rdio_token
54 token
= create_rdio_token
57 Rdio
::SimpleRdio.new([@rdio_key, @rdio_secret], token
)
62 abort
"Usage: #{$0} artist song"
67 #Use the API to search
68 uri
= URI("http://lyrics.wikia.com/api.php?artist=#{self.sanitize_param @artist}&song=#{self.sanitize_param @song}&fmt=realjson")
70 res
= Net
::HTTP.get(uri
)
71 res
= MultiJson
.decode(res
)
73 #Get the actual lyrics url
74 doc
= Nokogiri
::HTML(open(res
['url']))
75 node
= doc
.search(".lyricbox").first
77 abort
"Lyrics not found :("
80 #Remove the rtMatcher nodes
81 node
.search(".rtMatcher").each
do |n
|
86 node
.search("br").each
do |br
|
95 self.exit_with_error
if @artist.nil? or @artist.empty
?
96 self.exit_with_error
if @song.nil? or @song.empty
?
100 URI
.encode_www_form_component(p
.gsub(/ /, "+")).gsub("%2B
", "+
")