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_meta_fetcher.h>
39 #include <vlc_input_item.h>
41 static const char cover_files
[][20] = {
42 "Folder.jpg", /* Windows */
44 "AlbumArtSmall.jpg", /* Windows */
45 "AlbumArt.jpg", /* Windows */
47 ".folder.png", /* KDE? */
48 "cover.jpg", /* rockbox */
58 /*****************************************************************************
60 *****************************************************************************/
61 static int FindMeta( vlc_object_t
* );
63 /*****************************************************************************
65 *****************************************************************************/
68 set_shortname( N_( "Folder" ) )
69 set_description( N_("Folder meta data") )
70 add_loadfile("album-art-filename", NULL
, N_("Album art filename"),
71 N_("Filename to look for album art in current directory"))
72 set_capability( "art finder", 90 )
73 set_callbacks( FindMeta
, NULL
)
76 static bool ProbeArtFile(input_item_t
*item
,
77 const char *dirpath
, const char *filename
)
83 if (asprintf(&filepath
, "%s"DIR_SEP
"%s", dirpath
, filename
) == -1)
86 if (vlc_stat(filepath
, &st
) == 0 && S_ISREG(st
.st_mode
))
88 char *url
= vlc_path2uri(filepath
, "file");
89 if (likely(url
!= NULL
))
91 input_item_SetArtURL(item
, url
);
101 static int FindMeta( vlc_object_t
*p_this
)
103 meta_fetcher_t
*p_finder
= (meta_fetcher_t
*)p_this
;
104 input_item_t
*p_item
= p_finder
->p_item
;
109 char *psz_uri
= input_item_GetURI( p_item
);
113 char *psz_basedir
= vlc_uri2path(psz_uri
);
115 if (psz_basedir
== NULL
)
118 /* If the item is an accessible directory, look for art inside it.
119 * Otherwise, look for art in the same directory. */
121 if (vlc_stat(psz_basedir
, &st
) == 0 && !S_ISDIR(st
.st_mode
))
123 char *psz_buf
= strrchr( psz_basedir
, DIR_SEP_CHAR
);
128 int ret
= VLC_EGENERIC
;
130 char *filename
= var_InheritString(p_this
, "album-art-filename");
131 if (filename
!= NULL
&& ProbeArtFile(p_item
, psz_basedir
, filename
))
135 for (size_t i
= 0; i
< ARRAY_SIZE(cover_files
); i
++)
136 if (ProbeArtFile(p_item
, psz_basedir
, cover_files
[i
]))