]> git.sesse.net Git - vlc/blob - include/vlc_meta.h
include/vlc_meta.h: Use the vlc_dictionary to store extra meta tags.
[vlc] / include / vlc_meta.h
1 /*****************************************************************************
2  * vlc_meta.h: Stream meta-data
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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 #if !defined( __LIBVLC__ )
25   #error You are not libvlc or one of its plugins. You cannot include this file
26 #endif
27
28 #ifndef _VLC_META_H
29 #define _VLC_META_H 1
30
31 #include <vlc_arrays.h>
32
33 /* VLC meta name */
34 #define VLC_META_INFO_CAT           N_("Meta-information")
35 #define VLC_META_TITLE              N_("Title")
36 #define VLC_META_ARTIST             N_("Artist")
37 #define VLC_META_GENRE              N_("Genre")
38 #define VLC_META_COPYRIGHT          N_("Copyright")
39 #define VLC_META_COLLECTION         N_("Album/movie/show title")
40 #define VLC_META_SEQ_NUM            N_("Track number/position in set")
41 #define VLC_META_DESCRIPTION        N_("Description")
42 #define VLC_META_RATING             N_("Rating")
43 #define VLC_META_DATE               N_("Date")
44 #define VLC_META_SETTING            N_("Setting")
45 #define VLC_META_URL                N_("URL")
46 #define VLC_META_LANGUAGE           N_("Language")
47 #define VLC_META_NOW_PLAYING        N_("Now Playing")
48 #define VLC_META_PUBLISHER          N_("Publisher")
49 #define VLC_META_ENCODED_BY         N_("Encoded by")
50
51 #define VLC_META_ART_URL            N_("Art URL")
52
53 #define VLC_META_CODEC_NAME         N_("Codec Name")
54 #define VLC_META_CODEC_DESCRIPTION  N_("Codec Description")
55
56 #define ITEM_PREPARSED      0x01
57 #define ITEM_META_FETCHED   0x02
58 #define ITEM_ARTURL_FETCHED 0x04
59 #define ITEM_ART_FETCHED    0x08
60 #define ITEM_ART_NOTFOUND   0x10
61
62 struct vlc_meta_t
63 {
64     char *psz_title;
65     char *psz_artist;
66     char *psz_genre;
67     char *psz_copyright;
68     char *psz_album;
69     char *psz_tracknum;
70     char *psz_description;
71     char *psz_rating;
72     char *psz_date;
73     char *psz_setting;
74     char *psz_url;
75     char *psz_language;
76     char *psz_nowplaying;
77     char *psz_publisher;
78     char *psz_encodedby;
79     char *psz_arturl;
80     char *psz_trackid;
81
82     vlc_dictionary_t extra_tags;
83
84     int i_status;
85
86 };
87
88 #define vlc_meta_Set( meta,var,val ) do { \
89     const char *str = val; \
90     if( meta->psz_##var ) free( meta->psz_##var ); \
91     meta->psz_##var = str ? strdup( str ) : NULL; } while(0)
92
93 #define vlc_meta_SetTitle( meta, b ) vlc_meta_Set( meta, title, b )
94 #define vlc_meta_SetArtist( meta, b ) vlc_meta_Set( meta, artist, b )
95 #define vlc_meta_SetGenre( meta, b ) vlc_meta_Set( meta, genre, b )
96 #define vlc_meta_SetCopyright( meta, b ) vlc_meta_Set( meta, copyright, b )
97 #define vlc_meta_SetAlbum( meta, b ) vlc_meta_Set( meta, album, b )
98 #define vlc_meta_SetTracknum( meta, b ) vlc_meta_Set( meta, tracknum, b )
99 #define vlc_meta_SetDescription( meta, b ) vlc_meta_Set( meta, description, b )
100 #define vlc_meta_SetRating( meta, b ) vlc_meta_Set( meta, rating, b )
101 #define vlc_meta_SetDate( meta, b ) vlc_meta_Set( meta, date, b )
102 #define vlc_meta_SetSetting( meta, b ) vlc_meta_Set( meta, setting, b )
103 #define vlc_meta_SetURL( meta, b ) vlc_meta_Set( meta, url, b )
104 #define vlc_meta_SetLanguage( meta, b ) vlc_meta_Set( meta, language, b )
105 #define vlc_meta_SetNowPlaying( meta, b ) vlc_meta_Set( meta, nowplaying, b )
106 #define vlc_meta_SetPublisher( meta, b ) vlc_meta_Set( meta, publisher, b )
107 #define vlc_meta_SetEncodedBy( meta, b ) vlc_meta_Set( meta, encodedby, b )
108 #define vlc_meta_SetArtURL( meta, b ) vlc_meta_Set( meta, arturl, b )
109 #define vlc_meta_SetTrackID( meta, b ) vlc_meta_Set( meta, trackid, b )
110
111 static inline vlc_meta_t *vlc_meta_New( void )
112 {
113     vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof( vlc_meta_t ) );
114     if( !m ) return NULL;
115     m->psz_title = NULL;
116     m->psz_artist = NULL;
117     m->psz_genre = NULL;
118     m->psz_copyright = NULL;
119     m->psz_album = NULL;
120     m->psz_tracknum = NULL;
121     m->psz_description = NULL;
122     m->psz_rating = NULL;
123     m->psz_date = NULL;
124     m->psz_setting = NULL;
125     m->psz_url = NULL;
126     m->psz_language = NULL;
127     m->psz_nowplaying = NULL;
128     m->psz_publisher = NULL;
129     m->psz_encodedby = NULL;
130     m->psz_arturl = NULL;
131     m->psz_trackid = NULL;
132
133     m->i_status = 0;
134     vlc_dictionary_init( &m->extra_tags, 32 /* "ought to be enough for anybody" */ );
135     return m;
136 }
137
138 static inline void vlc_meta_Delete( vlc_meta_t *m )
139 {
140     free( m->psz_title );
141     free( m->psz_artist );
142     free( m->psz_genre );
143     free( m->psz_copyright );
144     free( m->psz_album );
145     free( m->psz_tracknum );
146     free( m->psz_description );
147     free( m->psz_rating );
148     free( m->psz_date );
149     free( m->psz_setting );
150     free( m->psz_url );
151     free( m->psz_language );
152     free( m->psz_nowplaying );
153     free( m->psz_publisher );
154     free( m->psz_encodedby );
155     free( m->psz_trackid );
156     free( m->psz_arturl );
157     vlc_dictionary_clear( &m->extra_tags );
158     free( m );
159 }
160 static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value )
161 {
162     char * psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name );
163     if( psz_oldvalue != kVLCDictionaryNotFound )
164     {
165         free( psz_oldvalue );
166         vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name );
167     }
168     vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) );
169 }
170
171 static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
172 {
173     if( !dst || !src ) return;
174 #define COPY_FIELD( a ) \
175     if( src->psz_ ## a ) { \
176         if( dst->psz_ ## a ) free( dst->psz_## a ); \
177         dst->psz_##a = strdup( src->psz_##a ); \
178     }
179     COPY_FIELD( title );
180     COPY_FIELD( artist );
181     COPY_FIELD( genre );
182     COPY_FIELD( copyright );
183     COPY_FIELD( album );
184     COPY_FIELD( tracknum );
185     COPY_FIELD( description );
186     COPY_FIELD( rating );
187     COPY_FIELD( date );
188     COPY_FIELD( setting );
189     COPY_FIELD( url );
190     COPY_FIELD( language );
191     COPY_FIELD( nowplaying );
192     COPY_FIELD( publisher );
193     COPY_FIELD( encodedby );
194     COPY_FIELD( trackid );
195     COPY_FIELD( arturl );
196 #undef COPY_FIELD
197     char ** ppsz_all_keys;
198     int i;
199     /* XXX: If speed up are needed, it is possible */
200     ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags );
201     for( i = 0; ppsz_all_keys[i]; i++ )
202     {
203         /* Always try to remove the previous value */
204         vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i] );
205         void * p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] );
206         vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], p_value );
207         free( ppsz_all_keys[i] );
208     }
209     free( ppsz_all_keys );
210 }
211
212 enum {
213     ALBUM_ART_WHEN_ASKED,
214     ALBUM_ART_WHEN_PLAYED,
215     ALBUM_ART_ALL
216 };
217
218 struct meta_export_t
219 {
220     input_item_t *p_item;
221     const char *psz_file;
222 };
223
224 #define VLC_META_ENGINE_TITLE           0x00000001
225 #define VLC_META_ENGINE_ARTIST          0x00000004
226 #define VLC_META_ENGINE_GENRE           0x00000008
227 #define VLC_META_ENGINE_COPYRIGHT       0x00000010
228 #define VLC_META_ENGINE_COLLECTION      0x00000020
229 #define VLC_META_ENGINE_SEQ_NUM         0x00000040
230 #define VLC_META_ENGINE_DESCRIPTION     0x00000080
231 #define VLC_META_ENGINE_RATING          0x00000100
232 #define VLC_META_ENGINE_DATE            0x00000200
233 #define VLC_META_ENGINE_URL             0x00000400
234 #define VLC_META_ENGINE_LANGUAGE        0x00000800
235
236 #define VLC_META_ENGINE_ART_URL         0x00001000
237
238 #define VLC_META_ENGINE_MB_ARTIST_ID    0x00002000
239 #define VLC_META_ENGINE_MB_RELEASE_ID   0x00004000
240 #define VLC_META_ENGINE_MB_TRACK_ID     0x00008000
241 #define VLC_META_ENGINE_MB_TRM_ID       0x00010000
242
243 typedef struct meta_engine_sys_t meta_engine_sys_t;
244
245 struct meta_engine_t
246 {
247     VLC_COMMON_MEMBERS
248
249     module_t *p_module;
250
251     uint32_t i_mandatory; /**< Stuff which we really need to get */
252     uint32_t i_optional; /**< Stuff which we'd like to have */
253
254     input_item_t *p_item;
255 };
256
257 VLC_EXPORT(uint32_t, input_CurrentMetaFlags,( vlc_meta_t *p_meta ) );
258
259 #endif