1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2006 VLC authors and VideoLAN
6 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_meta_fetcher.h>
38 #include <vlc_input_item.h>
40 static const char cover_files
[][20] = {
41 "Folder.jpg", /* Windows */
43 "AlbumArtSmall.jpg", /* Windows */
44 "AlbumArt.jpg", /* Windows */
46 ".folder.png", /* KDE? */
47 "cover.jpg", /* rockbox */
57 /*****************************************************************************
59 *****************************************************************************/
60 static int FindMeta( vlc_object_t
* );
62 /*****************************************************************************
64 *****************************************************************************/
67 set_shortname( N_( "Folder" ) )
68 set_description( N_("Folder meta data") )
69 set_category( CAT_PLAYLIST
)
70 set_subcategory( SUBCAT_PLAYLIST_GENERAL
)
71 add_loadfile("album-art-filename", NULL
, N_("Album art filename"),
72 N_("Filename to look for album art in current directory"))
73 set_capability( "art finder", 90 )
74 set_callback( FindMeta
)
77 static bool ProbeArtFile(input_item_t
*item
,
78 const char *dirpath
, const char *filename
)
84 if (asprintf(&filepath
, "%s"DIR_SEP
"%s", dirpath
, filename
) == -1)
87 if (vlc_stat(filepath
, &st
) == 0 && S_ISREG(st
.st_mode
))
89 char *url
= vlc_path2uri(filepath
, "file");
90 if (likely(url
!= NULL
))
92 input_item_SetArtURL(item
, url
);
102 static int FindMeta( vlc_object_t
*p_this
)
104 meta_fetcher_t
*p_finder
= (meta_fetcher_t
*)p_this
;
105 input_item_t
*p_item
= p_finder
->p_item
;
110 char *psz_uri
= input_item_GetURI( p_item
);
114 char *psz_basedir
= vlc_uri2path(psz_uri
);
116 if (psz_basedir
== NULL
)
119 /* If the item is an accessible directory, look for art inside it.
120 * Otherwise, look for art in the same directory. */
122 if (vlc_stat(psz_basedir
, &st
) == 0 && !S_ISDIR(st
.st_mode
))
124 char *psz_buf
= strrchr( psz_basedir
, DIR_SEP_CHAR
);
129 int ret
= VLC_EGENERIC
;
131 char *filename
= var_InheritString(p_this
, "album-art-filename");
132 if (filename
!= NULL
&& ProbeArtFile(p_item
, psz_basedir
, filename
))
136 for (size_t i
= 0; i
< ARRAY_SIZE(cover_files
); i
++)
137 if (ProbeArtFile(p_item
, psz_basedir
, cover_files
[i
]))