]> git.sesse.net Git - vlc/blob - share/luameta/googleimage.lua
share/luameta/googleimage.lua: Filter out extensions.
[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     -- If we have a .EXT remove the extension.
7     str = string.gsub( title, "(.*)%....$", "%1" )
8     return string.gsub( str, "([^%w ])",
9          function (c) return string.format ("%%%02X", string.byte(c)) end)
10 end
11
12 -- Return the artwork
13 function fetch_art()
14     if vlc.title and vlc.artist then
15         title = vlc.artist.." "..vlc.title
16     elseif vlc.title then
17         title = vlc.title
18     elseif vlc.name then
19         title = vlc.name
20     else
21         return nil
22     end
23     fd = vlc.stream_new( "http://images.google.com/images?q=" .. get_query( title ) )
24     page = vlc.stream_read( fd, 65653 )
25     vlc.stream_delete( fd )
26     _, _, arturl = string.find( page, "imgurl=([^&]+)" )
27     return vlc.decode_uri(arturl)
28 end