- input_FindArtInCache( p_playlist, p_item );
- if( !EMPTY_STR( psz_arturl ) )
- {
- free( psz_arturl );
- return 0;
- }
- free( psz_arturl );
-
- PL_LOCK;
- p_playlist->p_private = p_item;
- psz_album = input_item_GetAlbum( p_item );
- psz_artist = input_item_GetArtist( p_item );
- psz_name = input_item_GetName( p_item );
- psz_title = input_item_GetTitle( p_item );
- if( psz_album && psz_artist )
- {
- msg_Dbg( p_playlist, "searching art for %s - %s",
- psz_artist, psz_album );
- }
- else
- {
- msg_Dbg( p_playlist, "searching art for %s",
- psz_title ? psz_title : psz_name );
- }
- free( psz_title );
- free( psz_name );
-
- p_module = module_Need( p_playlist, "art finder", 0, VLC_FALSE );
-
- if( p_module )
- i_ret = 1;
- else
- msg_Dbg( p_playlist, "unable to find art" );
-
- /* Record this album */
- if( psz_artist && psz_album )
- {
- playlist_album_t a;
- a.psz_artist = psz_artist;
- a.psz_album = psz_album;
- a.b_found = (i_ret == VLC_EGENERIC ? VLC_FALSE : VLC_TRUE );
- ARRAY_APPEND( p_playlist->p_fetcher->albums, a );
- }
- else
- {
- free( psz_artist );
- free( psz_album );
- }
-
- if( p_module )
- module_Unneed( p_playlist, p_module );
- p_playlist->p_private = NULL;
- PL_UNLOCK;
-
- return i_ret;
-}
-
-#ifndef MAX_PATH
-# define MAX_PATH 250
-#endif
-static void ArtCacheCreateDir( const char *psz_dir )
-{
- char newdir[MAX_PATH+1];
- strcpy( newdir, psz_dir );
- char * psz_newdir = newdir;
- char * psz = psz_newdir;
-
- while( *psz_newdir )
- {
- while( *psz && *psz != '/') psz++;
- if( !*psz ) break;
- *psz = 0;
- if( !EMPTY_STR( psz_newdir ) ) utf8_mkdir( psz_newdir );
- psz_newdir = psz+1;
- }
-}
-
-static char *ArtCacheCreateString( const char *psz )
-{
- char *dup = strdup(psz);
- int i;
-
- /* 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] == '/' )
- dup[i] = ' ';
- }
- return dup;
-}
-
-#define ArtCacheGetDirName(a,b,c,d,e) __ArtCacheGetDirName(VLC_OBJECT(a),b,c,d,e)
-static void __ArtCacheGetDirName( vlc_object_t *p_obj,
- char *psz_dir,
- char *psz_title,
- char *psz_artist, char *psz_album )
-{
- if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
- {
- filename_sanitize( psz_title );
- filename_sanitize( psz_artist );
-
- snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR DIR_SEP
- "art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s",
- p_obj->p_libvlc->psz_homedir,
- psz_artist, psz_album );
- }
- else
- {
- filename_sanitize( psz_title );
- snprintf( psz_dir, MAX_PATH, "%s" DIR_SEP CONFIG_DIR DIR_SEP
- "art" DIR_SEP "title" DIR_SEP "%s",
- p_obj->p_libvlc->psz_homedir, psz_title );
- }
-}
-
-
-
-#define ArtCacheGetFileName(a,b,c,d,e,f) __ArtCacheGetFileName(VLC_OBJECT(a),b,c,d,e,f)
-static void __ArtCacheGetFileName( vlc_object_t *p_obj,
- char * psz_filename,
- char *psz_title,
- char *psz_artist, char *psz_album,
- const char *psz_extension )
-{
- char psz_dir[MAX_PATH+1];
- char * psz_ext;
- ArtCacheGetDirName( 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, MAX_PATH, "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 )
-{
- char *psz_artist;
- char *psz_album;
- char *psz_title;
- char psz_dirname[MAX_PATH+1];
- char psz_filename[MAX_PATH+1];
- struct dirent * p_de;
- DIR * p_dir;
-
- if( !p_item->p_meta ) return VLC_EGENERIC;
-
- psz_artist = input_item_GetArtist( p_item );
- psz_album = input_item_GetAlbum( p_item );
- psz_title = input_item_GetTitle( p_item );
- if( !psz_title ) psz_title = input_item_GetName( p_item );
-
- if( !psz_title && ( !psz_album || !psz_artist ) )
- {
- free( psz_artist );
- free( psz_album );
- free( psz_title );
- return VLC_EGENERIC;
- }
-
- ArtCacheGetDirName( p_obj, psz_dirname, psz_title,
- psz_artist, psz_album );
-
- free( psz_artist );
- free( psz_album );
- free( psz_title );
-
- /* Check if file exists */
- p_dir = utf8_opendir( psz_dirname );
- if( !p_dir )
- return VLC_EGENERIC;
-
- while( (p_de = readdir( p_dir )) )
- {
- if( strncmp( p_de->d_name, "art", 3 ) )
- {
- snprintf( psz_filename, MAX_PATH, "%s" DIR_SEP "%s",
- psz_dirname, p_de->d_name );
- input_item_SetArtURL( p_item, psz_filename );
- closedir( p_dir );
- return VLC_SUCCESS;
- }
- }
-
- closedir( p_dir );
- return VLC_EGENERIC;
-}
-
-/**
- * Download the art using the URL or an art downloaded
- * This function should be called only if data is not already in cache
- */
-int input_DownloadAndCacheArt( playlist_t *p_playlist, input_item_t *p_item )
-{
- int i_status = VLC_EGENERIC;
- stream_t *p_stream;
- char psz_filename[MAX_PATH+1];
- char *psz_artist = NULL;
- char *psz_album = NULL;
- char *psz_title = NULL;
- char *psz_name = NULL;
- char *psz_arturl;
- char *psz_type;
-
- psz_artist = input_item_GetArtist( p_item );
- psz_album = input_item_GetAlbum( p_item );
- psz_title = input_item_GetTitle( p_item );
- psz_name = input_item_GetName( p_item );
-
- if( !psz_title && (!psz_artist || !psz_album) )
- {
- free( psz_title );
- free( psz_album );
- free( psz_artist );
- return VLC_EGENERIC;
- }
-
- psz_arturl = input_item_GetArtURL( p_item );
- assert( !EMPTY_STR( psz_arturl ) );
-
- if( !strncmp( psz_arturl , "APIC", 4 ) )