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