art_finder_t: custom type for art finder modules
authorRémi Denis-Courmont <remi@remlab.net>
Sun, 23 Aug 2009 10:07:03 +0000 (13:07 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Sun, 23 Aug 2009 10:08:04 +0000 (13:08 +0300)
include/vlc_art_finder.h [new file with mode: 0644]
modules/meta_engine/folder.c
modules/misc/lua/meta.c
src/playlist/fetcher.c

diff --git a/include/vlc_art_finder.h b/include/vlc_art_finder.h
new file mode 100644 (file)
index 0000000..d4b7e90
--- /dev/null
@@ -0,0 +1,30 @@
+/*****************************************************************************
+ * vlc_art_finder.h
+ *****************************************************************************
+ * Copyright (C) 2009 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_ART_FINDER_H
+#define VLC_ART_FINDER_H 1
+
+typedef struct art_finder_t
+{
+    VLC_COMMON_MEMBERS
+    input_item_t *p_item;
+} art_finder_t;
+
+#endif
index 9ef715f..fbb9619 100644 (file)
@@ -32,6 +32,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_playlist.h>
+#include <vlc_art_finder.h>
 #include <vlc_charset.h>
 #include <vlc_url.h>
 
@@ -74,7 +75,8 @@ vlc_module_end ()
  *****************************************************************************/
 static int FindMeta( vlc_object_t *p_this )
 {
-    input_item_t *p_item = (input_item_t *)p_this->p_private;
+    art_finder_t *p_finder = (art_finder_t *)p_this;
+    input_item_t *p_item = p_finder->p_item;
     bool b_have_art = false;
 
     int i;
index 733f2b7..5eb2ef0 100644 (file)
@@ -37,6 +37,7 @@
 #include <vlc_input.h>
 #include <vlc_playlist.h>
 #include <vlc_meta.h>
+#include <vlc_art_finder.h>
 #include <vlc_url.h>
 #include <vlc_strings.h>
 #include <vlc_stream.h>
@@ -191,11 +192,12 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
  *****************************************************************************/
 int FindArt( vlc_object_t *p_this )
 {
+    art_finder_t *p_finder = (art_finder_t *)p_this;
+    input_item_t *p_item = p_finder->p_item;
     playlist_t *p_playlist = pl_Hold( p_this );
     if( !p_playlist )
         return VLC_EGENERIC;
 
-    input_item_t *p_item = (input_item_t *)p_this->p_private;
     lua_State *L = vlclua_meta_init( p_this, p_item );
     int i_ret = vlclua_scripts_batch_execute( p_this, "meta", &fetch_art, L, p_item );
     lua_close( L );
index d2b6356..47715c8 100644 (file)
@@ -29,6 +29,7 @@
 #include <vlc_playlist.h>
 #include <vlc_stream.h>
 #include <limits.h>
+#include <vlc_art_finder.h>
 
 #include "art.h"
 #include "fetcher.h"
@@ -138,12 +139,10 @@ void playlist_fetcher_Delete( playlist_fetcher_t *p_fetcher )
 static int FindArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
 {
     int i_ret;
-    module_t *p_module;
-    char *psz_title, *psz_artist, *psz_album;
 
-    psz_artist = input_item_GetArtist( p_item );
-    psz_album = input_item_GetAlbum( p_item );
-    psz_title = input_item_GetTitle( p_item );
+    char *psz_artist = input_item_GetArtist( p_item );
+    char *psz_album = input_item_GetAlbum( p_item );
+    char *psz_title = input_item_GetTitle( p_item );
     if( !psz_title )
         psz_title = input_item_GetName( p_item );
 
@@ -219,19 +218,26 @@ static int FindArt( playlist_fetcher_t *p_fetcher, input_item_t *p_item )
     }
 
     /* Fetch the art url */
-    p_fetcher->p_private = p_item;
-
-    p_module = module_need( p_fetcher, "art finder", NULL, false );
+    i_ret = VLC_EGENERIC;
 
-    if( p_module )
-    {
-        module_unneed( p_fetcher, p_module );
-        i_ret = 1;
-    }
-    else
+    vlc_object_t *p_parent = VLC_OBJECT(p_fetcher->p_playlist);
+    art_finder_t *p_finder =
+        vlc_custom_create( p_parent, sizeof( *p_finder ), VLC_OBJECT_GENERIC,
+                           "art finder" );
+    if( p_finder != NULL)
     {
-        msg_Dbg( p_fetcher, "unable to find art" );
-        i_ret = VLC_EGENERIC;
+        module_t *p_module;
+
+        vlc_object_attach( p_finder, p_parent );
+        p_finder->p_item = p_item;
+
+        p_module = module_need( p_parent, "art finder", NULL, false );
+        if( p_module )
+        {
+            module_unneed( p_finder, p_module );
+            i_ret = 1;
+        }
+        vlc_object_release( p_finder );
     }
 
     /* Record this album */