1 /*****************************************************************************
2 * vlc_meta.h: Stream meta-data
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 #if !defined( __LIBVLC__ )
25 #error You are not libvlc or one of its plugins. You cannot include this file
31 #include <vlc_arrays.h>
33 #define VLC_META_TYPE_COUNT 17
35 typedef enum vlc_meta_type_t
56 /* Returns a localizes string describing the meta */
57 VLC_EXPORT(const char *, input_MetaTypeToLocalizedString, ( vlc_meta_type_t meta_type ) );
59 #define ITEM_PREPARSED 0x01
60 #define ITEM_META_FETCHED 0x02
61 #define ITEM_ARTURL_FETCHED 0x04
62 #define ITEM_ART_FETCHED 0x08
63 #define ITEM_ART_NOTFOUND 0x10
67 char * ppsz_meta[VLC_META_TYPE_COUNT];
69 vlc_dictionary_t extra_tags;
76 * Warning: Make sure to use the input_item meta setters (defined in vlc_input.h)
77 * instead of those one. */
78 #define vlc_meta_SetTitle( meta, b ) vlc_meta_Set( meta, vlc_meta_Title, b )
79 #define vlc_meta_SetArtist( meta, b ) vlc_meta_Set( meta, vlc_meta_Artist, b )
80 #define vlc_meta_SetGenre( meta, b ) vlc_meta_Set( meta, vlc_meta_Genre, b )
81 #define vlc_meta_SetCopyright( meta, b ) vlc_meta_Set( meta, vlc_meta_Copyright, b )
82 #define vlc_meta_SetAlbum( meta, b ) vlc_meta_Set( meta, vlc_meta_Album, b )
83 #define vlc_meta_SetTracknum( meta, b ) vlc_meta_Set( meta, vlc_meta_TrackNumber, b )
84 #define vlc_meta_SetDescription( meta, b ) vlc_meta_Set( meta, vlc_meta_Description, b )
85 #define vlc_meta_SetRating( meta, b ) vlc_meta_Set( meta, vlc_meta_Rating, b )
86 #define vlc_meta_SetDate( meta, b ) vlc_meta_Set( meta, vlc_meta_Date, b )
87 #define vlc_meta_SetSetting( meta, b ) vlc_meta_Set( meta, vlc_meta_Setting, b )
88 #define vlc_meta_SetURL( meta, b ) vlc_meta_Set( meta, vlc_meta_URL, b )
89 #define vlc_meta_SetLanguage( meta, b ) vlc_meta_Set( meta, vlc_meta_Language, b )
90 #define vlc_meta_SetNowPlaying( meta, b ) vlc_meta_Set( meta, vlc_meta_NowPlaying, b )
91 #define vlc_meta_SetPublisher( meta, b ) vlc_meta_Set( meta, vlc_meta_Publisher, b )
92 #define vlc_meta_SetEncodedBy( meta, b ) vlc_meta_Set( meta, vlc_meta_EncodedBy, b )
93 #define vlc_meta_SetArtURL( meta, b ) vlc_meta_Set( meta, vlc_meta_ArtworkURL, b )
94 #define vlc_meta_SetTrackID( meta, b ) vlc_meta_Set( meta, vlc_meta_TrackID, b )
96 static inline void vlc_meta_Set( vlc_meta_t * p_meta, vlc_meta_type_t meta_type, const char * psz_val )
98 if( p_meta->ppsz_meta[meta_type] ) free( p_meta->ppsz_meta[meta_type] );
99 p_meta->ppsz_meta[meta_type] = psz_val ? strdup( psz_val ) : NULL;
102 static inline const char * vlc_meta_Get( const vlc_meta_t * p_meta, vlc_meta_type_t meta_type )
104 return p_meta->ppsz_meta[meta_type];
107 static inline vlc_meta_t *vlc_meta_New( void )
109 vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof( vlc_meta_t ) );
110 if( !m ) return NULL;
111 memset( m->ppsz_meta, 0, sizeof(m->ppsz_meta) );
113 vlc_dictionary_init( &m->extra_tags, 0 );
117 static inline void vlc_meta_Delete( vlc_meta_t *m )
120 for( i = 0; i < 0; i++ )
121 free( m->ppsz_meta[i] );
122 vlc_dictionary_clear( &m->extra_tags );
126 static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value )
128 char * psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name );
129 if( psz_oldvalue != kVLCDictionaryNotFound )
131 free( psz_oldvalue );
132 vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name );
134 vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) );
137 static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
139 char ** ppsz_all_keys;
142 if( !dst || !src ) return;
144 for( i = 0; i < VLC_META_TYPE_COUNT; i++ )
146 if( src->ppsz_meta[i] )
148 if( dst->ppsz_meta[i] ) free( dst->ppsz_meta[i] );
149 dst->ppsz_meta[i] = strdup( src->ppsz_meta[i] );
153 /* XXX: If speed up are needed, it is possible */
154 ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags );
155 for( i = 0; ppsz_all_keys[i]; i++ )
157 /* Always try to remove the previous value */
158 vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i] );
159 void * p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] );
160 vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], p_value );
161 free( ppsz_all_keys[i] );
163 free( ppsz_all_keys );
166 /* Shortcuts for the AddInfo */
167 #define VLC_META_INFO_CAT N_("Meta-information")
168 #define VLC_META_TITLE input_MetaTypeToLocalizedString( vlc_meta_Title )
169 #define VLC_META_ARTIST input_MetaTypeToLocalizedString( vlc_meta_Artist )
170 #define VLC_META_GENRE input_MetaTypeToLocalizedString( vlc_meta_Genre )
171 #define VLC_META_COPYRIGHT input_MetaTypeToLocalizedString( vlc_meta_Copyright )
172 #define VLC_META_COLLECTION input_MetaTypeToLocalizedString( vlc_meta_Album )
173 #define VLC_META_SEQ_NUM input_MetaTypeToLocalizedString( vlc_meta_TrackNumber )
174 #define VLC_META_DESCRIPTION input_MetaTypeToLocalizedString( vlc_meta_Description )
175 #define VLC_META_RATING input_MetaTypeToLocalizedString( vlc_meta_Rating )
176 #define VLC_META_DATE input_MetaTypeToLocalizedString( vlc_meta_Date )
177 #define VLC_META_SETTING input_MetaTypeToLocalizedString( vlc_meta_Setting )
178 #define VLC_META_URL input_MetaTypeToLocalizedString( vlc_meta_URL )
179 #define VLC_META_LANGUAGE input_MetaTypeToLocalizedString( vlc_meta_Language )
180 #define VLC_META_NOW_PLAYING input_MetaTypeToLocalizedString( vlc_meta_NowPlaying )
181 #define VLC_META_PUBLISHER input_MetaTypeToLocalizedString( vlc_meta_Publisher )
182 #define VLC_META_ENCODED_BY input_MetaTypeToLocalizedString( vlc_meta_EncodedBy )
183 #define VLC_META_ART_URL input_MetaTypeToLocalizedString( vlc_meta_ArtworkURL )
184 #define VLC_META_CODEC_NAME N_("Codec Name")
185 #define VLC_META_CODEC_DESCRIPTION N_("Codec Description")
188 ALBUM_ART_WHEN_ASKED,
189 ALBUM_ART_WHEN_PLAYED,
195 input_item_t *p_item;
196 const char *psz_file;
199 #define VLC_META_ENGINE_TITLE 0x00000001
200 #define VLC_META_ENGINE_ARTIST 0x00000004
201 #define VLC_META_ENGINE_GENRE 0x00000008
202 #define VLC_META_ENGINE_COPYRIGHT 0x00000010
203 #define VLC_META_ENGINE_COLLECTION 0x00000020
204 #define VLC_META_ENGINE_SEQ_NUM 0x00000040
205 #define VLC_META_ENGINE_DESCRIPTION 0x00000080
206 #define VLC_META_ENGINE_RATING 0x00000100
207 #define VLC_META_ENGINE_DATE 0x00000200
208 #define VLC_META_ENGINE_URL 0x00000400
209 #define VLC_META_ENGINE_LANGUAGE 0x00000800
211 #define VLC_META_ENGINE_ART_URL 0x00001000
213 #if 0 /* unused (yet?) */
214 #define VLC_META_ENGINE_MB_ARTIST_ID 0x00002000
215 #define VLC_META_ENGINE_MB_RELEASE_ID 0x00004000
216 #define VLC_META_ENGINE_MB_TRACK_ID 0x00008000
217 #define VLC_META_ENGINE_MB_TRM_ID 0x00010000
220 typedef struct meta_engine_sys_t meta_engine_sys_t;
228 uint32_t i_mandatory; /**< Stuff which we really need to get */
229 uint32_t i_optional; /**< Stuff which we'd like to have */
231 input_item_t *p_item;
234 VLC_EXPORT(uint32_t, input_CurrentMetaFlags,( vlc_meta_t *p_meta ) );