packetizer: hevc: add poc debug
[vlc.git] / modules / meta_engine / folder.c
blobd243172973eef9219e11ee07b7f1951cacfbb617
1 /*****************************************************************************
2 * folder.c
3 *****************************************************************************
4 * Copyright (C) 2006 VLC authors and VideoLAN
5 * $Id$
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 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <sys/stat.h>
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_meta_fetcher.h>
37 #include <vlc_fs.h>
38 #include <vlc_url.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 */
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 static const int i_covers = (sizeof(cover_files)/sizeof(cover_files[0]));
59 /*****************************************************************************
60 * Local prototypes
61 *****************************************************************************/
62 static int FindMeta( vlc_object_t * );
64 /*****************************************************************************
65 * Module descriptor
66 *****************************************************************************/
68 vlc_module_begin ()
69 set_shortname( N_( "Folder" ) )
70 set_description( N_("Folder meta data") )
71 add_loadfile( "album-art-filename", NULL,
72 N_("Album art filename"), N_("Filename to look for album art in current directory"), false );
73 set_capability( "art finder", 90 )
74 set_callbacks( FindMeta, NULL )
75 vlc_module_end ()
77 /*****************************************************************************
78 *****************************************************************************/
79 static int FindMeta( vlc_object_t *p_this )
81 meta_fetcher_t *p_finder = (meta_fetcher_t *)p_this;
82 input_item_t *p_item = p_finder->p_item;
83 bool b_have_art = false;
84 struct stat statinfo;
85 char *psz_path = NULL;
87 if( !p_item )
88 return VLC_EGENERIC;
90 char *psz_uri = input_item_GetURI( p_item );
91 if( !psz_uri )
92 return VLC_EGENERIC;
94 if ( *psz_uri && psz_uri[strlen( psz_uri ) - 1] != DIR_SEP_CHAR )
96 if ( asprintf( &psz_path, "%s"DIR_SEP, psz_uri ) == -1 )
98 free( psz_uri );
99 return VLC_EGENERIC;
101 char *psz_basedir = vlc_uri2path( psz_path );
102 FREENULL( psz_path );
103 if( psz_basedir == NULL )
105 free( psz_uri );
106 return VLC_EGENERIC;
108 if( vlc_stat( psz_basedir, &statinfo ) == 0 && S_ISDIR(statinfo.st_mode) )
109 psz_path = psz_basedir;
110 else
111 free( psz_basedir );
114 if ( psz_path == NULL )
116 char *psz_basedir = vlc_uri2path( psz_uri );
117 if( psz_basedir == NULL )
119 free( psz_uri );
120 return VLC_EGENERIC;
123 char *psz_buf = strrchr( psz_basedir, DIR_SEP_CHAR );
124 if( psz_buf )
125 *++psz_buf = '\0';
126 else
127 *psz_basedir = '\0'; /* relative path */
128 psz_path = psz_basedir;
131 free( psz_uri );
133 for( int i = -1; !b_have_art && i < i_covers; i++ )
135 const char *filename;
136 char *filebuf, *filepath;
138 if( i == -1 ) /* higher priority : configured filename */
140 filebuf = var_InheritString( p_this, "album-art-filename" );
141 if( filebuf == NULL )
142 continue;
143 filename = filebuf;
145 else
147 filename = cover_files[i];
148 filebuf = NULL;
151 if( asprintf( &filepath, "%s%s", psz_path, filename ) == -1 )
152 filepath = NULL;
153 free( filebuf );
154 if( unlikely(filepath == NULL) )
155 continue;
157 if( vlc_stat( filepath, &statinfo ) == 0 && S_ISREG(statinfo.st_mode) )
159 char *psz_uri = vlc_path2uri( filepath, "file" );
160 if( psz_uri )
162 input_item_SetArtURL( p_item, psz_uri );
163 free( psz_uri );
164 b_have_art = true;
167 free( filepath );
169 free( psz_path );
171 return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;