vlc_meta.h 8.73 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
 *****************************************************************************/

Clément Stenac's avatar
Clément Stenac committed
24 25 26 27
#if !defined( __LIBVLC__ )
  #error You are not libvlc or one of its plugins. You cannot include this file
#endif

28 29 30
#ifndef _VLC_META_H
#define _VLC_META_H 1

31 32
#include <vlc_arrays.h>

33
#define VLC_META_TYPE_COUNT 17
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
typedef enum vlc_meta_type_t
{
    vlc_meta_Title = 0,
    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;

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

59 60 61 62
#define ITEM_PREPARSED      0x01
#define ITEM_META_FETCHED   0x02
#define ITEM_ARTURL_FETCHED 0x04
#define ITEM_ART_FETCHED    0x08
63
#define ITEM_ART_NOTFOUND   0x10
64

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

69
    vlc_dictionary_t extra_tags;
70 71

    int i_status;
Laurent Aimar's avatar
Laurent Aimar committed
72

73 74
};

75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
/* Setters for meta.
 * Warning: Make sure to use the input_item meta setters (defined in vlc_input.h) 
 * 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 )
#define vlc_meta_SetTracknum( meta, b )    vlc_meta_Set( meta, vlc_meta_TrackNumber, b )
#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 )

static inline void vlc_meta_Set( vlc_meta_t * p_meta, vlc_meta_type_t meta_type, const char * psz_val )
{
    if( p_meta->ppsz_meta[meta_type] ) free( p_meta->ppsz_meta[meta_type] );
    p_meta->ppsz_meta[meta_type] = psz_val ? strdup( psz_val ) : NULL;
}

static inline const char * vlc_meta_Get( const vlc_meta_t * p_meta, vlc_meta_type_t meta_type )
{
    return p_meta->ppsz_meta[meta_type];
}
106

107 108
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) );
112
    m->i_status = 0;
113
    vlc_dictionary_init( &m->extra_tags, 0 );
114 115
    return m;
}
116

117 118
static inline void vlc_meta_Delete( vlc_meta_t *m )
{
119 120 121
    int i;
    for( i = 0; i < 0; i++ )
        free( m->ppsz_meta[i] );
122
    vlc_dictionary_clear( &m->extra_tags );
123 124
    free( m );
}
125

Laurent Aimar's avatar
Laurent Aimar committed
126 127
static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value )
{
128 129 130 131 132 133 134
    char * psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name );
    if( psz_oldvalue != kVLCDictionaryNotFound )
    {
        free( psz_oldvalue );
        vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name );
    }
    vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) );
Laurent Aimar's avatar
Laurent Aimar committed
135
}
136

Laurent Aimar's avatar
Laurent Aimar committed
137
static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
138
{
139 140
    char ** ppsz_all_keys;
    int i;
141 142 143 144 145 146 147 148 149 150 151 152

    if( !dst || !src ) return;

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

153 154 155
    /* XXX: If speed up are needed, it is possible */
    ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags );
    for( i = 0; ppsz_all_keys[i]; i++ )
Laurent Aimar's avatar
Laurent Aimar committed
156
    {
157 158 159 160 161
        /* Always try to remove the previous value */
        vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i] );
        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], p_value );
        free( ppsz_all_keys[i] );
Laurent Aimar's avatar
Laurent Aimar committed
162
    }
163
    free( ppsz_all_keys );
164 165
}

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
/* Shortcuts for the AddInfo */
#define VLC_META_INFO_CAT           N_("Meta-information")
#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 )
#define VLC_META_COLLECTION         input_MetaTypeToLocalizedString( vlc_meta_Album )
#define VLC_META_SEQ_NUM            input_MetaTypeToLocalizedString( vlc_meta_TrackNumber )
#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 )
#define VLC_META_CODEC_NAME         N_("Codec Name")
#define VLC_META_CODEC_DESCRIPTION  N_("Codec Description")

187 188 189
enum {
    ALBUM_ART_WHEN_ASKED,
    ALBUM_ART_WHEN_PLAYED,
190 191
    ALBUM_ART_ALL
};
192

Rafaël Carré's avatar
Rafaël Carré committed
193 194 195 196 197 198
struct meta_export_t
{
    input_item_t *p_item;
    const char *psz_file;
};

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
#define VLC_META_ENGINE_TITLE           0x00000001
#define VLC_META_ENGINE_ARTIST          0x00000004
#define VLC_META_ENGINE_GENRE           0x00000008
#define VLC_META_ENGINE_COPYRIGHT       0x00000010
#define VLC_META_ENGINE_COLLECTION      0x00000020
#define VLC_META_ENGINE_SEQ_NUM         0x00000040
#define VLC_META_ENGINE_DESCRIPTION     0x00000080
#define VLC_META_ENGINE_RATING          0x00000100
#define VLC_META_ENGINE_DATE            0x00000200
#define VLC_META_ENGINE_URL             0x00000400
#define VLC_META_ENGINE_LANGUAGE        0x00000800

#define VLC_META_ENGINE_ART_URL         0x00001000

#define VLC_META_ENGINE_MB_ARTIST_ID    0x00002000
#define VLC_META_ENGINE_MB_RELEASE_ID   0x00004000
#define VLC_META_ENGINE_MB_TRACK_ID     0x00008000
#define VLC_META_ENGINE_MB_TRM_ID       0x00010000

typedef struct meta_engine_sys_t meta_engine_sys_t;

struct meta_engine_t
{
    VLC_COMMON_MEMBERS

    module_t *p_module;

    uint32_t i_mandatory; /**< Stuff which we really need to get */
    uint32_t i_optional; /**< Stuff which we'd like to have */

    input_item_t *p_item;
};

Clément Stenac's avatar
Clément Stenac committed
232
VLC_EXPORT(uint32_t, input_CurrentMetaFlags,( vlc_meta_t *p_meta ) );
233

234
#endif