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