1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2006 VLC authors and VideoLAN
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_art_finder.h>
39 #include <vlc_input_item.h>
41 static const char* cover_files[] = {
42 "Folder.jpg", /* Windows */
43 "AlbumArtSmall.jpg", /* Windows */
44 "AlbumArt.jpg", /* Windows */
46 ".folder.png", /* KDE? */
47 "cover.jpg", /* rockbox */
51 static const int i_covers = (sizeof(cover_files)/sizeof(cover_files[0]));
53 /*****************************************************************************
55 *****************************************************************************/
56 static int FindMeta( vlc_object_t * );
58 /*****************************************************************************
60 *****************************************************************************/
63 set_shortname( N_( "Folder" ) )
64 set_description( N_("Folder meta data") )
65 add_loadfile( "album-art-filename", NULL,
66 N_("Album art filename"), N_("Filename to look for album art in current directory"), false );
67 set_capability( "art finder", 90 )
68 set_callbacks( FindMeta, NULL )
71 /*****************************************************************************
72 *****************************************************************************/
73 static int FindMeta( vlc_object_t *p_this )
75 art_finder_t *p_finder = (art_finder_t *)p_this;
76 input_item_t *p_item = p_finder->p_item;
77 bool b_have_art = false;
82 char *psz_dir = input_item_GetURI( p_item );
86 char *psz_path = make_path( psz_dir );
88 if( psz_path == NULL )
91 char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR );
95 *psz_path = '\0'; /* relative path */
97 for( int i = -1; !b_have_art && i < i_covers; i++ )
100 char *filebuf, *filepath;
102 if( i == -1 ) /* higher priority : configured filename */
104 filebuf = var_InheritString( p_this, "album-art-filename" );
105 if( filebuf == NULL )
111 filename = cover_files[i];
115 if( asprintf( &filepath, "%s%s", psz_path, filename ) == -1 )
118 if( unlikely(filepath == NULL) )
122 if( vlc_stat( filepath, &dummy ) == 0 )
124 char *psz_uri = vlc_path2uri( filepath, "file" );
127 input_item_SetArtURL( p_item, psz_uri );
136 return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;