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