]> git.sesse.net Git - vlc/blob - include/vlc_meta.h
* Show meta-information separately
[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 #ifndef _VLC_META_H
25 #define _VLC_META_H 1
26
27 /* VLC meta name */
28 #define VLC_META_INFO_CAT           N_("Meta-information")
29 #define VLC_META_TITLE              N_("Title")
30 #define VLC_META_AUTHOR             N_("Author")
31 #define VLC_META_ARTIST             N_("Artist")
32 #define VLC_META_GENRE              N_("Genre")
33 #define VLC_META_COPYRIGHT          N_("Copyright")
34 #define VLC_META_COLLECTION         N_("Album/movie/show title")
35 #define VLC_META_SEQ_NUM            N_("Track number/position in set")
36 #define VLC_META_DESCRIPTION        N_("Description")
37 #define VLC_META_RATING             N_("Rating")
38 #define VLC_META_DATE               N_("Date")
39 #define VLC_META_SETTING            N_("Setting")
40 #define VLC_META_URL                N_("URL")
41 #define VLC_META_LANGUAGE           N_("Language")
42 #define VLC_META_NOW_PLAYING        N_("Now Playing")
43 #define VLC_META_PUBLISHER          N_("Publisher")
44
45 #define VLC_META_CDDB_ARTIST        N_("CDDB Artist")
46 #define VLC_META_CDDB_CATEGORY      N_("CDDB Category")
47 #define VLC_META_CDDB_DISCID        N_("CDDB Disc ID")
48 #define VLC_META_CDDB_EXT_DATA      N_("CDDB Extended Data")
49 #define VLC_META_CDDB_GENRE         N_("CDDB Genre")
50 #define VLC_META_CDDB_YEAR          N_("CDDB Year")
51 #define VLC_META_CDDB_TITLE         N_("CDDB Title")
52
53 #define VLC_META_CDTEXT_ARRANGER    N_("CD-Text Arranger")
54 #define VLC_META_CDTEXT_COMPOSER    N_("CD-Text Composer")
55 #define VLC_META_CDTEXT_DISCID      N_("CD-Text Disc ID")
56 #define VLC_META_CDTEXT_GENRE       N_("CD-Text Genre")
57 #define VLC_META_CDTEXT_MESSAGE     N_("CD-Text Message")
58 #define VLC_META_CDTEXT_SONGWRITER  N_("CD-Text Songwriter")
59 #define VLC_META_CDTEXT_PERFORMER   N_("CD-Text Performer")
60 #define VLC_META_CDTEXT_TITLE       N_("CD-Text Title")
61
62 #define VLC_META_ISO_APPLICATION_ID N_("ISO-9660 Application ID")
63 #define VLC_META_ISO_PREPARER       N_("ISO-9660 Preparer")
64 #define VLC_META_ISO_PUBLISHER      N_("ISO-9660 Publisher")
65 #define VLC_META_ISO_VOLUME         N_("ISO-9660 Volume")
66 #define VLC_META_ISO_VOLUMESET      N_("ISO-9660 Volume Set")
67
68 #define VLC_META_CODEC_NAME         N_("Codec Name")
69 #define VLC_META_CODEC_DESCRIPTION  N_("Codec Description")
70
71 struct vlc_meta_t
72 {
73     /* meta name/value pairs */
74     int     i_meta;
75     char    **name;
76     char    **value;
77
78     /* track meta information */
79     int         i_track;
80     vlc_meta_t  **track;
81 };
82
83 static inline vlc_meta_t *vlc_meta_New( void )
84 {
85     vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof( vlc_meta_t ) );
86
87     m->i_meta = 0;
88     m->name   = NULL;
89     m->value  = NULL;
90
91     m->i_track= 0;
92     m->track  = NULL;
93
94     return m;
95 }
96
97 static inline void vlc_meta_Delete( vlc_meta_t *m )
98 {
99     int i;
100     for( i = 0; i < m->i_meta; i++ )
101     {
102         free( m->name[i] );
103         free( m->value[i] );
104     }
105     if( m->name ) free( m->name );
106     if( m->value ) free( m->value );
107
108     for( i = 0; i < m->i_track; i++ )
109     {
110         vlc_meta_Delete( m->track[i] );
111     }
112     if( m->track ) free( m->track );
113     free( m );
114 }
115
116 static inline void vlc_meta_Add( vlc_meta_t *m,
117                                  const char *name, const char *value )
118 {
119     m->name  = (char**)realloc( m->name, sizeof(char*) * ( m->i_meta + 1 ) );
120     m->name[m->i_meta] = strdup( name );
121
122     m->value = (char**)realloc( m->value, sizeof(char*) * ( m->i_meta + 1 ) );
123     m->value[m->i_meta] = strdup( value );
124
125     m->i_meta++;
126 }
127
128 static inline vlc_meta_t *vlc_meta_Duplicate( vlc_meta_t *src )
129 {
130     vlc_meta_t *dst = vlc_meta_New();
131     int i;
132     for( i = 0; i < src->i_meta; i++ )
133     {
134         vlc_meta_Add( dst, src->name[i], src->value[i] );
135     }
136     for( i = 0; i < src->i_track; i++ )
137     {
138         vlc_meta_t *tk = vlc_meta_Duplicate( src->track[i] );
139
140         dst->track = (vlc_meta_t**)realloc( dst->track, sizeof( vlc_meta_t* ) * (dst->i_track+1) );
141         dst->track[dst->i_track++] = tk;
142     }
143     return dst;
144 }
145
146 static inline void vlc_meta_Merge( vlc_meta_t *dst, vlc_meta_t *src )
147 {
148     int i, j;
149     for( i = 0; i < src->i_meta; i++ )
150     {
151         /* Check if dst contains the entry */
152         for( j = 0; j < dst->i_meta; j++ )
153         {
154             if( !strcmp( src->name[i], dst->name[j] ) ) break;
155         }
156         if( j < dst->i_meta )
157         {
158             if( dst->value[j] ) free( dst->value[j] );
159             dst->value[j] = strdup( src->value[i] );
160         }
161         else vlc_meta_Add( dst, src->name[i], src->value[i] );
162     }
163 }
164
165 static inline char *vlc_meta_GetValue( vlc_meta_t *m, const char *name )
166 {
167     int i;
168
169     for( i = 0; i < m->i_meta; i++ )
170     {
171         if( !strcmp( m->name[i], name ) )
172         {
173             char *value = NULL;
174             if( m->value[i] ) value = strdup( m->value[i] );
175             return value;
176         }
177     }
178     return NULL;
179 }
180
181 #endif