1 /*****************************************************************************
2 * meta.c : Metadata handling
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea@videolan.org>
8 * Clément Stenac <zorglub@videolan.org
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.
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.
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 *****************************************************************************/
29 #include <vlc_common.h>
30 #include <vlc_playlist.h>
33 #include "input_internal.h"
34 #include "../playlist/art.h"
36 /* FIXME bad name convention */
37 const char * input_MetaTypeToLocalizedString( vlc_meta_type_t meta_type )
41 case vlc_meta_Title: return _("Title");
42 case vlc_meta_Artist: return _("Artist");
43 case vlc_meta_Genre: return _("Genre");
44 case vlc_meta_Copyright: return _("Copyright");
45 case vlc_meta_Album: return _("Album");
46 case vlc_meta_TrackNumber: return _("Track number");
47 case vlc_meta_Description: return _("Description");
48 case vlc_meta_Rating: return _("Rating");
49 case vlc_meta_Date: return _("Date");
50 case vlc_meta_Setting: return _("Setting");
51 case vlc_meta_URL: return _("URL");
52 case vlc_meta_Language: return _("Language");
53 case vlc_meta_NowPlaying: return _("Now Playing");
54 case vlc_meta_Publisher: return _("Publisher");
55 case vlc_meta_EncodedBy: return _("Encoded by");
56 case vlc_meta_ArtworkURL: return _("Artwork URL");
57 case vlc_meta_TrackID: return _("Track ID");
63 void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
65 input_item_t *p_item = p_input->p->p_item;
68 char *psz_arturl = input_item_GetArtURL( p_item );
69 if( !psz_arturl || strncmp( psz_arturl, "attachment://", strlen("attachment://") ) )
71 msg_Err( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
76 playlist_t *p_playlist = pl_Hold( p_input );
84 if( input_item_IsArtFetched( p_item ) )
86 /* XXX Weird, we should not have end up with attachment:// art url unless there is a race
88 msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
89 playlist_FindArtInCache( p_item );
94 input_attachment_t *p_attachment = NULL;
96 vlc_mutex_lock( &p_item->lock );
97 for( int i_idx = 0; i_idx < p_input->p->i_attachment; i_idx++ )
99 if( !strcmp( p_input->p->attachment[i_idx]->psz_name,
100 &psz_arturl[strlen("attachment://")] ) )
102 p_attachment = vlc_input_attachment_Duplicate( p_input->p->attachment[i_idx] );
106 vlc_mutex_unlock( &p_item->lock );
108 if( !p_attachment || p_attachment->i_data <= 0 )
111 vlc_input_attachment_Delete( p_attachment );
112 msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
117 const char *psz_type = NULL;
118 if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) )
120 else if( !strcmp( p_attachment->psz_mime, "image/png" ) )
124 playlist_SaveArt( p_playlist, p_item,
125 p_attachment->p_data, p_attachment->i_data, psz_type );
127 vlc_input_attachment_Delete( p_attachment );
130 pl_Release( p_input );
134 int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item )
136 meta_export_t *p_export =
137 vlc_custom_create( obj, sizeof( *p_export ), VLC_OBJECT_GENERIC,
139 if( p_export == NULL )
141 vlc_object_attach( p_export, obj );
142 p_export->p_item = p_item;
145 vlc_mutex_lock( &p_item->lock );
146 type = p_item->i_type;
147 vlc_mutex_unlock( &p_item->lock );
148 if( type == ITEM_TYPE_FILE )
150 char *psz_uri = input_item_GetURI( p_item );
152 #warning FIXME: function for URI->path conversion!
153 decode_URI( psz_uri );
154 if( !strncmp( psz_uri, "file://", 7 ) )
156 p_export->psz_file = strdup( psz_uri + 7 );
160 #warning This should not happen!
161 p_export->psz_file = psz_uri;
165 vlc_object_release( p_export );
169 module_t *p_mod = module_need( p_export, "meta writer", NULL, false );
171 module_unneed( p_export, p_mod );
172 vlc_object_release( p_export );