meta.c 4.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*****************************************************************************
 * meta.c : Metadata handling
 *****************************************************************************
 * Copyright (C) 1998-2004 the VideoLAN team
 * $Id$
 *
 * Authors: Antoine Cellerier <dionoea@videolan.org>
 *          Clément Stenac <zorglub@videolan.org
 *
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

25 26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

29
#include <vlc_common.h>
Clément Stenac's avatar
Clément Stenac committed
30
#include <vlc_playlist.h>
31
#include "input_internal.h"
32
#include "../playlist/art.h"
33

34 35
/* FIXME bad name convention */
const char * input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type )
36
{
Rafaël Carré's avatar
Rafaël Carré committed
37
    switch( meta_type )
38
    {
Rafaël Carré's avatar
Rafaël Carré committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    case vlc_meta_Title:        return _("Title");
    case vlc_meta_Artist:       return _("Artist");
    case vlc_meta_Genre:        return _("Genre");
    case vlc_meta_Copyright:    return _("Copyright");
    case vlc_meta_Album:        return _("Album");
    case vlc_meta_TrackNumber:  return _("Track number");
    case vlc_meta_Description:  return _("Description");
    case vlc_meta_Rating:       return _("Rating");
    case vlc_meta_Date:         return _("Date");
    case vlc_meta_Setting:      return _("Setting");
    case vlc_meta_URL:          return _("URL");
    case vlc_meta_Language:     return _("Language");
    case vlc_meta_NowPlaying:   return _("Now Playing");
    case vlc_meta_Publisher:    return _("Publisher");
    case vlc_meta_EncodedBy:    return _("Encoded by");
    case vlc_meta_ArtworkURL:   return _("Artwork URL");
    case vlc_meta_TrackID:      return _("Track ID");

    default: abort();
58
    }
Rafaël Carré's avatar
Rafaël Carré committed
59
};
60

61 62
void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
{
63
    input_item_t *p_item = p_input->p->p_item;
64

65 66
    /* */
    const char *psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
67 68 69 70 71 72
    if( !psz_arturl || strncmp( psz_arturl, "attachment://", strlen("attachment://") ) )
    {
        msg_Err( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
        return;
    }

73 74 75 76 77
    playlist_t *p_playlist = pl_Hold( p_input );
    if( !p_playlist )
        return;


78
    if( input_item_IsArtFetched( p_item ) )
79 80 81 82
    {
        /* XXX Weird, we should not have end up with attachment:// art url unless there is a race
         * condition */
        msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
83 84
        playlist_FindArtInCache( p_item );
        pl_Release( p_playlist );
85 86 87 88
        return;
    }

    /* */
89 90
    input_attachment_t *p_attachment = NULL;
    for( int i_idx = 0; i_idx < p_input->p->i_attachment; i_idx++ )
91 92 93 94 95 96 97 98 99 100 101
    {
        if( !strcmp( p_input->p->attachment[i_idx]->psz_name,
                     &psz_arturl[strlen("attachment://")] ) )
        {
            p_attachment = p_input->p->attachment[i_idx];
            break;
        }
    }
    if( !p_attachment || p_attachment->i_data <= 0 )
    {
        msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
102
        pl_Release( p_playlist );
103
        return;
104 105
    }

106 107
    /* */
    const char *psz_type = NULL;
108
    if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) )
109
        psz_type = ".jpg";
110
    else if( !strcmp( p_attachment->psz_mime, "image/png" ) )
111
        psz_type = ".png";
112

113 114 115
    /* */
    playlist_SaveArt( p_playlist, p_item,
                      p_attachment->p_data, p_attachment->i_data, psz_type );
116

117
    pl_Release( p_playlist );
118
}
119