]> git.sesse.net Git - vlc/blob - modules/meta_engine/taglib.cpp
taglib writer: use decode_URI_duplicate
[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
334     p_demux_meta->p_meta = NULL;
335
336
337 #if defined(WIN32) || defined (UNDER_CE)
338     wchar_t wpath[MAX_PATH + 1];
339     if( !MultiByteToWideChar( CP_UTF8, 0, p_demux->psz_path, -1, wpath, MAX_PATH) )
340         return VLC_EGENERIC;
341     wpath[MAX_PATH] = L'\0';
342     f = FileRef( wpath );
343 #else
344     const char* local_name = ToLocale( p_demux->psz_path );
345     if( !local_name )
346         return VLC_EGENERIC;
347     f = FileRef( local_name );
348     LocaleFree( local_name );
349 #endif
350
351     if( f.isNull() )
352         return VLC_EGENERIC;
353     if( !f.tag() || f.tag()->isEmpty() )
354         return VLC_EGENERIC;
355
356     p_demux_meta->p_meta = p_meta = vlc_meta_New();
357     if( !p_meta )
358         return VLC_ENOMEM;
359
360
361     // Read the tags from the file
362     Tag* p_tag = f.tag();
363
364 #define SET( tag, meta )                                                       \
365     if( !p_tag->tag().isNull() && !p_tag->tag().isEmpty() )                    \
366         vlc_meta_Set##meta( p_meta, p_tag->tag().toCString(true) )
367 #define SETINT( tag, meta )                                                    \
368     if( p_tag->tag() )                                                         \
369     {                                                                          \
370         char psz_tmp[10];                                                      \
371         snprintf( psz_tmp, 10, "%d", p_tag->tag() );                           \
372         vlc_meta_Set##meta( p_meta, psz_tmp );                                 \
373     }
374
375     SET( title, Title );
376     SET( artist, Artist );
377     SET( album, Album );
378     SET( comment, Description );
379     SET( genre, Genre );
380     SETINT( year, Date );
381     SETINT( track, TrackNum );
382
383 #undef SETINT
384 #undef SET
385
386
387     // Try now to read special tags
388     if( FLAC::File* flac = dynamic_cast<FLAC::File*>(f.file()) )
389     {
390         if( flac->ID3v2Tag() )
391             ReadMetaFromId3v2( flac->ID3v2Tag(), p_demux, p_demux_meta, p_meta );
392         else if( flac->xiphComment() )
393             ReadMetaFromXiph( flac->xiphComment(), p_demux, p_demux_meta, p_meta );
394     }
395     else if( MPC::File* mpc = dynamic_cast<MPC::File*>(f.file()) )
396     {
397         if( mpc->APETag() )
398             ReadMetaFromAPE( mpc->APETag(), p_demux, p_demux_meta, p_meta );
399     }
400     else if( MPEG::File* mpeg = dynamic_cast<MPEG::File*>(f.file()) )
401     {
402         if( mpeg->ID3v2Tag() )
403             ReadMetaFromId3v2( mpeg->ID3v2Tag(), p_demux, p_demux_meta, p_meta );
404         else if( mpeg->APETag() )
405             ReadMetaFromAPE( mpeg->APETag(), p_demux, p_demux_meta, p_meta );
406     }
407     else if( Ogg::File* ogg = dynamic_cast<Ogg::File*>(f.file()) )
408     {
409         if( Ogg::FLAC::File* ogg_flac = dynamic_cast<Ogg::FLAC::File*>(f.file()))
410             ReadMetaFromXiph( ogg_flac->tag(), p_demux, p_demux_meta, p_meta );
411         else if( Ogg::Speex::File* ogg_speex = dynamic_cast<Ogg::Speex::File*>(f.file()) )
412             ReadMetaFromXiph( ogg_speex->tag(), p_demux, p_demux_meta, p_meta );
413         else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
414             ReadMetaFromXiph( ogg_vorbis->tag(), p_demux, p_demux_meta, p_meta );
415     }
416 #ifdef TAGLIB_WITH_ASF
417     else if( RIFF::File* riff = dynamic_cast<RIFF::File*>(f.file()) )
418     {
419         if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
420             ReadMetaFromId3v2( riff_aiff->tag(), p_demux, p_demux_meta, p_meta );
421         else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
422             ReadMetaFromId3v2( riff_wav->tag(), p_demux, p_demux_meta, p_meta );
423     }
424 #endif
425     else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
426     {
427         if( trueaudio->ID3v2Tag() )
428             ReadMetaFromId3v2( trueaudio->ID3v2Tag(), p_demux, p_demux_meta, p_meta );
429     }
430     else if( WavPack::File* wavpack = dynamic_cast<WavPack::File*>(f.file()) )
431     {
432         if( wavpack->APETag() )
433             ReadMetaFromAPE( wavpack->APETag(), p_demux, p_demux_meta, p_meta );
434     }
435
436     return VLC_SUCCESS;
437 }
438
439
440
441 /**
442  * Write meta informations to APE tags
443  * @param tag: the APE tag
444  * @param p_item: the input item
445  */
446 static void WriteMetaToAPE( APE::Tag* tag, input_item_t* p_item )
447 {
448     char* psz_meta;
449 #define WRITE( metaName, keyName )                      \
450     psz_meta = input_item_Get##metaName( p_item );      \
451     if( psz_meta )                                      \
452     {                                                   \
453         String key( keyName, String::UTF8 );            \
454         String value( psz_meta, String::UTF8 );         \
455         tag->addValue( key, value, true );              \
456     }                                                   \
457     free( psz_meta );
458
459     WRITE( Copyright, "COPYRIGHT" );
460     WRITE( Language, "LANGUAGE" );
461     WRITE( Publisher, "PUBLISHER" );
462
463 #undef WRITE
464 }
465
466
467
468 /**
469  * Write meta information to id3v2 tags
470  * @param tag: the id3v2 tag
471  * @param p_input: the input item
472  */
473 static void WriteMetaToId3v2( ID3v2::Tag* tag, input_item_t* p_item )
474 {
475     char* psz_meta;
476 #define WRITE( metaName, tagName )                                            \
477     psz_meta = input_item_Get##metaName( p_item );                            \
478     if( psz_meta )                                                            \
479     {                                                                         \
480         ByteVector p_byte( tagName, 4 );                                      \
481         tag->removeFrames( p_byte );                                         \
482         ID3v2::TextIdentificationFrame* p_frame =                             \
483             new ID3v2::TextIdentificationFrame( p_byte, String::UTF8 );       \
484         p_frame->setText( psz_meta );                                         \
485         tag->addFrame( p_frame );                                             \
486     }                                                                         \
487     free( psz_meta );
488
489     WRITE( Copyright, "TCOP" );
490     WRITE( EncodedBy, "TENC" );
491     WRITE( Language,  "TLAN" );
492     WRITE( Publisher, "TPUB" );
493
494 #undef WRITE
495 }
496
497
498
499 /**
500  * Write the meta informations to XiphComments
501  * @param tag: the Xiph Comment
502  * @param p_input: the input item
503  */
504 static void WriteMetaToXiph( Ogg::XiphComment* tag, input_item_t* p_item )
505 {
506     char* psz_meta;
507 #define WRITE( metaName, keyName )                      \
508     psz_meta = input_item_Get##metaName( p_item );      \
509     if( psz_meta )                                      \
510     {                                                   \
511         String key( keyName, String::UTF8 );            \
512         String value( psz_meta, String::UTF8 );         \
513         tag->addField( key, value, true );              \
514     }                                                   \
515     free( psz_meta );
516
517     WRITE( Copyright, "COPYRIGHT" );
518
519 #undef WRITE
520 }
521
522
523
524 /**
525  * Set the tags to the file using TagLib
526  * @param p_this: the demux object
527  * @return VLC_SUCCESS if the operation success
528  */
529
530 static int WriteMeta( vlc_object_t *p_this )
531 {
532     meta_export_t *p_export = (meta_export_t *)p_this;
533     input_item_t *p_item = p_export->p_item;
534     FileRef f;
535
536     if( !p_item )
537     {
538         msg_Err( p_this, "Can't save meta data of an empty input" );
539         return VLC_EGENERIC;
540     }
541
542     char *export_file = decode_URI_duplicate(p_export->psz_file);
543     if( export_file == NULL )
544         return VLC_EGENERIC;
545
546 #if defined(WIN32) || defined (UNDER_CE)
547     wchar_t wpath[MAX_PATH + 1];
548     if( !MultiByteToWideChar( CP_UTF8, 0, export_file , -1, wpath, MAX_PATH) )
549         return VLC_EGENERIC;
550     wpath[MAX_PATH] = L'\0';
551     f = FileRef( wpath );
552 #else
553     const char* local_name = ToLocale( export_file );
554     if( !local_name )
555     {
556         free( export_file );
557         return VLC_EGENERIC;
558     }
559     f = FileRef( local_name );
560     LocaleFree( local_name );
561 #endif
562
563     if( f.isNull() || !f.tag() || f.file()->readOnly() )
564     {
565         msg_Err( p_this, "File %s can't be opened for tag writing",
566             export_file );
567         free( export_file );
568         return VLC_EGENERIC;
569     }
570
571     msg_Dbg( p_this, "Writing metadata for %s", export_file );
572     free( export_file );
573
574     Tag *p_tag = f.tag();
575
576     char *psz_meta;
577
578 #define SET( a, b )                                             \
579     psz_meta = input_item_Get ## a( p_item );                   \
580     if( psz_meta )                                              \
581     {                                                           \
582         String tmp( psz_meta, String::UTF8 );                   \
583         p_tag->set##b( tmp );                                   \
584     }                                                           \
585     free( psz_meta );
586
587     // Saving all common fields
588     // If the title is empty, use the name
589     SET( TitleFbName, Title );
590     SET( Artist, Artist );
591     SET( Album, Album );
592     SET( Description, Comment );
593     SET( Genre, Genre );
594
595 #undef SET
596
597     psz_meta = input_item_GetDate( p_item );
598     if( psz_meta ) p_tag->setYear( atoi( psz_meta ) );
599     free( psz_meta );
600
601     psz_meta = input_item_GetTrackNum( p_item );
602     if( psz_meta ) p_tag->setTrack( atoi( psz_meta ) );
603     free( psz_meta );
604
605
606     // Try now to write special tags
607     if( FLAC::File* flac = dynamic_cast<FLAC::File*>(f.file()) )
608     {
609         if( flac->ID3v2Tag() )
610             WriteMetaToId3v2( flac->ID3v2Tag(), p_item );
611         else if( flac->xiphComment() )
612             WriteMetaToXiph( flac->xiphComment(), p_item );
613     }
614     else if( MPC::File* mpc = dynamic_cast<MPC::File*>(f.file()) )
615     {
616         if( mpc->APETag() )
617             WriteMetaToAPE( mpc->APETag(), p_item );
618     }
619     else if( MPEG::File* mpeg = dynamic_cast<MPEG::File*>(f.file()) )
620     {
621         if( mpeg->ID3v2Tag() )
622             WriteMetaToId3v2( mpeg->ID3v2Tag(), p_item );
623         else if( mpeg->APETag() )
624             WriteMetaToAPE( mpeg->APETag(), p_item );
625     }
626     else if( Ogg::File* ogg = dynamic_cast<Ogg::File*>(f.file()) )
627     {
628         if( Ogg::FLAC::File* ogg_flac = dynamic_cast<Ogg::FLAC::File*>(f.file()))
629             WriteMetaToXiph( ogg_flac->tag(), p_item );
630         else if( Ogg::Speex::File* ogg_speex = dynamic_cast<Ogg::Speex::File*>(f.file()) )
631             WriteMetaToXiph( ogg_speex->tag(), p_item );
632         else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
633             WriteMetaToXiph( ogg_vorbis->tag(), p_item );
634     }
635 #ifdef TAGLIB_WITH_ASF
636     else if( RIFF::File* riff = dynamic_cast<RIFF::File*>(f.file()) )
637     {
638         if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
639             WriteMetaToId3v2( riff_aiff->tag(), p_item );
640         else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
641             WriteMetaToId3v2( riff_wav->tag(), p_item );
642     }
643 #endif
644     else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
645     {
646         if( trueaudio->ID3v2Tag() )
647             WriteMetaToId3v2( trueaudio->ID3v2Tag(), p_item );
648     }
649     else if( WavPack::File* wavpack = dynamic_cast<WavPack::File*>(f.file()) )
650     {
651         if( wavpack->APETag() )
652             WriteMetaToAPE( wavpack->APETag(), p_item );
653     }
654
655     // Save the meta data
656     f.save();
657
658     return VLC_SUCCESS;
659 }
660