]> git.sesse.net Git - vlc/blob - modules/meta_engine/taglib.cpp
taglib: read the cover art from mp4.
[vlc] / modules / meta_engine / taglib.cpp
1 /*****************************************************************************
2  * taglib.cpp: Taglib tag parser/writer
3  *****************************************************************************
4  * Copyright (C) 2003-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Rafaël Carré <funman@videolanorg>
9  *          Rémi Duraffort <ivoire@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_playlist.h>
33 #include <vlc_meta.h>
34 #include <vlc_demux.h>
35 #include <vlc_strings.h>
36 #include <vlc_charset.h>
37 #include <vlc_url.h>
38
39 #ifdef WIN32
40 # include <io.h>
41 #else
42 # include <unistd.h>
43 #endif
44
45
46 // Taglib headers
47 #include <fileref.h>
48 #include <tag.h>
49 #include <tbytevector.h>
50
51 #include <apetag.h>
52 #include <id3v2tag.h>
53 #include <xiphcomment.h>
54
55 #include <flacfile.h>
56 #include <mpcfile.h>
57 #include <mpegfile.h>
58 #include <oggfile.h>
59 #include <oggflacfile.h>
60
61 #ifdef TAGLIB_WITH_ASF
62 # include <aifffile.h>
63 # include <wavfile.h>
64 #endif
65
66 #ifdef TAGLIB_WITH_MP4
67 # include <mp4file.h>
68 #endif
69
70 #include <speexfile.h>
71 #include <trueaudiofile.h>
72 #include <vorbisfile.h>
73 #include <wavpackfile.h>
74
75 #include <attachedpictureframe.h>
76 #include <textidentificationframe.h>
77 #include <uniquefileidentifierframe.h>
78
79
80 // Local functions
81 static int ReadMeta    ( vlc_object_t * );
82 static int WriteMeta   ( vlc_object_t * );
83
84 vlc_module_begin ()
85     set_capability( "meta reader", 1000 )
86     set_callbacks( ReadMeta, NULL )
87     add_submodule ()
88         set_capability( "meta writer", 50 )
89         set_callbacks( WriteMeta, NULL )
90 vlc_module_end ()
91
92 using namespace TagLib;
93
94
95 /**
96  * Read meta informations from APE tags
97  * @param tag: the APE tag
98  * @param p_demux; the demux object
99  * @param p_demux_meta: the demuxer meta
100  * @param p_meta: the meta
101  */
102 static void ReadMetaFromAPE( APE::Tag* tag, demux_t* p_demux, demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
103 {
104     APE::Item item;
105 #define SET( keyName, metaName ) \
106     item = tag->itemListMap()[keyName]; \
107     vlc_meta_Set##metaName( p_meta, item.toString().toCString( true ) );\
108
109     SET( "COPYRIGHT", Copyright );
110     SET( "LANGUAGE", Language );
111     SET( "PUBLISHER", Publisher );
112
113 #undef SET
114 }
115
116
117
118 /**
119  * Read meta information from id3v2 tags
120  * @param tag: the id3v2 tag
121  * @param p_demux; the demux object
122  * @param p_demux_meta: the demuxer meta
123  * @param p_meta: the meta
124  */
125 static void ReadMetaFromId3v2( ID3v2::Tag* tag, demux_t* p_demux, demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
126 {
127     // Get the unique file identifier
128     ID3v2::FrameList list = tag->frameListMap()["UFID"];
129     ID3v2::FrameList::Iterator iter;
130     for( iter = list.begin(); iter != list.end(); iter++ )
131     {
132         ID3v2::UniqueFileIdentifierFrame* p_ufid =
133                 dynamic_cast<ID3v2::UniqueFileIdentifierFrame*>(*iter);
134         const char *owner = p_ufid->owner().toCString();
135         if (!strcmp( owner, "http://musicbrainz.org" ))
136         {
137             /* ID3v2 UFID contains up to 64 bytes binary data
138              * but in our case it will be a '\0'
139              * terminated string */
140             char psz_ufid[64];
141             int max_size = __MIN( p_ufid->identifier().size(), 63);
142             strncpy( psz_ufid, p_ufid->identifier().data(), max_size );
143             psz_ufid[max_size] = '\0';
144             vlc_meta_SetTrackID( p_meta, psz_ufid );
145         }
146     }
147
148     // Get the use text
149     list = tag->frameListMap()["TXXX"];
150     for( iter = list.begin(); iter != list.end(); iter++ )
151     {
152         ID3v2::UserTextIdentificationFrame* p_txxx =
153                 dynamic_cast<ID3v2::UserTextIdentificationFrame*>(*iter);
154         vlc_meta_AddExtra( p_meta, p_txxx->description().toCString( true ),
155                            p_txxx->fieldList().toString().toCString( true ) );
156     }
157
158     // Get some more informations
159 #define SET( tagName, metaName )                                               \
160     list = tag->frameListMap()[tagName];                                       \
161     if( !list.isEmpty() )                                                      \
162         vlc_meta_Set##metaName( p_meta,                                        \
163                                 (*list.begin())->toString().toCString( true ) );
164
165     SET( "TCOP", Copyright );
166     SET( "TENC", EncodedBy );
167     SET( "TLAN", Language );
168     SET( "TPUB", Publisher );
169
170 #undef SET
171
172     /* Preferred type of image
173      * The 21 types are defined in id3v2 standard:
174      * http://www.id3.org/id3v2.4.0-frames */
175     static const int pi_cover_score[] = {
176         0,  /* Other */
177         5,  /* 32x32 PNG image that should be used as the file icon */
178         4,  /* File icon of a different size or format. */
179         20, /* Front cover image of the album. */
180         19, /* Back cover image of the album. */
181         13, /* Inside leaflet page of the album. */
182         18, /* Image from the album itself. */
183         17, /* Picture of the lead artist or soloist. */
184         16, /* Picture of the artist or performer. */
185         14, /* Picture of the conductor. */
186         15, /* Picture of the band or orchestra. */
187         9,  /* Picture of the composer. */
188         8,  /* Picture of the lyricist or text writer. */
189         7,  /* Picture of the recording location or studio. */
190         10, /* Picture of the artists during recording. */
191         11, /* Picture of the artists during performance. */
192         6,  /* Picture from a movie or video related to the track. */
193         1,  /* Picture of a large, coloured fish. */
194         12, /* Illustration related to the track. */
195         3,  /* Logo of the band or performer. */
196         2   /* Logo of the publisher (record company). */
197     };
198     int i_score = -1;
199
200     // Try now to get embedded art
201     list = tag->frameListMap()[ "APIC" ];
202     if( list.isEmpty() )
203         return;
204
205     TAB_INIT( p_demux_meta->i_attachments, p_demux_meta->attachments );
206     for( iter = list.begin(); iter != list.end(); iter++ )
207     {
208         ID3v2::AttachedPictureFrame* p_apic =
209             dynamic_cast<ID3v2::AttachedPictureFrame*>(*iter);
210         input_attachment_t *p_attachment;
211
212         const char *psz_mime;
213         char *psz_name, *psz_description;
214
215         // Get the mime and description of the image.
216         // If the description is empty, take the type as a description
217         psz_mime = p_apic->mimeType().toCString( true );
218         if( p_apic->description().size() > 0 )
219             psz_description = strdup( p_apic->description().toCString( true ) );
220         else
221         {
222             if( asprintf( &psz_description, "%i", p_apic->type() ) == -1 )
223                 psz_description = NULL;
224         }
225
226         if( !psz_description )
227             continue;
228         psz_name = psz_description;
229
230         /* some old iTunes version not only sets incorrectly the mime type
231          * or the description of the image,
232          * but also embeds incorrectly the image.
233          * Recent versions seem to behave correctly */
234         if( !strncmp( psz_mime, "PNG", 3 ) ||
235             !strncmp( psz_name, "\xC2\x89PNG", 5 ) )
236         {
237             msg_Warn( p_demux_meta, "Invalid picture embedded by broken iTunes version" );
238             free( psz_description );
239             continue;
240         }
241
242         const ByteVector picture = p_apic->picture();
243         const char *p_data = picture.data();
244         const unsigned i_data = picture.size();
245
246         msg_Dbg( p_demux_meta, "Found embedded art: %s (%s) is %u bytes",
247                  psz_name, psz_mime, i_data );
248
249         p_attachment = vlc_input_attachment_New( psz_name, psz_mime,
250                                 psz_description, p_data, i_data );
251         if( p_attachment )
252             TAB_APPEND_CAST( (input_attachment_t**),
253                              p_demux_meta->i_attachments, p_demux_meta->attachments,
254                              p_attachment );
255         free( psz_description );
256
257         if( pi_cover_score[p_apic->type()] > i_score )
258         {
259             i_score = pi_cover_score[p_apic->type()];
260             char *psz_url;
261             if( asprintf( &psz_url, "attachment://%s",
262                           p_attachment->psz_name ) == -1 )
263                 continue;
264             vlc_meta_SetArtURL( p_meta, psz_url );
265             free( psz_url );
266         }
267     }
268 }
269
270
271
272 /**
273  * Read the meta informations from XiphComments
274  * @param tag: the Xiph Comment
275  * @param p_demux; the demux object
276  * @param p_demux_meta: the demuxer meta
277  * @param p_meta: the meta
278  */
279 static void ReadMetaFromXiph( Ogg::XiphComment* tag, demux_t* p_demux, demux_meta_t* p_demux_meta, vlc_meta_t* p_meta )
280 {
281 #define SET( keyName, metaName )                                               \
282     StringList list = tag->fieldListMap()[keyName];                            \
283     if( !list.isEmpty() )                                                      \
284         vlc_meta_Set##metaName( p_meta, (*list.begin()).toCString( true ) );
285
286     SET( "COPYRIGHT", Copyright );
287 #undef SET
288
289     // Try now to get embedded art
290     StringList mime_list = tag->fieldListMap()[ "COVERARTMIME" ];
291     StringList art_list = tag->fieldListMap()[ "COVERART" ];
292
293     // We get only the first covert art
294     if( mime_list.size() > 1 || art_list.size() > 1 )
295         msg_Warn( p_demux_meta, "Found %i embedded arts, so using only the first one",
296                   art_list.size() );
297     else if( mime_list.size() == 0 || art_list.size() == 0 )
298         return;
299
300     input_attachment_t *p_attachment;
301
302     const char* psz_name = "cover";
303     const char* psz_mime = mime_list[0].toCString(true);
304     const char* psz_description = "cover";
305
306     uint8_t *p_data;
307     int i_data = vlc_b64_decode_binary( &p_data, art_list[0].toCString(true) );
308
309     msg_Dbg( p_demux_meta, "Found embedded art: %s (%s) is %i bytes",
310              psz_name, psz_mime, i_data );
311
312     TAB_INIT( p_demux_meta->i_attachments, p_demux_meta->attachments );
313               p_attachment = vlc_input_attachment_New( psz_name, psz_mime,
314               psz_description, p_data, i_data );
315     free( p_data );
316
317     TAB_APPEND_CAST( (input_attachment_t**),
318                      p_demux_meta->i_attachments, p_demux_meta->attachments,
319                      p_attachment );
320
321     vlc_meta_SetArtURL( p_meta, "attachment://cover" );
322 }
323
324 #ifdef TAGLIB_WITH_MP4
325 static void ReadMetaFromMP4( MP4::Tag* tag, demux_t *p_demux, demux_meta_t *p_demux_meta, vlc_meta_t* p_meta )
326 {
327     if( tag->itemListMap().contains("covr") )
328     {
329         MP4::CoverArtList list = tag->itemListMap()["covr"].toCoverArtList();
330         const char *psz_format = list[0].format() == MP4::CoverArt::PNG ? "image/png" : "image/jpeg";
331
332         TAB_INIT( p_demux_meta->i_attachments, p_demux_meta->attachments );
333         input_attachment_t *p_attachment =
334                 vlc_input_attachment_New( "cover", psz_format, "cover",
335                                           list[0].data().data(), list[0].data().size() );
336         TAB_APPEND_CAST( (input_attachment_t**),
337                          p_demux_meta->i_attachments, p_demux_meta->attachments,
338                          p_attachment );
339         vlc_meta_SetArtURL( p_meta, "attachment://cover" );
340     }
341 }
342 #endif
343
344 /**
345  * Get the tags from the file using TagLib
346  * @param p_this: the demux object
347  * @return VLC_SUCCESS if the operation success
348  */
349 static int ReadMeta( vlc_object_t* p_this)
350 {
351     demux_meta_t*   p_demux_meta = (demux_meta_t *)p_this;
352     demux_t*        p_demux = p_demux_meta->p_demux;
353     vlc_meta_t*     p_meta;
354     FileRef f;
355     char *psz_path = decode_URI_duplicate( p_demux->psz_path );
356
357     p_demux_meta->p_meta = NULL;
358     if( !psz_path )
359         return VLC_ENOMEM;
360     if( strncmp( p_demux->psz_access, "file", strlen("file") ) )
361         return VLC_EGENERIC;
362
363
364 #if defined(WIN32) || defined (UNDER_CE)
365     wchar_t wpath[MAX_PATH + 1];
366     if( !MultiByteToWideChar( CP_UTF8, 0, psz_path, -1, wpath, MAX_PATH) )
367         return VLC_EGENERIC;
368     wpath[MAX_PATH] = L'\0';
369     f = FileRef( wpath );
370 #else
371     const char* local_name = ToLocale( psz_path );
372     if( !local_name )
373         return VLC_EGENERIC;
374     f = FileRef( local_name );
375     LocaleFree( local_name );
376 #endif
377     free( psz_path );
378
379     if( f.isNull() )
380         return VLC_EGENERIC;
381     if( !f.tag() || f.tag()->isEmpty() )
382         return VLC_EGENERIC;
383
384     p_demux_meta->p_meta = p_meta = vlc_meta_New();
385     if( !p_meta )
386         return VLC_ENOMEM;
387
388
389     // Read the tags from the file
390     Tag* p_tag = f.tag();
391
392 #define SET( tag, meta )                                                       \
393     if( !p_tag->tag().isNull() && !p_tag->tag().isEmpty() )                    \
394         vlc_meta_Set##meta( p_meta, p_tag->tag().toCString(true) )
395 #define SETINT( tag, meta )                                                    \
396     if( p_tag->tag() )                                                         \
397     {                                                                          \
398         char psz_tmp[10];                                                      \
399         snprintf( psz_tmp, 10, "%d", p_tag->tag() );                           \
400         vlc_meta_Set##meta( p_meta, psz_tmp );                                 \
401     }
402
403     SET( title, Title );
404     SET( artist, Artist );
405     SET( album, Album );
406     SET( comment, Description );
407     SET( genre, Genre );
408     SETINT( year, Date );
409     SETINT( track, TrackNum );
410
411 #undef SETINT
412 #undef SET
413
414
415     // Try now to read special tags
416     if( FLAC::File* flac = dynamic_cast<FLAC::File*>(f.file()) )
417     {
418         if( flac->ID3v2Tag() )
419             ReadMetaFromId3v2( flac->ID3v2Tag(), p_demux, p_demux_meta, p_meta );
420         else if( flac->xiphComment() )
421             ReadMetaFromXiph( flac->xiphComment(), p_demux, p_demux_meta, p_meta );
422     }
423 #ifdef TAGLIB_WITH_MP4
424     else if( MP4::File *mp4 = dynamic_cast<MP4::File*>(f.file()) )
425     {
426         if( mp4->tag() )
427             ReadMetaFromMP4( mp4->tag(), p_demux, p_demux_meta, p_meta );
428     }
429 #endif
430     else if( MPC::File* mpc = dynamic_cast<MPC::File*>(f.file()) )
431     {
432         if( mpc->APETag() )
433             ReadMetaFromAPE( mpc->APETag(), p_demux, p_demux_meta, p_meta );
434     }
435     else if( MPEG::File* mpeg = dynamic_cast<MPEG::File*>(f.file()) )
436     {
437         if( mpeg->ID3v2Tag() )
438             ReadMetaFromId3v2( mpeg->ID3v2Tag(), p_demux, p_demux_meta, p_meta );
439         else if( mpeg->APETag() )
440             ReadMetaFromAPE( mpeg->APETag(), p_demux, p_demux_meta, p_meta );
441     }
442     else if( Ogg::File* ogg = dynamic_cast<Ogg::File*>(f.file()) )
443     {
444         if( Ogg::FLAC::File* ogg_flac = dynamic_cast<Ogg::FLAC::File*>(f.file()))
445             ReadMetaFromXiph( ogg_flac->tag(), p_demux, p_demux_meta, p_meta );
446         else if( Ogg::Speex::File* ogg_speex = dynamic_cast<Ogg::Speex::File*>(f.file()) )
447             ReadMetaFromXiph( ogg_speex->tag(), p_demux, p_demux_meta, p_meta );
448         else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
449             ReadMetaFromXiph( ogg_vorbis->tag(), p_demux, p_demux_meta, p_meta );
450     }
451 #ifdef TAGLIB_WITH_ASF
452     else if( RIFF::File* riff = dynamic_cast<RIFF::File*>(f.file()) )
453     {
454         if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
455             ReadMetaFromId3v2( riff_aiff->tag(), p_demux, p_demux_meta, p_meta );
456         else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
457             ReadMetaFromId3v2( riff_wav->tag(), p_demux, p_demux_meta, p_meta );
458     }
459 #endif
460     else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
461     {
462         if( trueaudio->ID3v2Tag() )
463             ReadMetaFromId3v2( trueaudio->ID3v2Tag(), p_demux, p_demux_meta, p_meta );
464     }
465     else if( WavPack::File* wavpack = dynamic_cast<WavPack::File*>(f.file()) )
466     {
467         if( wavpack->APETag() )
468             ReadMetaFromAPE( wavpack->APETag(), p_demux, p_demux_meta, p_meta );
469     }
470
471     return VLC_SUCCESS;
472 }
473
474
475
476 /**
477  * Write meta informations to APE tags
478  * @param tag: the APE tag
479  * @param p_item: the input item
480  */
481 static void WriteMetaToAPE( APE::Tag* tag, input_item_t* p_item )
482 {
483     char* psz_meta;
484 #define WRITE( metaName, keyName )                      \
485     psz_meta = input_item_Get##metaName( p_item );      \
486     if( psz_meta )                                      \
487     {                                                   \
488         String key( keyName, String::UTF8 );            \
489         String value( psz_meta, String::UTF8 );         \
490         tag->addValue( key, value, true );              \
491     }                                                   \
492     free( psz_meta );
493
494     WRITE( Copyright, "COPYRIGHT" );
495     WRITE( Language, "LANGUAGE" );
496     WRITE( Publisher, "PUBLISHER" );
497
498 #undef WRITE
499 }
500
501
502
503 /**
504  * Write meta information to id3v2 tags
505  * @param tag: the id3v2 tag
506  * @param p_input: the input item
507  */
508 static void WriteMetaToId3v2( ID3v2::Tag* tag, input_item_t* p_item )
509 {
510     char* psz_meta;
511 #define WRITE( metaName, tagName )                                            \
512     psz_meta = input_item_Get##metaName( p_item );                            \
513     if( psz_meta )                                                            \
514     {                                                                         \
515         ByteVector p_byte( tagName, 4 );                                      \
516         tag->removeFrames( p_byte );                                         \
517         ID3v2::TextIdentificationFrame* p_frame =                             \
518             new ID3v2::TextIdentificationFrame( p_byte, String::UTF8 );       \
519         p_frame->setText( psz_meta );                                         \
520         tag->addFrame( p_frame );                                             \
521     }                                                                         \
522     free( psz_meta );
523
524     WRITE( Copyright, "TCOP" );
525     WRITE( EncodedBy, "TENC" );
526     WRITE( Language,  "TLAN" );
527     WRITE( Publisher, "TPUB" );
528
529 #undef WRITE
530 }
531
532
533
534 /**
535  * Write the meta informations to XiphComments
536  * @param tag: the Xiph Comment
537  * @param p_input: the input item
538  */
539 static void WriteMetaToXiph( Ogg::XiphComment* tag, input_item_t* p_item )
540 {
541     char* psz_meta;
542 #define WRITE( metaName, keyName )                      \
543     psz_meta = input_item_Get##metaName( p_item );      \
544     if( psz_meta )                                      \
545     {                                                   \
546         String key( keyName, String::UTF8 );            \
547         String value( psz_meta, String::UTF8 );         \
548         tag->addField( key, value, true );              \
549     }                                                   \
550     free( psz_meta );
551
552     WRITE( Copyright, "COPYRIGHT" );
553
554 #undef WRITE
555 }
556
557
558
559 /**
560  * Set the tags to the file using TagLib
561  * @param p_this: the demux object
562  * @return VLC_SUCCESS if the operation success
563  */
564
565 static int WriteMeta( vlc_object_t *p_this )
566 {
567     meta_export_t *p_export = (meta_export_t *)p_this;
568     input_item_t *p_item = p_export->p_item;
569     FileRef f;
570
571     if( !p_item )
572     {
573         msg_Err( p_this, "Can't save meta data of an empty input" );
574         return VLC_EGENERIC;
575     }
576
577 #if defined(WIN32) || defined (UNDER_CE)
578     wchar_t wpath[MAX_PATH + 1];
579     if( !MultiByteToWideChar( CP_UTF8, 0, p_export->psz_file, -1, wpath, MAX_PATH) )
580         return VLC_EGENERIC;
581     wpath[MAX_PATH] = L'\0';
582     f = FileRef( wpath );
583 #else
584     const char* local_name = ToLocale( p_export->psz_file );
585     if( !local_name )
586         return VLC_EGENERIC;
587     f = FileRef( local_name );
588     LocaleFree( local_name );
589 #endif
590
591     if( f.isNull() || !f.tag() || f.file()->readOnly() )
592     {
593         msg_Err( p_this, "File %s can't be opened for tag writing",
594                  p_export->psz_file );
595         return VLC_EGENERIC;
596     }
597
598     msg_Dbg( p_this, "Writing metadata for %s", p_export->psz_file );
599
600     Tag *p_tag = f.tag();
601
602     char *psz_meta;
603
604 #define SET( a, b )                                             \
605     psz_meta = input_item_Get ## a( p_item );                   \
606     if( psz_meta )                                              \
607     {                                                           \
608         String tmp( psz_meta, String::UTF8 );                   \
609         p_tag->set##b( tmp );                                   \
610     }                                                           \
611     free( psz_meta );
612
613     // Saving all common fields
614     // If the title is empty, use the name
615     SET( TitleFbName, Title );
616     SET( Artist, Artist );
617     SET( Album, Album );
618     SET( Description, Comment );
619     SET( Genre, Genre );
620
621 #undef SET
622
623     psz_meta = input_item_GetDate( p_item );
624     if( psz_meta ) p_tag->setYear( atoi( psz_meta ) );
625     free( psz_meta );
626
627     psz_meta = input_item_GetTrackNum( p_item );
628     if( psz_meta ) p_tag->setTrack( atoi( psz_meta ) );
629     free( psz_meta );
630
631
632     // Try now to write special tags
633     if( FLAC::File* flac = dynamic_cast<FLAC::File*>(f.file()) )
634     {
635         if( flac->ID3v2Tag() )
636             WriteMetaToId3v2( flac->ID3v2Tag(), p_item );
637         else if( flac->xiphComment() )
638             WriteMetaToXiph( flac->xiphComment(), p_item );
639     }
640     else if( MPC::File* mpc = dynamic_cast<MPC::File*>(f.file()) )
641     {
642         if( mpc->APETag() )
643             WriteMetaToAPE( mpc->APETag(), p_item );
644     }
645     else if( MPEG::File* mpeg = dynamic_cast<MPEG::File*>(f.file()) )
646     {
647         if( mpeg->ID3v2Tag() )
648             WriteMetaToId3v2( mpeg->ID3v2Tag(), p_item );
649         else if( mpeg->APETag() )
650             WriteMetaToAPE( mpeg->APETag(), p_item );
651     }
652     else if( Ogg::File* ogg = dynamic_cast<Ogg::File*>(f.file()) )
653     {
654         if( Ogg::FLAC::File* ogg_flac = dynamic_cast<Ogg::FLAC::File*>(f.file()))
655             WriteMetaToXiph( ogg_flac->tag(), p_item );
656         else if( Ogg::Speex::File* ogg_speex = dynamic_cast<Ogg::Speex::File*>(f.file()) )
657             WriteMetaToXiph( ogg_speex->tag(), p_item );
658         else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
659             WriteMetaToXiph( ogg_vorbis->tag(), p_item );
660     }
661 #ifdef TAGLIB_WITH_ASF
662     else if( RIFF::File* riff = dynamic_cast<RIFF::File*>(f.file()) )
663     {
664         if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
665             WriteMetaToId3v2( riff_aiff->tag(), p_item );
666         else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
667             WriteMetaToId3v2( riff_wav->tag(), p_item );
668     }
669 #endif
670     else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
671     {
672         if( trueaudio->ID3v2Tag() )
673             WriteMetaToId3v2( trueaudio->ID3v2Tag(), p_item );
674     }
675     else if( WavPack::File* wavpack = dynamic_cast<WavPack::File*>(f.file()) )
676     {
677         if( wavpack->APETag() )
678             WriteMetaToAPE( wavpack->APETag(), p_item );
679     }
680
681     // Save the meta data
682     f.save();
683
684     return VLC_SUCCESS;
685 }
686