PDA

View Full Version : code to get Lyrics from lyricswiki



mhwlng
August 18th, 2007, 09:35 AM
I've been playing with LuaSOAP to get song lyrics from lyricswiki from G5:

1) download luasoap from http://www.keplerproject.org/luasoap/
2) put soap.lua in luascript\soap (don't use http.lua)
3) put the following code in luascript\soap\http.lua



require "socket.http"
require "ltn12"
require "soap.soap"
soap.http = {}
function soap.http.call (posturl, namespace, method, entries, headers)
local bodydata = soap.soap.encode (namespace, method, entries, headers);
local t = {}
local r, httperror = socket.http.request(
{ url = posturl,
sink = ltn12.sink.table(t),
method = 'POST',
headers = {
["content-length"] = string.len(bodydata),
["Content-type"] = "text/xml",
["SOAPAction"] = '"'..method..'"',
},
source = ltn12.source.string(bodydata)
}
)
if (r==1) and (httperror==200) then
return soap.soap.decode (table.concat(t))
else
return httperror
end
end




then, to get the lyrics, do something like this :


require "soap.http"
local ns, meth, ent = soap.http.call ("http://lyricwiki.org/server.php",
"LyricWiki",
"getSong",
{
{ tag = "artist", "Ani Difranco" },
{ tag = "song", "Gravel" },
})

if ent ~= nil then
for i, elem in ipairs (ent[1]) do
if elem.tag=="lyrics" then
print (elem[1]); -- can also return "Not Found"
break;
end
end
end



Marcel

theguywiththefunnyhair
August 22nd, 2007, 06:37 AM
This also works with G4, thanks Marcel!!

harleydude
December 15th, 2007, 12:42 AM
Marcel,

Great find. Just added this tonight. Works great.

Burre
August 13th, 2008, 01:37 PM
Can someone please repeat that in english? :p
I\d really love autolyrics on the PPC, will this code do that? and where do I put it? Im using JRMC.