-
- /* Art need to be put in cache */
- return 1;
- }
-
- PL_LOCK;
- p_playlist->p_private = p_item;
- psz_album = input_item_GetAlbum( p_item );
- psz_artist = input_item_GetArtist( p_item );
- psz_title = input_item_GetTitle( p_item );
- if( !psz_title )
- psz_title = input_item_GetName( 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 );
- }
- free( psz_title );
-
- p_module = module_Need( p_playlist, "art finder", 0, 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.psz_arturl = input_item_GetArtURL( p_item );
- a.b_found = (i_ret == VLC_EGENERIC ? false : 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;
-}
-
-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 )
-{
- 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 )
-{
- char *psz_artist;
- char *psz_album;
- char *psz_title;
- char psz_dirpath[PATH_MAX+1];
- char psz_filepath[PATH_MAX+1];
- char * psz_filename;
- DIR * p_dir;
-
- 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;
- }
-
- ArtCacheGetDirPath( p_obj, psz_dirpath, psz_title,
- psz_artist, psz_album );
-
- free( psz_artist );
- free( psz_album );
- free( psz_title );
-
- /* Check if file exists */
- p_dir = utf8_opendir( psz_dirpath );
- if( !p_dir )
- return VLC_EGENERIC;
-
- while( (psz_filename = utf8_readdir( p_dir )) )
- {
- if( !strncmp( psz_filename, "art", 3 ) )
- {
- snprintf( psz_filepath, PATH_MAX, "file://%s" DIR_SEP "%s",
- psz_dirpath, psz_filename );
- input_item_SetArtURL( p_item, psz_filepath );
- free( psz_filename );
- closedir( p_dir );
- return VLC_SUCCESS;
- }
- free( psz_filename );
- }
-
- /* Not found */
- 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[PATH_MAX+1];
- char *psz_artist = NULL;
- char *psz_album = NULL;
- char *psz_title = 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 );
- if( !psz_title )
- psz_title = input_item_GetName( p_item );
-
- if( !psz_title && (!psz_artist || !psz_album) )
- {
- free( psz_title );
- free( psz_album );
- free( psz_artist );
- return VLC_EGENERIC;