]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
Use playlist_fetcher_t object instead of playlist one.
[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_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_playlist.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( N_("Folder meta data") )
57
58     set_capability( "art finder", 90 )
59     set_callbacks( FindMeta, NULL )
60 vlc_module_end ()
61
62 /*****************************************************************************
63  *****************************************************************************/
64 static int FindMeta( vlc_object_t *p_this )
65 {
66     input_item_t *p_item = (input_item_t *)p_this->p_private;
67     bool b_have_art = false;
68
69     int i = 0;
70     struct stat a;
71     char psz_filename[MAX_PATH];
72     if( !p_item )
73         return VLC_EGENERIC;
74
75     char *psz_dir = input_item_GetURI( p_item );
76     if( !psz_dir )
77         return VLC_EGENERIC;
78
79     char *psz_buf = strrchr( psz_dir, '/' );
80     if( psz_buf )
81     {
82         psz_buf++;
83         *psz_buf = '\0';
84     }
85     else
86     {
87         *psz_dir = '\0';
88     }
89
90     char *psz_path = psz_dir;
91     if( !strncmp( psz_path, "file://", 7 ) )
92         psz_path += 7;
93
94     for( i = 0; b_have_art == 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_path );
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_path );
108             break;
109
110             case 2:
111             /* KDE (?) .folder.png */
112             snprintf( psz_filename, MAX_PATH,
113                   "file://%s.folder.png", psz_path );
114             break;
115         }
116
117         if( utf8_stat( psz_filename+7, &a ) != -1 )
118         {
119             input_item_SetArtURL( p_item, psz_filename );
120             b_have_art = true;
121         }
122     }
123
124     free( psz_dir );
125
126     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
127 }