]> git.sesse.net Git - vlc/blob - modules/meta_engine/folder.c
Track, Artist, Album MusicBrainz IDs reading with libid3tag
[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_shortname( N_( "Folder" ) );
54     set_description( _("Folder meta data") );
55
56     set_capability( "art finder", 10 );
57     set_callbacks( FindMeta, NULL );
58 vlc_module_end();
59
60 /*****************************************************************************
61  *****************************************************************************/
62 static int FindMeta( vlc_object_t *p_this )
63 {
64     playlist_t *p_playlist = (playlist_t *)p_this;
65     input_item_t *p_item = (input_item_t *)(p_playlist->p_private);
66     vlc_bool_t b_have_art = VLC_FALSE;
67     uint32_t i_meta;
68
69     int i = 0;
70     struct stat a;
71     char psz_filename[MAX_PATH];
72     char *psz_dir = strdup( p_item->psz_uri );
73     char *psz_buf = strrchr( psz_dir, '/' );
74
75     if( !p_item->p_meta ) return VLC_EGENERIC;
76     if( psz_buf )
77     {
78         psz_buf++;
79         *psz_buf = '\0';
80     }
81     else
82     {
83         *psz_dir = '\0';
84     }
85
86     for( i = 0; b_have_art == VLC_FALSE && i < 3; i++ )
87     {
88         switch( i )
89         {
90             case 0:
91             /* Windows Folder.jpg */
92             snprintf( psz_filename, MAX_PATH,
93                       "file://%sFolder.jpg", psz_dir );
94             break;
95
96             case 1:
97             /* Windows AlbumArtSmall.jpg == small version of Folder.jpg */
98             snprintf( psz_filename, MAX_PATH,
99                   "file://%sAlbumArtSmall.jpg", psz_dir );
100             break;
101
102             case 2:
103             /* KDE (?) .folder.png */
104             snprintf( psz_filename, MAX_PATH,
105                   "file://%s.folder.png", psz_dir );
106             break;
107         }
108
109         if( utf8_stat( psz_filename+7, &a ) != -1 )
110         {
111             vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
112             b_have_art = VLC_TRUE;
113         }
114     }
115
116     free( psz_dir );
117
118     return b_have_art ? VLC_SUCCESS : VLC_EGENERIC;
119 }