]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
Some more meta changes (mostly cleanup and check the i_mandatory flags)
[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 <vlc_meta.h>
34 #include <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_category( CAT_INTERFACE );
55     set_subcategory( SUBCAT_INTERFACE_CONTROL );*/
56     set_shortname( N_( "Folder" ) );
57     set_description( _("Folder meta data") );
58
59     set_capability( "art finder", 10 );
60     set_callbacks( FindMeta, NULL );
61 vlc_module_end();
62
63 /*****************************************************************************
64  *****************************************************************************/
65 static int FindMeta( vlc_object_t *p_this )
66 {
67     meta_engine_t *p_me = (meta_engine_t *)p_this;
68     input_item_t *p_item = p_me->p_item;
69     vlc_bool_t b_have_art = VLC_FALSE;
70     uint32_t i_meta;
71
72     if( !p_item->p_meta ) return VLC_EGENERIC;
73
74
75     if( p_me->i_mandatory & VLC_META_ENGINE_ART_URL
76         || p_me->i_optional & VLC_META_ENGINE_ART_URL )
77     {
78         int i = 0;
79         struct stat a;
80         char psz_filename[MAX_PATH];
81         char *psz_dir = strdup( p_item->psz_uri );
82         char *psz_buf = strrchr( psz_dir, '/' );
83
84         if( psz_buf )
85         {
86             psz_buf++;
87             *psz_buf = '\0';
88         }
89         else
90         {
91             *psz_dir = '\0';
92         }
93
94         for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
95         {
96             switch( i )
97             {
98                 case 0:
99                 /* Windows Folder.jpg */
100                 snprintf( psz_filename, MAX_PATH,
101                           "file://%sFolder.jpg", psz_dir );
102                 break;
103
104                 case 1:
105                 /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
106                 snprintf( psz_filename, MAX_PATH,
107                       "file://%sAlbumArtSmall.jpg", psz_dir );
108                 break;
109
110                 case 2:
111                 /* KDE (?) .folder.png */
112                 snprintf( psz_filename, MAX_PATH,
113                       "file://%s.folder.png", psz_dir );
114                 break;
115             }
116
117             if( utf8_stat( psz_filename+7, &a ) != -1 )
118             {
119                 vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
120                 b_have_art = VLC_TRUE;
121             }
122         }
123
124         free( psz_dir );
125     }
126
127     i_meta = input_GetMetaEngineFlags( p_item->p_meta );
128     p_me->i_mandatory &= ~i_meta;
129     p_me->i_optional &= ~i_meta;
130     if( p_me->i_mandatory )
131         return VLC_EGENERIC;
132     else
133         return VLC_SUCCESS;
134 }