]> git.sesse.net Git - vlc/blob - modules/meta_engine/dummy.c
Add dummy meta engine with highest priority. Will check if meta is already available.
[vlc] / modules / meta_engine / dummy.c
1 /*****************************************************************************
2  * dummy.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_engine.h>
34 #include <charset.h>
35
36 /*****************************************************************************
37  * Local prototypes
38  *****************************************************************************/
39 static int FindMeta( vlc_object_t * );
40
41 /*****************************************************************************
42  * Module descriptor
43  *****************************************************************************/
44
45 vlc_module_begin();
46 /*    set_category( CAT_INTERFACE );
47     set_subcategory( SUBCAT_INTERFACE_CONTROL );*/
48     set_shortname( N_( "Dummy" ) );
49     set_description( _("Dummy meta data") );
50
51     set_capability( "meta engine", 1000 );
52     set_callbacks( FindMeta, NULL );
53 vlc_module_end();
54
55 /*****************************************************************************
56  *****************************************************************************/
57 static int FindMeta( vlc_object_t *p_this )
58 {
59     meta_engine_t *p_me = (meta_engine_t *)p_this;
60     input_item_t *p_item = p_me->p_item;
61
62     if( !p_item->p_meta ) return VLC_EGENERIC;
63
64     uint32_t i_meta = 0;
65 #define CHECK( a, b ) \
66     if( p_item->p_meta->psz_ ## a && *p_item->p_meta->psz_ ## a ) \
67         i_meta |= VLC_META_ENGINE_ ## b;
68
69     CHECK( title, TITLE )
70     CHECK( author, AUTHOR )
71     CHECK( artist, ARTIST )
72     CHECK( genre, GENRE )
73     CHECK( copyright, COPYRIGHT )
74     CHECK( album, COLLECTION )
75     CHECK( tracknum, SEQ_NUM )
76     CHECK( description, DESCRIPTION )
77     CHECK( rating, RATING )
78     CHECK( date, DATE )
79     CHECK( url, URL )
80     CHECK( language, LANGUAGE )
81     CHECK( arturl, ART_URL )
82
83     if( !(i_meta & VLC_META_ENGINE_ART_URL) )
84     {
85         if( i_meta & VLC_META_ENGINE_COLLECTION
86             && i_meta & VLC_META_ENGINE_ARTIST )
87         {
88             FILE *p_file;
89             char *psz_filename;
90             asprintf( &psz_filename,
91                       "file://%s/" CONFIG_DIR "/art/%s/%s/art.jpg", /* ahem ... we can have other filetype too... */
92                       p_me->p_libvlc->psz_homedir,
93                       p_item->p_meta->psz_artist,
94                       p_item->p_meta->psz_album );
95             p_file = utf8_fopen( psz_filename+7, "r" );
96             if( p_file )
97             {
98                 fclose( p_file );
99                 vlc_meta_SetArtURL( p_item->p_meta, psz_filename );
100                 i_meta |= VLC_META_ENGINE_ART_URL;
101             }
102             free( psz_filename );
103         }
104     }
105
106     /* Add checks for musicbrainz meta */
107
108     if( ( p_me->i_mandatory & i_meta ) == p_me->i_mandatory )
109     {
110         return VLC_SUCCESS;
111     }
112     else
113     {
114         return VLC_EGENERIC;
115      }
116 }