]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
A bit of headers cleanup
[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_interface.h>
32 #include <vlc_meta.h>
33 #include <vlc_playlist.h>
34 #include <vlc_input.h>
35 #include <vlc_charset.h>
36
37 #ifdef HAVE_SYS_STAT_H
38 #   include <sys/stat.h>
39 #endif
40
41 #ifndef MAX_PATH
42 #   define MAX_PATH 250
43 #endif
44
45 /*****************************************************************************
46  * Local prototypes
47  *****************************************************************************/
48 static int FindMeta( vlc_object_t * );
49
50 /*****************************************************************************
51  * Module descriptor
52  *****************************************************************************/
53
54 vlc_module_begin();
55     set_shortname( N_( "Folder" ) );
56     set_description( _("Folder meta data") );
57
58     set_capability( "art finder", 10 );
59     set_callbacks( FindMeta, NULL );
60 vlc_module_end();
61
62 /*****************************************************************************
63  *****************************************************************************/
64 static int FindMeta( vlc_object_t *p_this )
65 {
66     playlist_t *p_playlist = (playlist_t *)p_this;
67     input_item_t *p_item = (input_item_t *)(p_playlist->p_private);
68     vlc_bool_t b_have_art = VLC_FALSE;
69
70     int i = 0;
71     struct stat a;
72     char psz_filename[MAX_PATH];
73     char *psz_dir = strdup( p_item->psz_uri );
74     char *psz_buf = strrchr( psz_dir, '/' );
75
76     if( !p_item->p_meta ) return VLC_EGENERIC;
77     if( psz_buf )
78     {
79         psz_buf++;
80         *psz_buf = '\0';
81     }
82     else
83     {
84         *psz_dir = '\0';
85     }
86
87     for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
88     {
89         switch( i )
90         {
91             case 0:
92             /* Windows Folder.jpg */
93             snprintf( psz_filename, MAX_PATH,
94                       "file://%sFolder.jpg", psz_dir );
95             break;
96
97             case 1:
98             /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
99             snprintf( psz_filename, MAX_PATH,
100                   "file://%sAlbumArtSmall.jpg", psz_dir );
101             break;
102
103             case 2:
104             /* KDE (?) .folder.png */
105             snprintf( psz_filename, MAX_PATH,
106                   "file://%s.folder.png", psz_dir );
107             break;
108         }
109
110         if( utf8_stat( psz_filename+7, &a ) != -1 )
111         {
112             vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
113             b_have_art = VLC_TRUE;
114         }
115     }
116
117     free( psz_dir );
118
119     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
120 }