Ok, i got a good deal of it working : http://imgur.com/G77AG.png. Lyrc's API
returns a very badly formatted html. Naturally, getting the actual lyrics
out of the html dump is not very elegant.

In my rc.lua, I have set the mpd widget to update every 2 sec. Is it to mean
that the following code will fetch lyrics every 2 secs? Can it be optimized?

code( in mpd.lua ) :

    artist = mpd_state["{Artist}"]
    title = mpd_state["{Title}"]
    local lurl =
"http://lyrc.com.ar/tema1es.php?artist="..url_encode(artist).."&songname="..url_encode(
title )
    local lf = io.popen("curl --connect-timeout 1 -fsm 3 '"..lurl.."'")
    local ls = lf:read("*all")
    local lyrics = string.match( ls, "</table>(.*)</font>" )
    if lyrics == nil
        then
            mpd_state["{lyrics}"] = 'N/A'
        else
            lyrics = string.gsub( lyrics, '<.->', '' ) -- filters html tags
from the lyrics
            mpd_state["{lyrics}"] = lyrics
        end

@anrxc
do you think that the lyrics fetching code( perhaps a better version of mine
) can be merged into vicious?

P.S. : I do not really know Lua, so a more idiomatic version of above would
be welcome :).

-- 
Anurag Priyam,
3rd Year Undergraduate,
Department of Mechanical Engineering,
IIT Kharagpur.
+91-9775550642

Reply via email to