On 2010-08-06 Anurag Priyam wrote:

> 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?
> 
yes, thats way to heavy ...
i did not test the following idea:

> code( in mpd.lua ) :

-- somewhere in your init-code
old_artist=''
old_title=''

> 
>     artist = mpd_state["{Artist}"]
>     title = mpd_state["{Title}"]
if (artist~=old_artist or title~=old_title) 
then
>     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.."'")

-- why not use lynx -dump -nolist ? No need to do html-stuff and the
-- overhead should be small

>     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

              old_artist= artist
              old_title= title

>             mpd_state["{lyrics}"] = lyrics
>         end

end

I myself go one step further: after i fetched correct lyrics i store it
in ~/.lyrics/artist-title.txt and when i want to show it again i first
try to open this text and only if that fails i try to fetch it from
somewhere else ..

I also only load lyrics if i really want to show it (in a
notification) - so i think it does not make much sense to put int in
vicious, also funny things will happen when the server replies really
slow ... 

-- 
To unsubscribe, send mail to [email protected].

Reply via email to