vlc_meta.h 7.81 KB
Newer Older
1
/*****************************************************************************
2
 * vlc_meta.h: Stream meta-data
3
 *****************************************************************************
4
 * Copyright (C) 2004 the VideoLAN team
5
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23
 *****************************************************************************/

24 25
#ifndef VLC_META_H
#define VLC_META_H 1
26

27 28 29 30 31 32
/**
 * \file
 * This file defines functions and structures for stream meta-data in vlc
 *
 */

33 34
#include <vlc_arrays.h>

35 36
typedef enum vlc_meta_type_t
{
Rafaël Carré's avatar
Rafaël Carré committed
37
    vlc_meta_Title,
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    vlc_meta_Artist,
    vlc_meta_Genre,
    vlc_meta_Copyright,
    vlc_meta_Album,
    vlc_meta_TrackNumber,
    vlc_meta_Description,
    vlc_meta_Rating,
    vlc_meta_Date,
    vlc_meta_Setting,
    vlc_meta_URL,
    vlc_meta_Language,
    vlc_meta_NowPlaying,
    vlc_meta_Publisher,
    vlc_meta_EncodedBy,
    vlc_meta_ArtworkURL,
    vlc_meta_TrackID
} vlc_meta_type_t;

Rafaël Carré's avatar
Rafaël Carré committed
56 57
#define VLC_META_TYPE_COUNT 17

58 59
/* Returns a localizes string describing the meta */
VLC_EXPORT(const char *, input_MetaTypeToLocalizedString, ( vlc_meta_type_t meta_type ) );
60

61
#define ITEM_PREPARSED      0x01
Rafaël Carré's avatar
Rafaël Carré committed
62 63 64
#define ITEM_ARTURL_FETCHED 0x02
#define ITEM_ART_FETCHED    0x04
#define ITEM_ART_NOTFOUND   0x08
65

66 67
struct vlc_meta_t
{
68
    char * ppsz_meta[VLC_META_TYPE_COUNT];
Laurent Aimar's avatar
Laurent Aimar committed
69

70
    vlc_dictionary_t extra_tags;
71 72

    int i_status;
73 74
};

75
/* Setters for meta.
76
 * Warning: Make sure to use the input_item meta setters (defined in vlc_input.h)
77 78 79 80 81 82
 * instead of those one. */
#define vlc_meta_SetTitle( meta, b )       vlc_meta_Set( meta, vlc_meta_Title, b )
#define vlc_meta_SetArtist( meta, b )      vlc_meta_Set( meta, vlc_meta_Artist, b )
#define vlc_meta_SetGenre( meta, b )       vlc_meta_Set( meta, vlc_meta_Genre, b )
#define vlc_meta_SetCopyright( meta, b )   vlc_meta_Set( meta, vlc_meta_Copyright, b )
#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 85 86 87 88 89 90 91 92 93 94 95
#define vlc_meta_SetDescription( meta, b ) vlc_meta_Set( meta, vlc_meta_Description, b )
#define vlc_meta_SetRating( meta, b )      vlc_meta_Set( meta, vlc_meta_Rating, b )
#define vlc_meta_SetDate( meta, b )        vlc_meta_Set( meta, vlc_meta_Date, b )
#define vlc_meta_SetSetting( meta, b )     vlc_meta_Set( meta, vlc_meta_Setting, b )
#define vlc_meta_SetURL( meta, b )         vlc_meta_Set( meta, vlc_meta_URL, b )
#define vlc_meta_SetLanguage( meta, b )    vlc_meta_Set( meta, vlc_meta_Language, b )
#define vlc_meta_SetNowPlaying( meta, b )  vlc_meta_Set( meta, vlc_meta_NowPlaying, b )
#define vlc_meta_SetPublisher( meta, b )   vlc_meta_Set( meta, vlc_meta_Publisher, b )
#define vlc_meta_SetEncodedBy( meta, b )   vlc_meta_Set( meta, vlc_meta_EncodedBy, b )
#define vlc_meta_SetArtURL( meta, b )      vlc_meta_Set( meta, vlc_meta_ArtworkURL, b )
#define vlc_meta_SetTrackID( meta, b )     vlc_meta_Set( meta, vlc_meta_TrackID, b )

96
/* Free a dictonary key allocated by strdup() in vlc_meta_AddExtra() */
Laurent Aimar's avatar
Laurent Aimar committed
97
static inline void vlc_meta_FreeExtraKey( void *p_data, void *p_obj )
98 99 100 101 102
{
    VLC_UNUSED( p_obj );
    free( p_data );
}

Laurent Aimar's avatar
Laurent Aimar committed
103
static inline void vlc_meta_Set( vlc_meta_t *p_meta, vlc_meta_type_t meta_type, const char *psz_val )
104
{
105
    free( p_meta->ppsz_meta[meta_type] );
106 107 108
    p_meta->ppsz_meta[meta_type] = psz_val ? strdup( psz_val ) : NULL;
}

Laurent Aimar's avatar
Laurent Aimar committed
109
static inline const char *vlc_meta_Get( const vlc_meta_t *p_meta, vlc_meta_type_t meta_type )
110 111 112
{
    return p_meta->ppsz_meta[meta_type];
}
113

114 115
static inline vlc_meta_t *vlc_meta_New( void )
{
Laurent Aimar's avatar
Laurent Aimar committed
116 117 118
    vlc_meta_t *m = (vlc_meta_t*)malloc( sizeof(*m) );
    if( !m )
        return NULL;
119
    memset( m->ppsz_meta, 0, sizeof(m->ppsz_meta) );
120
    m->i_status = 0;
121
    vlc_dictionary_init( &m->extra_tags, 0 );
122 123
    return m;
}
124

125 126
static inline void vlc_meta_Delete( vlc_meta_t *m )
{
127
    int i;
Rafaël Carré's avatar
Rafaël Carré committed
128
    for( i = 0; i < VLC_META_TYPE_COUNT ; i++ )
129
        free( m->ppsz_meta[i] );
Laurent Aimar's avatar
Laurent Aimar committed
130
    vlc_dictionary_clear( &m->extra_tags, vlc_meta_FreeExtraKey, NULL );
131 132
    free( m );
}
133

Laurent Aimar's avatar
Laurent Aimar committed
134 135
static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value )
{
Laurent Aimar's avatar
Laurent Aimar committed
136
    char *psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name );
137
    if( psz_oldvalue != kVLCDictionaryNotFound )
138
        vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name,
Laurent Aimar's avatar
Laurent Aimar committed
139
                                             vlc_meta_FreeExtraKey, NULL );
140
    vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) );
Laurent Aimar's avatar
Laurent Aimar committed
141
}
142

Laurent Aimar's avatar
Laurent Aimar committed
143
static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
144
{
Laurent Aimar's avatar
Laurent Aimar committed
145
    char **ppsz_all_keys;
146
    int i;
147

Laurent Aimar's avatar
Laurent Aimar committed
148 149
    if( !dst || !src )
        return;
150 151 152 153 154

    for( i = 0; i < VLC_META_TYPE_COUNT; i++ )
    {
        if( src->ppsz_meta[i] )
        {
155
            free( dst->ppsz_meta[i] );
156 157 158 159
            dst->ppsz_meta[i] = strdup( src->ppsz_meta[i] );
        }
    }

160 161
    /* XXX: If speed up are needed, it is possible */
    ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags );
Laurent Aimar's avatar
Laurent Aimar committed
162
    for( i = 0; ppsz_all_keys && ppsz_all_keys[i]; i++ )
Laurent Aimar's avatar
Laurent Aimar committed
163
    {
164
        /* Always try to remove the previous value */
Laurent Aimar's avatar
Laurent Aimar committed
165 166 167 168
        vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i], vlc_meta_FreeExtraKey, NULL );

        void *p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] );
        vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], strdup( (const char*)p_value ) );
169
        free( ppsz_all_keys[i] );
Laurent Aimar's avatar
Laurent Aimar committed
170
    }
171
    free( ppsz_all_keys );
172 173
}

174 175 176 177
#define VLC_META_TITLE              input_MetaTypeToLocalizedString( vlc_meta_Title )
#define VLC_META_ARTIST             input_MetaTypeToLocalizedString( vlc_meta_Artist )
#define VLC_META_GENRE              input_MetaTypeToLocalizedString( vlc_meta_Genre )
#define VLC_META_COPYRIGHT          input_MetaTypeToLocalizedString( vlc_meta_Copyright )
Rafaël Carré's avatar
Rafaël Carré committed
178 179
#define VLC_META_ALBUM              input_MetaTypeToLocalizedString( vlc_meta_Album )
#define VLC_META_TRACK_NUMBER       input_MetaTypeToLocalizedString( vlc_meta_TrackNumber )
180 181 182 183 184 185 186 187 188 189
#define VLC_META_DESCRIPTION        input_MetaTypeToLocalizedString( vlc_meta_Description )
#define VLC_META_RATING             input_MetaTypeToLocalizedString( vlc_meta_Rating )
#define VLC_META_DATE               input_MetaTypeToLocalizedString( vlc_meta_Date )
#define VLC_META_SETTING            input_MetaTypeToLocalizedString( vlc_meta_Setting )
#define VLC_META_URL                input_MetaTypeToLocalizedString( vlc_meta_URL )
#define VLC_META_LANGUAGE           input_MetaTypeToLocalizedString( vlc_meta_Language )
#define VLC_META_NOW_PLAYING        input_MetaTypeToLocalizedString( vlc_meta_NowPlaying )
#define VLC_META_PUBLISHER          input_MetaTypeToLocalizedString( vlc_meta_Publisher )
#define VLC_META_ENCODED_BY         input_MetaTypeToLocalizedString( vlc_meta_EncodedBy )
#define VLC_META_ART_URL            input_MetaTypeToLocalizedString( vlc_meta_ArtworkURL )
190
#define VLC_META_TRACKID            input_MetaTypeToLocalizedString( vlc_meta_TrackID )
191

192 193 194
enum {
    ALBUM_ART_WHEN_ASKED,
    ALBUM_ART_WHEN_PLAYED,
195 196
    ALBUM_ART_ALL
};
197

198
typedef struct meta_export_t
Rafaël Carré's avatar
Rafaël Carré committed
199
{
200
    VLC_COMMON_MEMBERS
Rafaël Carré's avatar
Rafaël Carré committed
201 202
    input_item_t *p_item;
    const char *psz_file;
203 204 205
} meta_export_t;

VLC_EXPORT( int, input_item_WriteMeta, (vlc_object_t *, input_item_t *) );
Rafaël Carré's avatar
Rafaël Carré committed
206

207
#endif