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