]> git.sesse.net Git - vlc/blobdiff - modules/meta_engine/folder.c
grain: fix clobber list
[vlc] / modules / meta_engine / folder.c
index 9ef715f44591e706dd2b9f8f850c5ceddb863b16..46337908c49728e8d524b96397a3de288edac661 100644 (file)
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_playlist.h>
-#include <vlc_charset.h>
+#include <vlc_art_finder.h>
+#include <vlc_fs.h>
 #include <vlc_url.h>
+#include <vlc_input_item.h>
 
 #ifdef HAVE_SYS_STAT_H
 #   include <sys/stat.h>
 #endif
 
-#ifndef MAX_PATH
-#   define MAX_PATH 250
-#endif
-
 static const char* cover_files[] = {
     "Folder.jpg",           /* Windows */
     "AlbumArtSmall.jpg",    /* Windows */
@@ -64,7 +61,7 @@ static int FindMeta( vlc_object_t * );
 vlc_module_begin ()
     set_shortname( N_( "Folder" ) )
     set_description( N_("Folder meta data") )
-    add_file( "album-art-filename", NULL, NULL,
+    add_loadfile( "album-art-filename", NULL,
         N_("Album art filename"), N_("Filename to look for album art in current directory"), false );
     set_capability( "art finder", 90 )
     set_callbacks( FindMeta, NULL )
@@ -74,13 +71,10 @@ 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;
-    struct stat a;
-    char psz_filename[MAX_PATH];
-
     if( !p_item )
         return VLC_EGENERIC;
 
@@ -88,41 +82,45 @@ static int FindMeta( vlc_object_t *p_this )
     if( !psz_dir )
         return VLC_EGENERIC;
 
-    char *psz_path = psz_dir;
-    if( strncmp( psz_path, "file://", 7 ) || !decode_URI( psz_path + 7 ) )
-    {
-        free( psz_dir );
+    char *psz_path = make_path( psz_dir );
+    free( psz_dir );
+    if( psz_path == NULL )
         return VLC_EGENERIC;
-    }
-
-#if defined(WIN32) && !defined(UNDER_CE)
-    psz_path += 8;
-#else
-    psz_path += 7;
-#endif
 
-    char *psz_buf = strrchr( psz_path, '/' );
+    char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR );
     if( psz_buf )
         *++psz_buf = '\0';
     else
         *psz_path = '\0'; /* relative path */
 
-    for( i = -1; !b_have_art && i < i_covers; i++ )
+    for( int i = -1; !b_have_art && i < i_covers; i++ )
     {
+        const char *filename;
+        char *filebuf, *filepath;
+
         if( i == -1 ) /* higher priority : configured filename */
         {
-            char *psz_userfile = config_GetPsz( p_this, "album-art-filename" );
-            if( !psz_userfile )
+            filebuf = var_InheritString( p_this, "album-art-filename" );
+            if( filebuf == NULL )
                 continue;
-            snprintf( psz_filename, MAX_PATH, "%s%s", psz_path, psz_userfile );
-            free( psz_userfile );
+            filename = filebuf;
         }
         else
-            snprintf( psz_filename, MAX_PATH, "%s%s", psz_path, cover_files[i] );
+        {
+            filename = cover_files[i];
+            filebuf = NULL;
+        }
 
-        if( utf8_stat( psz_filename, &a ) != -1 )
+        if( asprintf( &filepath, "%s%s", psz_path, filename ) == -1 )
+            filepath = NULL;
+        free( filebuf );
+        if( unlikely(filepath == NULL) )
+            continue;
+
+        struct stat dummy;
+        if( vlc_stat( filepath, &dummy ) == 0 )
         {
-            char *psz_uri = make_URI( psz_filename );
+            char *psz_uri = make_URI( filepath, "file" );
             if( psz_uri )
             {
                 input_item_SetArtURL( p_item, psz_uri );
@@ -130,9 +128,9 @@ static int FindMeta( vlc_object_t *p_this )
                 b_have_art = true;
             }
         }
+        free( filepath );
     }
-
-    free( psz_dir );
+    free( psz_path );
 
     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
 }