Commit 2af1ee85 authored by Rémi Duraffort's avatar Rémi Duraffort

playlist_art: simplify.

parent 7b4a81eb
...@@ -63,65 +63,64 @@ static void ArtCacheCreateDir( const char *psz_dir ) ...@@ -63,65 +63,64 @@ static void ArtCacheCreateDir( const char *psz_dir )
utf8_mkdir( psz_dir, 0700 ); utf8_mkdir( psz_dir, 0700 );
} }
static void ArtCacheGetDirPath( char *psz_dir, static char* ArtCacheGetDirPath( const char *psz_title, const char *psz_artist,
const char *psz_title, const char *psz_album )
const char *psz_artist, const char *psz_album )
{ {
char *psz_dir;
char *psz_cachedir = config_GetCacheDir(); char *psz_cachedir = config_GetCacheDir();
if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) ) if( !EMPTY_STR(psz_artist) && !EMPTY_STR(psz_album) )
{ {
char *psz_album_sanitized = filename_sanitize( psz_album ); char *psz_album_sanitized = filename_sanitize( psz_album );
char *psz_artist_sanitized = filename_sanitize( psz_artist ); char *psz_artist_sanitized = filename_sanitize( psz_artist );
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP if( asprintf( &psz_dir, "%s" DIR_SEP "art" DIR_SEP "artistalbum"
"art" DIR_SEP "artistalbum" DIR_SEP "%s" DIR_SEP "%s", DIR_SEP "%s" DIR_SEP "%s", psz_cachedir,
psz_cachedir, psz_artist_sanitized, psz_album_sanitized ); psz_artist_sanitized, psz_album_sanitized ) == -1 )
psz_dir = NULL;
free( psz_album_sanitized ); free( psz_album_sanitized );
free( psz_artist_sanitized ); free( psz_artist_sanitized );
} }
else else
{ {
char * psz_title_sanitized = filename_sanitize( psz_title ); char * psz_title_sanitized = filename_sanitize( psz_title );
snprintf( psz_dir, PATH_MAX, "%s" DIR_SEP if( asprintf( &psz_dir, "%s" DIR_SEP "art" DIR_SEP "title" DIR_SEP
"art" DIR_SEP "title" DIR_SEP "%s", "%s", psz_cachedir, psz_title_sanitized ) == -1 )
psz_cachedir, psz_title_sanitized ); psz_dir = NULL;
free( psz_title_sanitized ); free( psz_title_sanitized );
} }
free( psz_cachedir ); free( psz_cachedir );
return psz_dir;
} }
static char *ArtCachePath( input_item_t *p_item ) static char *ArtCachePath( input_item_t *p_item )
{ {
char psz_path[PATH_MAX+1]; /* FIXME */ char* psz_path = NULL;
const char *psz_artist;
const char *psz_album;
const char *psz_title;
vlc_mutex_lock( &p_item->lock ); vlc_mutex_lock( &p_item->lock );
if( !p_item->p_meta ) if( !p_item->p_meta )
p_item->p_meta = vlc_meta_New(); p_item->p_meta = vlc_meta_New();
if( !p_item->p_meta ) if( !p_item->p_meta )
{ goto end;
vlc_mutex_unlock( &p_item->lock );
return NULL;
}
const char *psz_artist = vlc_meta_Get( p_item->p_meta, vlc_meta_Artist ); psz_artist = vlc_meta_Get( p_item->p_meta, vlc_meta_Artist );
const char *psz_album = vlc_meta_Get( p_item->p_meta, vlc_meta_Album ); psz_album = vlc_meta_Get( p_item->p_meta, vlc_meta_Album );
const char *psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title ); psz_title = vlc_meta_Get( p_item->p_meta, vlc_meta_Title );
if( !psz_title ) if( !psz_title )
psz_title = p_item->psz_name; psz_title = p_item->psz_name;
if( (!psz_artist || !psz_album ) && !psz_title ) if( (!psz_artist || !psz_album ) && !psz_title )
{ goto end;
vlc_mutex_unlock( &p_item->lock );
return NULL;
}
ArtCacheGetDirPath( psz_path, psz_title, psz_artist, psz_album ); psz_path = ArtCacheGetDirPath( psz_title, psz_artist, psz_album );
end:
vlc_mutex_unlock( &p_item->lock ); vlc_mutex_unlock( &p_item->lock );
return psz_path;
return strdup( psz_path );
} }
static char *ArtCacheName( input_item_t *p_item, const char *psz_type ) static char *ArtCacheName( input_item_t *p_item, const char *psz_type )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment