]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
Fix bogus warnings
[vlc] / modules / meta_engine / folder.c
1 /*****************************************************************************
2  * folder.c
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #define _GNU_SOURCE
28 #include <stdlib.h>                                      /* malloc(), free() */
29
30 #include <vlc/vlc.h>
31 #include <vlc/intf.h>
32 #include <vlc_meta.h>
33 #include <charset.h>
34
35 #ifdef HAVE_SYS_STAT_H
36 #   include <sys/stat.h>
37 #endif
38
39 #ifndef MAX_PATH
40 #   define MAX_PATH 250
41 #endif
42
43 /*****************************************************************************
44  * Local prototypes
45  *****************************************************************************/
46 static int FindMeta( vlc_object_t * );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51
52 vlc_module_begin();
53     set_shortname( N_( "Folder" ) );
54     set_description( _("Folder meta data") );
55
56     set_capability( "art finder", 10 );
57     set_callbacks( FindMeta, NULL );
58 vlc_module_end();
59
60 /*****************************************************************************
61  *****************************************************************************/
62 static int FindMeta( vlc_object_t *p_this )
63 {
64     playlist_t *p_playlist = (playlist_t *)p_this;
65     input_item_t *p_item = (input_item_t *)(p_playlist->p_private);
66     vlc_bool_t b_have_art = VLC_FALSE;
67
68     int i = 0;
69     struct stat a;
70     char psz_filename[MAX_PATH];
71     char *psz_dir = strdup( p_item->psz_uri );
72     char *psz_buf = strrchr( psz_dir, '/' );
73
74     if( !p_item->p_meta ) return VLC_EGENERIC;
75     if( psz_buf )
76     {
77         psz_buf++;
78         *psz_buf = '\0';
79     }
80     else
81     {
82         *psz_dir = '\0';
83     }
84
85     for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
86     {
87         switch( i )
88         {
89             case 0:
90             /* Windows Folder.jpg */
91             snprintf( psz_filename, MAX_PATH,
92                       "file://%sFolder.jpg", psz_dir );
93             break;
94
95             case 1:
96             /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
97             snprintf( psz_filename, MAX_PATH,
98                   "file://%sAlbumArtSmall.jpg", psz_dir );
99             break;
100
101             case 2:
102             /* KDE (?) .folder.png */
103             snprintf( psz_filename, MAX_PATH,
104                   "file://%s.folder.png", psz_dir );
105             break;
106         }
107
108         if( utf8_stat( psz_filename+7, &a ) != -1 )
109         {
110             vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
111             b_have_art = VLC_TRUE;
112         }
113     }
114
115     free( psz_dir );
116
117     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
118 }