]> git.sesse.net Git - vlc/blob - include/vlc_meta.h
* src/libvlc.h, src/input/input.c:
[vlc] / include / vlc_meta.h
1 /*****************************************************************************
2  * vlc_meta.h
3  *****************************************************************************
4  * Copyright (C) 2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef _VLC_META_H
25 #define _VLC_META_H 1
26
27 /* VLC meta name */
28 #define VLC_META_TITLE              N_("Title")
29 #define VLC_META_AUTHOR             N_("Author")
30 #define VLC_META_ARTIST             N_("Artist")
31 #define VLC_META_GENRE              N_("Genre")
32 #define VLC_META_COPYRIGHT          N_("Copyright")
33 #define VLC_META_DESCRIPTION        N_("Description")
34 #define VLC_META_RATING             N_("Rating")
35 #define VLC_META_DATE               N_("Date")
36 #define VLC_META_SETTING            N_("Setting")
37 #define VLC_META_URL                N_("Url")
38 #define VLC_META_LANGUAGE           N_("Language")
39 #define VLC_META_CODEC_NAME         N_("Codec Name")
40 #define VLC_META_CODEC_DESCRIPTION  N_("Codec Description")
41
42 struct vlc_meta_t
43 {
44     /* meta name/value pairs */
45     int     i_meta;
46     char    **name;
47     char    **value;
48
49     /* track meta informations */
50     int         i_track;
51     vlc_meta_t  **track;
52 };
53
54 static inline vlc_meta_t *vlc_meta_New( void )
55 {
56     vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof( vlc_meta_t ) );
57
58     m->i_meta = 0;
59     m->name   = NULL;
60     m->value  = NULL;
61
62     m->i_track= 0;
63     m->track  = NULL;
64
65     return m;
66 }
67
68 static inline void vlc_meta_Delete( vlc_meta_t *m )
69 {
70     int i;
71     for( i = 0; i < m->i_meta; i++ )
72     {
73         free( m->name[i] );
74         free( m->value[i] );
75     }
76     if( m->name ) free( m->name );
77     if( m->value ) free( m->value );
78
79     for( i = 0; i < m->i_track; i++ )
80     {
81         vlc_meta_Delete( m->track[i] );
82     }
83     if( m->track ) free( m->track );
84     free( m );
85 }
86
87 static inline void vlc_meta_Add( vlc_meta_t *m, char *name, char *value )
88 {
89     int i_meta = m->i_meta;
90
91     name = strdup( name );
92     value = strdup( value );
93
94     TAB_APPEND( m->i_meta, m->name, name );
95     TAB_APPEND( i_meta,    m->value,value );
96 }
97
98 static inline vlc_meta_t *vlc_meta_Duplicate( vlc_meta_t *src )
99 {
100     vlc_meta_t *dst = vlc_meta_New();
101     int i;
102     for( i = 0; i < src->i_meta; i++ )
103     {
104         vlc_meta_Add( dst, src->name[i], src->value[i] );
105     }
106     for( i = 0; i < src->i_track; i++ )
107     {
108         vlc_meta_t *tk = vlc_meta_Duplicate( src->track[i] );
109         TAB_APPEND( dst->i_track, dst->track, tk );
110     }
111     return dst;
112 }
113
114 static inline void vlc_meta_Merge( vlc_meta_t *dst, vlc_meta_t *src )
115 {
116     int i, j;
117     for( i = 0; i < src->i_meta; i++ )
118     {
119         /* Check if dst contains the entry */
120         for( j = 0; j < dst->i_meta; j++ )
121         {
122             if( !strcmp( src->name[i], dst->name[j] ) ) break;
123         }
124         if( j < dst->i_meta )
125         {
126             if( dst->value[j] ) free( dst->value[j] );
127             dst->value[j] = strdup( src->value[i] );
128         }
129         else vlc_meta_Add( dst, src->name[i], src->value[i] );
130     }
131 }
132
133 #endif