]> git.sesse.net Git - vlc/blob - src/input/meta.c
Fixed embedded art attachment support (close #2416)
[vlc] / src / input / meta.c
1 /*****************************************************************************
2  * meta.c : Metadata handling
3  *****************************************************************************
4  * Copyright (C) 1998-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *          ClĂ©ment Stenac <zorglub@videolan.org
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_playlist.h>
31 #include "input_internal.h"
32 #include "../playlist/art.h"
33
34 /* FIXME bad name convention */
35 const char * input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type )
36 {
37     switch( meta_type )
38     {
39     case vlc_meta_Title:        return _("Title");
40     case vlc_meta_Artist:       return _("Artist");
41     case vlc_meta_Genre:        return _("Genre");
42     case vlc_meta_Copyright:    return _("Copyright");
43     case vlc_meta_Album:        return _("Album");
44     case vlc_meta_TrackNumber:  return _("Track number");
45     case vlc_meta_Description:  return _("Description");
46     case vlc_meta_Rating:       return _("Rating");
47     case vlc_meta_Date:         return _("Date");
48     case vlc_meta_Setting:      return _("Setting");
49     case vlc_meta_URL:          return _("URL");
50     case vlc_meta_Language:     return _("Language");
51     case vlc_meta_NowPlaying:   return _("Now Playing");
52     case vlc_meta_Publisher:    return _("Publisher");
53     case vlc_meta_EncodedBy:    return _("Encoded by");
54     case vlc_meta_ArtworkURL:   return _("Artwork URL");
55     case vlc_meta_TrackID:      return _("Track ID");
56
57     default: abort();
58     }
59 };
60
61 void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
62 {
63     input_item_t *p_item = p_input->p->p_item;
64
65     /* */
66     char *psz_arturl = input_item_GetArtURL( p_item );
67     if( !psz_arturl || strncmp( psz_arturl, "attachment://", strlen("attachment://") ) )
68     {
69         msg_Err( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
70         free( psz_arturl );
71         return;
72     }
73
74     playlist_t *p_playlist = pl_Hold( p_input );
75     if( !p_playlist )
76     {
77         free( psz_arturl );
78         return;
79     }
80
81
82     if( input_item_IsArtFetched( p_item ) )
83     {
84         /* XXX Weird, we should not have end up with attachment:// art url unless there is a race
85          * condition */
86         msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
87         playlist_FindArtInCache( p_item );
88         goto exit;
89     }
90
91     /* */
92     input_attachment_t *p_attachment = NULL;
93
94     vlc_mutex_lock( &p_item->lock );
95     for( int i_idx = 0; i_idx < p_input->p->i_attachment; i_idx++ )
96     {
97         if( !strcmp( p_input->p->attachment[i_idx]->psz_name,
98                      &psz_arturl[strlen("attachment://")] ) )
99         {
100             p_attachment = vlc_input_attachment_Duplicate( p_input->p->attachment[i_idx] );
101             break;
102         }
103     }
104     vlc_mutex_unlock( &p_item->lock );
105
106     if( !p_attachment || p_attachment->i_data <= 0 )
107     {
108         if( p_attachment )
109             vlc_input_attachment_Delete( p_attachment );
110         msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
111         goto exit;
112     }
113
114     /* */
115     const char *psz_type = NULL;
116     if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) )
117         psz_type = ".jpg";
118     else if( !strcmp( p_attachment->psz_mime, "image/png" ) )
119         psz_type = ".png";
120
121     /* */
122     playlist_SaveArt( p_playlist, p_item,
123                       p_attachment->p_data, p_attachment->i_data, psz_type );
124
125     vlc_input_attachment_Delete( p_attachment );
126
127 exit:
128     pl_Release( p_input );
129     free( psz_arturl );
130 }
131