]> git.sesse.net Git - vlc/commitdiff
share/luameta/googleimage.lua: Rework a bit to better handle meta going wrong.
authorPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 15 Aug 2007 04:28:26 +0000 (04:28 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Wed, 15 Aug 2007 04:28:26 +0000 (04:28 +0000)
share/luameta/googleimage.lua

index 22bf50be5e2de18311ef97c6d380e9077ad005bb..98ef35a062d9938b77d0d35a9b4845f4ebd8d142 100644 (file)
@@ -2,19 +2,20 @@
 -- $Id$
 
 -- Replace non alphanumeric char by +
-function get_query( )
-    if vlc.title then
-        title = vlc.title
-    else
-        title = vlc.name
-    end
-    vlc.msg_dbg( title )
+function get_query( title )
     return title:gsub( "[^(a-z|A-Z|0-9)]", "+" )
 end
 
 -- Return the artwork
 function fetch_art()
-    fd = vlc.stream_new( "http://images.google.com/images?q=" .. get_query( ) )
+    if vlc.title then
+        title = vlc.title
+    elseif vlc.name then
+        title = vlc.name
+    else
+        return nil
+    end
+    fd = vlc.stream_new( "http://images.google.com/images?q=" .. get_query( title ) )
     page = vlc.stream_read( fd, 65653 )
     vlc.stream_delete( fd )
     _, _, arturl = string.find( page, "imgurl=([^&]+)" )