]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
bc40d09e7bff0709917c24d3ab3a1e875d6028bf
[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     char *psz_path = psz_dir;
88     if( !strncmp( psz_path, "file://", 7 ) )
89         psz_path += 7;
90
91     for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
92     {
93         switch( i )
94         {
95             case 0:
96             /* Windows Folder.jpg */
97             snprintf( psz_filename, MAX_PATH,
98                       "file://%sFolder.jpg", psz_path );
99             break;
100
101             case 1:
102             /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
103             snprintf( psz_filename, MAX_PATH,
104                   "file://%sAlbumArtSmall.jpg", psz_path );
105             break;
106
107             case 2:
108             /* KDE (?) .folder.png */
109             snprintf( psz_filename, MAX_PATH,
110                   "file://%s.folder.png", psz_path );
111             break;
112         }
113
114         if( utf8_stat( psz_filename+7, &a ) != -1 )
115         {
116             vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
117             b_have_art = VLC_TRUE;
118         }
119     }
120
121     free( psz_dir );
122
123     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
124 }