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