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 *****************************************************************************/
27 #include <vlc_arrays.h>
29 typedef enum vlc_meta_type_t
50 #define VLC_META_TYPE_COUNT 17
52 /* Returns a localizes string describing the meta */
53 VLC_EXPORT(const char *, input_MetaTypeToLocalizedString, ( vlc_meta_type_t meta_type ) );
55 #define ITEM_PREPARSED 0x01
56 #define ITEM_ARTURL_FETCHED 0x02
57 #define ITEM_ART_FETCHED 0x04
58 #define ITEM_ART_NOTFOUND 0x08
62 char * ppsz_meta[VLC_META_TYPE_COUNT];
64 vlc_dictionary_t extra_tags;
70 * Warning: Make sure to use the input_item meta setters (defined in vlc_input.h)
71 * instead of those one. */
72 #define vlc_meta_SetTitle( meta, b ) vlc_meta_Set( meta, vlc_meta_Title, b )
73 #define vlc_meta_SetArtist( meta, b ) vlc_meta_Set( meta, vlc_meta_Artist, b )
74 #define vlc_meta_SetGenre( meta, b ) vlc_meta_Set( meta, vlc_meta_Genre, b )
75 #define vlc_meta_SetCopyright( meta, b ) vlc_meta_Set( meta, vlc_meta_Copyright, b )
76 #define vlc_meta_SetAlbum( meta, b ) vlc_meta_Set( meta, vlc_meta_Album, b )
77 #define vlc_meta_SetTracknum( meta, b ) vlc_meta_Set( meta, vlc_meta_TrackNumber, b )
78 #define vlc_meta_SetDescription( meta, b ) vlc_meta_Set( meta, vlc_meta_Description, b )
79 #define vlc_meta_SetRating( meta, b ) vlc_meta_Set( meta, vlc_meta_Rating, b )
80 #define vlc_meta_SetDate( meta, b ) vlc_meta_Set( meta, vlc_meta_Date, b )
81 #define vlc_meta_SetSetting( meta, b ) vlc_meta_Set( meta, vlc_meta_Setting, b )
82 #define vlc_meta_SetURL( meta, b ) vlc_meta_Set( meta, vlc_meta_URL, b )
83 #define vlc_meta_SetLanguage( meta, b ) vlc_meta_Set( meta, vlc_meta_Language, b )
84 #define vlc_meta_SetNowPlaying( meta, b ) vlc_meta_Set( meta, vlc_meta_NowPlaying, b )
85 #define vlc_meta_SetPublisher( meta, b ) vlc_meta_Set( meta, vlc_meta_Publisher, b )
86 #define vlc_meta_SetEncodedBy( meta, b ) vlc_meta_Set( meta, vlc_meta_EncodedBy, b )
87 #define vlc_meta_SetArtURL( meta, b ) vlc_meta_Set( meta, vlc_meta_ArtworkURL, b )
88 #define vlc_meta_SetTrackID( meta, b ) vlc_meta_Set( meta, vlc_meta_TrackID, b )
90 static inline void vlc_meta_Set( vlc_meta_t * p_meta, vlc_meta_type_t meta_type, const char * psz_val )
92 free( p_meta->ppsz_meta[meta_type] );
93 p_meta->ppsz_meta[meta_type] = psz_val ? strdup( psz_val ) : NULL;
96 static inline const char * vlc_meta_Get( const vlc_meta_t * p_meta, vlc_meta_type_t meta_type )
98 return p_meta->ppsz_meta[meta_type];
101 static inline vlc_meta_t *vlc_meta_New( void )
103 vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof( vlc_meta_t ) );
104 if( !m ) return NULL;
105 memset( m->ppsz_meta, 0, sizeof(m->ppsz_meta) );
107 vlc_dictionary_init( &m->extra_tags, 0 );
111 static inline void vlc_meta_Delete( vlc_meta_t *m )
114 for( i = 0; i < VLC_META_TYPE_COUNT ; i++ )
115 free( m->ppsz_meta[i] );
116 vlc_dictionary_clear( &m->extra_tags );
120 static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value )
122 char * psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name );
123 if( psz_oldvalue != kVLCDictionaryNotFound )
125 free( psz_oldvalue );
126 vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name );
128 vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) );
131 static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
133 char ** ppsz_all_keys;
136 if( !dst || !src ) return;
138 for( i = 0; i < VLC_META_TYPE_COUNT; i++ )
140 if( src->ppsz_meta[i] )
142 free( dst->ppsz_meta[i] );
143 dst->ppsz_meta[i] = strdup( src->ppsz_meta[i] );
147 /* XXX: If speed up are needed, it is possible */
148 ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags );
149 for( i = 0; ppsz_all_keys[i]; i++ )
151 /* Always try to remove the previous value */
152 vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i] );
153 void * p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] );
154 vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], p_value );
155 free( ppsz_all_keys[i] );
157 free( ppsz_all_keys );
160 #define VLC_META_TITLE input_MetaTypeToLocalizedString( vlc_meta_Title )
161 #define VLC_META_ARTIST input_MetaTypeToLocalizedString( vlc_meta_Artist )
162 #define VLC_META_GENRE input_MetaTypeToLocalizedString( vlc_meta_Genre )
163 #define VLC_META_COPYRIGHT input_MetaTypeToLocalizedString( vlc_meta_Copyright )
164 #define VLC_META_ALBUM input_MetaTypeToLocalizedString( vlc_meta_Album )
165 #define VLC_META_TRACK_NUMBER input_MetaTypeToLocalizedString( vlc_meta_TrackNumber )
166 #define VLC_META_DESCRIPTION input_MetaTypeToLocalizedString( vlc_meta_Description )
167 #define VLC_META_RATING input_MetaTypeToLocalizedString( vlc_meta_Rating )
168 #define VLC_META_DATE input_MetaTypeToLocalizedString( vlc_meta_Date )
169 #define VLC_META_SETTING input_MetaTypeToLocalizedString( vlc_meta_Setting )
170 #define VLC_META_URL input_MetaTypeToLocalizedString( vlc_meta_URL )
171 #define VLC_META_LANGUAGE input_MetaTypeToLocalizedString( vlc_meta_Language )
172 #define VLC_META_NOW_PLAYING input_MetaTypeToLocalizedString( vlc_meta_NowPlaying )
173 #define VLC_META_PUBLISHER input_MetaTypeToLocalizedString( vlc_meta_Publisher )
174 #define VLC_META_ENCODED_BY input_MetaTypeToLocalizedString( vlc_meta_EncodedBy )
175 #define VLC_META_ART_URL input_MetaTypeToLocalizedString( vlc_meta_ArtworkURL )
176 #define VLC_META_TRACKID input_MetaTypeToLocalizedString( vlc_meta_TrackID )
179 ALBUM_ART_WHEN_ASKED,
180 ALBUM_ART_WHEN_PLAYED,
186 input_item_t *p_item;
187 const char *psz_file;