meta/folder: fix options being hidden in GUI
[vlc.git] / modules / meta_engine / folder.c
blob9d7e72b3f11afb3c64c9e6f8c1299b5200b676e7
1 /*****************************************************************************
2 * folder.c
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 /*****************************************************************************
24 * Preamble
25 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <sys/stat.h>
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
35 #include <vlc_meta_fetcher.h>
36 #include <vlc_fs.h>
37 #include <vlc_url.h>
38 #include <vlc_input_item.h>
40 static const char cover_files[][20] = {
41 "Folder.jpg", /* Windows */
42 "Folder.png",
43 "AlbumArtSmall.jpg", /* Windows */
44 "AlbumArt.jpg", /* Windows */
45 "Album.jpg",
46 ".folder.png", /* KDE? */
47 "cover.jpg", /* rockbox */
48 "cover.png",
49 "cover.gif",
50 "front.jpg",
51 "front.png",
52 "front.gif",
53 "front.bmp",
54 "thumb.jpg",
57 /*****************************************************************************
58 * Local prototypes
59 *****************************************************************************/
60 static int FindMeta( vlc_object_t * );
62 /*****************************************************************************
63 * Module descriptor
64 *****************************************************************************/
66 vlc_module_begin ()
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 )
75 vlc_module_end ()
77 static bool ProbeArtFile(input_item_t *item,
78 const char *dirpath, const char *filename)
80 char *filepath;
81 struct stat st;
82 bool found = false;
84 if (asprintf(&filepath, "%s"DIR_SEP"%s", dirpath, filename) == -1)
85 return false;
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);
93 free(url);
94 found = true;
98 free(filepath);
99 return found;
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;
107 if( !p_item )
108 return VLC_EGENERIC;
110 char *psz_uri = input_item_GetURI( p_item );
111 if( !psz_uri )
112 return VLC_EGENERIC;
114 char *psz_basedir = vlc_uri2path(psz_uri);
115 free(psz_uri);
116 if (psz_basedir == NULL)
117 return VLC_EGENERIC;
119 /* If the item is an accessible directory, look for art inside it.
120 * Otherwise, look for art in the same directory. */
121 struct stat st;
122 if (vlc_stat(psz_basedir, &st) == 0 && !S_ISDIR(st.st_mode))
124 char *psz_buf = strrchr( psz_basedir, DIR_SEP_CHAR );
125 if (psz_buf != NULL)
126 *psz_buf = '\0';
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))
133 ret = VLC_SUCCESS;
134 else
136 for (size_t i = 0; i < ARRAY_SIZE(cover_files); i++)
137 if (ProbeArtFile(p_item, psz_basedir, cover_files[i]))
139 ret = VLC_SUCCESS;
140 break;
144 free(psz_basedir);
145 return ret;