X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fmeta_engine%2Ffolder.c;h=99c640ce0a3efd52d6f2fafdb3231e6ea9c0f704;hb=c60652e38ac6afd74bd8225e9dae5406f13aaa4f;hp=10252dbc322f0bf360ea3ed018b91ca69742f061;hpb=e40d134c69b144327fd1d2001e8b85640f5c7cb9;p=vlc diff --git a/modules/meta_engine/folder.c b/modules/meta_engine/folder.c index 10252dbc32..99c640ce0a 100644 --- a/modules/meta_engine/folder.c +++ b/modules/meta_engine/folder.c @@ -25,12 +25,16 @@ * Preamble *****************************************************************************/ -#include -#include -#include -#include -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include +#include +#include #ifdef HAVE_SYS_STAT_H # include @@ -40,6 +44,15 @@ # define MAX_PATH 250 #endif +static const char* cover_files[] = { + "Folder.jpg", /* Windows */ + "AlbumArtSmall.jpg", /* Windows */ + ".folder.png", /* KDE? */ + "cover.jpg", /* rockbox */ +}; + +static const int i_covers = (sizeof(cover_files)/sizeof(cover_files[0])); + /***************************************************************************** * Local prototypes *****************************************************************************/ @@ -49,73 +62,70 @@ static int FindMeta( vlc_object_t * ); * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_shortname( N_( "Folder" ) ); - set_description( _("Folder meta data") ); - - set_capability( "art finder", 90 ); - set_callbacks( FindMeta, NULL ); -vlc_module_end(); +vlc_module_begin () + set_shortname( N_( "Folder" ) ) + set_description( N_("Folder meta data") ) + add_file( "album-art-filename", NULL, 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 ) +vlc_module_end () /***************************************************************************** *****************************************************************************/ static int FindMeta( vlc_object_t *p_this ) { - playlist_t *p_playlist = (playlist_t *)p_this; - input_item_t *p_item = (input_item_t *)(p_playlist->p_private); - vlc_bool_t b_have_art = VLC_FALSE; + 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 = 0; + int i; struct stat a; char psz_filename[MAX_PATH]; - char *psz_dir = strdup( p_item->psz_uri ); - char *psz_buf = strrchr( psz_dir, '/' ); + if( !p_item ) + return VLC_EGENERIC; + + char *psz_dir = input_item_GetURI( p_item ); + if( !psz_dir ) + return VLC_EGENERIC; + + char *psz_path = make_path( psz_dir ); + free( psz_dir ); + if( psz_path == NULL ) + return VLC_EGENERIC; + + char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR ); if( psz_buf ) - { - psz_buf++; - *psz_buf = '\0'; - } + *++psz_buf = '\0'; else - { - *psz_dir = '\0'; - } - - char *psz_path = psz_dir; - if( !strncmp( psz_path, "file://", 7 ) ) - psz_path += 7; + *psz_path = '\0'; /* relative path */ - for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ ) + for( i = -1; !b_have_art && i < i_covers; i++ ) { - switch( i ) + if( i == -1 ) /* higher priority : configured filename */ { - case 0: - /* Windows Folder.jpg */ - snprintf( psz_filename, MAX_PATH, - "file://%sFolder.jpg", psz_path ); - break; - - case 1: - /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */ - snprintf( psz_filename, MAX_PATH, - "file://%sAlbumArtSmall.jpg", psz_path ); - break; - - case 2: - /* KDE (?) .folder.png */ - snprintf( psz_filename, MAX_PATH, - "file://%s.folder.png", psz_path ); - break; + char *psz_userfile = var_InheritString( p_this, "album-art-filename" ); + if( !psz_userfile ) + continue; + snprintf( psz_filename, MAX_PATH, "%s%s", psz_path, psz_userfile ); + free( psz_userfile ); } + else + snprintf( psz_filename, MAX_PATH, "%s%s", psz_path, cover_files[i] ); - if( utf8_stat( psz_filename+7, &a ) != -1 ) + if( vlc_stat( psz_filename, &a ) != -1 ) { - input_item_SetArtURL( p_item, psz_filename ); - b_have_art = VLC_TRUE; + char *psz_uri = make_URI( psz_filename, "file" ); + if( psz_uri ) + { + input_item_SetArtURL( p_item, psz_uri ); + free( psz_uri ); + b_have_art = true; + } } } - - free( psz_dir ); + free( psz_path ); return b_have_art ? VLC_SUCCESS : VLC_EGENERIC; }