]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
Input access locking, part 3 (final).
[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
28 #include <vlc/vlc.h>
29 #include <vlc_interface.h>
30 #include <vlc_meta.h>
31 #include <vlc_playlist.h>
32 #include <vlc_input.h>
33 #include <vlc_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", 90 );
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 = input_item_GetURI( p_item );
72     char *psz_buf = strrchr( psz_dir, '/' );
73
74     if( psz_buf )
75     {
76         psz_buf++;
77         *psz_buf = '\0';
78     }
79     else
80     {
81         *psz_dir = '\0';
82     }
83
84     char *psz_path = psz_dir;
85     if( !strncmp( psz_path, "file://", 7 ) )
86         psz_path += 7;
87
88     for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
89     {
90         switch( i )
91         {
92             case 0:
93             /* Windows Folder.jpg */
94             snprintf( psz_filename, MAX_PATH,
95                       "file://%sFolder.jpg", psz_path );
96             break;
97
98             case 1:
99             /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
100             snprintf( psz_filename, MAX_PATH,
101                   "file://%sAlbumArtSmall.jpg", psz_path );
102             break;
103
104             case 2:
105             /* KDE (?) .folder.png */
106             snprintf( psz_filename, MAX_PATH,
107                   "file://%s.folder.png", psz_path );
108             break;
109         }
110
111         if( utf8_stat( psz_filename+7, &a ) != -1 )
112         {
113             input_item_SetArtURL( p_item, psz_filename );
114             b_have_art = VLC_TRUE;
115         }
116     }
117
118     free( psz_dir );
119
120     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
121 }