+static void ArtCacheCreateDir( const char *psz_dir )
+{
+ char newdir[strlen( psz_dir ) + 1];
+ strcpy( newdir, psz_dir );
+ char * psz_newdir = newdir;
+ char * psz = psz_newdir;
+
+ while( *psz )
+ {
+ while( *psz && *psz != DIR_SEP_CHAR) psz++;
+ if( !*psz ) break;
+ *psz = 0;
+ if( !EMPTY_STR( psz_newdir ) )
+ utf8_mkdir( psz_newdir, 0700 );
+ *psz = DIR_SEP_CHAR;
+ psz++;
+ }
+ utf8_mkdir( psz_dir, 0700 );
+}
+
+static char * ArtCacheGetSanitizedFileName( const char *psz )
+{
+ char *dup = strdup(psz);
+ int i;
+
+ filename_sanitize( dup );
+
+ /* Doesn't create a filename with invalid characters
+ * TODO: several filesystems forbid several characters: list them all
+ */
+ for( i = 0; dup[i] != '\0'; i++ )
+ {
+ if( dup[i] == DIR_SEP_CHAR )
+ dup[i] = ' ';
+ }
+ return dup;
+}
+
+#define ArtCacheGetDirPath(a,b,c,d,e) __ArtCacheGetDirPath(VLC_OBJECT(a),b,c,d,e)
+static void __ArtCacheGetDirPath( vlc_object_t *p_obj,
+ char *psz_dir,
+ const char *psz_title,
+ const char *psz_artist, const char *psz_album )
+{
+ (void)p_obj;
+ char *psz_cachedir = config_GetCacheDir();
+
+ if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
+ {
+ char * psz_album_sanitized = ArtCacheGetSanitizedFileName( psz_album );
+ char * psz_artist_sanitized = ArtCacheGetSanitizedFileName( psz_artist );
+ snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
+ "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
+ psz_cachedir, psz_artist_sanitized, psz_album_sanitized );
+ free( psz_album_sanitized );
+ free( psz_artist_sanitized );
+ }
+ else
+ {
+ char * psz_title_sanitized = ArtCacheGetSanitizedFileName( psz_title );
+ snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP
+ "art" DIR_SEP "title" DIR_SEP "%s",
+ psz_cachedir, psz_title_sanitized );
+ free( psz_title_sanitized );
+ }
+ free( psz_cachedir );
+}
+
+
+
+#define ArtCacheGetFilePath(a,b,c,d,e,f) __ArtCacheGetFilePath(VLC_OBJECT(a),b,c,d,e,f)
+static void __ArtCacheGetFilePath( vlc_object_t *p_obj,
+ char * psz_filename,
+ const char *psz_title,
+ const char *psz_artist, const char *psz_album,
+ const char *psz_extension )
+{
+ char psz_dir[PATH_MAX+1];
+ char * psz_ext;
+ ArtCacheGetDirPath( p_obj, psz_dir, psz_title, psz_artist, psz_album );
+
+ if( psz_extension )
+ {
+ psz_ext = strndup( psz_extension, 6 );
+ filename_sanitize( psz_ext );
+ }
+ else psz_ext = strdup( "" );
+
+ snprintf( psz_filename, PATH_MAX, "file://%s" DIR_SEP "art%s",
+ psz_dir, psz_ext );
+
+ free( psz_ext );
+}
+
+static int __input_FindArtInCache( vlc_object_t *p_obj, input_item_t *p_item )