]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
Cosmetic
[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/intf.h>
32 #include <vlc_meta.h>
33 #include <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_category( CAT_INTERFACE );
54     set_subcategory( SUBCAT_INTERFACE_CONTROL );*/
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     meta_engine_t *p_me = (meta_engine_t *)p_this;
67     input_item_t *p_item = p_me->p_item;
68     vlc_bool_t b_have_art = VLC_FALSE;
69     uint32_t i_meta;
70
71     if( !p_item->p_meta ) return VLC_EGENERIC;
72
73
74     if( p_me->i_mandatory & VLC_META_ENGINE_ART_URL
75         || p_me->i_optional & VLC_META_ENGINE_ART_URL )
76     {
77         int i = 0;
78         struct stat a;
79         char psz_filename[MAX_PATH];
80         char *psz_dir = strdup( p_item->psz_uri );
81         char *psz_buf = strrchr( psz_dir, '/' );
82
83         if( psz_buf )
84         {
85             psz_buf++;
86             *psz_buf = '\0';
87         }
88         else
89         {
90             *psz_dir = '\0';
91         }
92
93         for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
94         {
95             switch( i )
96             {
97                 case 0:
98                 /* Windows Folder.jpg */
99                 snprintf( psz_filename, MAX_PATH,
100                           "file://%sFolder.jpg", psz_dir );
101                 break;
102
103                 case 1:
104                 /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
105                 snprintf( psz_filename, MAX_PATH,
106                       "file://%sAlbumArtSmall.jpg", psz_dir );
107                 break;
108
109                 case 2:
110                 /* KDE (?) .folder.png */
111                 snprintf( psz_filename, MAX_PATH,
112                       "file://%s.folder.png", psz_dir );
113                 break;
114             }
115
116             if( utf8_stat( psz_filename+7, &a ) != -1 )
117             {
118                 vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
119                 b_have_art = VLC_TRUE;
120             }
121         }
122
123         free( psz_dir );
124     }
125
126     i_meta = input_GetMetaEngineFlags( p_item->p_meta );
127     p_me->i_mandatory &= ~i_meta;
128     p_me->i_optional &= ~i_meta;
129     if( p_me->i_mandatory )
130         return VLC_EGENERIC;
131     else
132         return VLC_SUCCESS;
133 }