]> git.sesse.net Git - vlc/blob - share/luameta/googleimage.lua
5046327601140057be5d7143a697f3695637bfd0
[vlc] / share / luameta / googleimage.lua
1 -- Get's an artwork from images.google.com
2 -- $Id$
3
4 -- Replace non alphanumeric char by +
5 function get_query( title )
6     return string.gsub( title, "([^%w ])",
7          function (c) return string.format ("%%%02X", string.byte(c)) end)
8 end
9
10 -- Return the artwork
11 function fetch_art()
12     if vlc.title and vlc.artist then
13         title = vlc.artist.." "..vlc.title
14     elseif vlc.title then
15         title = vlc.title
16     elseif vlc.name then
17         title = vlc.name
18     else
19         return nil
20     end
21     fd = vlc.stream_new( "http://images.google.com/images?q=" .. get_query( title ) )
22     page = vlc.stream_read( fd, 65653 )
23     vlc.stream_delete( fd )
24     _, _, arturl = string.find( page, "imgurl=([^&]+)" )
25     return vlc.decode_uri(arturl)
26 end