+
+ msg_Dbg( p_this, "Writing metadata for %s", p_export->psz_file );
+
+ TagLib::Tag *p_tag = f.tag();
+
+ char *psz_meta;
+
+#define SET(a,b) \
+ if(b) { \
+ TagLib::String *psz_##a = new TagLib::String( b, \
+ TagLib::String::UTF8 ); \
+ p_tag->set##a( *psz_##a ); \
+ delete psz_##a; \
+ }
+
+
+ psz_meta = input_item_GetArtist( p_item );
+ SET( Artist, psz_meta );
+ free( psz_meta );
+
+ psz_meta = input_item_GetTitle( p_item );
+ if( !psz_meta ) psz_meta = input_item_GetName( p_item );
+ TagLib::String *psz_title = new TagLib::String( psz_meta,
+ TagLib::String::UTF8 );
+ p_tag->setTitle( *psz_title );
+ delete psz_title;
+ free( psz_meta );
+
+ psz_meta = input_item_GetAlbum( p_item );
+ SET( Album, psz_meta );
+ free( psz_meta );
+
+ psz_meta = input_item_GetGenre( p_item );
+ SET( Genre, psz_meta );
+ free( psz_meta );
+
+#undef SET
+
+ psz_meta = input_item_GetDate( p_item );
+ if( psz_meta ) p_tag->setYear( atoi( psz_meta ) );
+ free( psz_meta );
+
+ psz_meta = input_item_GetTrackNum( p_item );
+ if( psz_meta ) p_tag->setTrack( atoi( psz_meta ) );
+ free( psz_meta );
+
+ if( TagLib::ID3v2::Tag *p_id3tag =
+ dynamic_cast<TagLib::ID3v2::Tag *>(p_tag) )
+ {
+#define WRITE( foo, bar ) \
+ psz_meta = input_item_Get##foo( p_item ); \
+ if( psz_meta ) \
+ { \
+ TagLib::ByteVector p_byte( bar, 4 ); \
+ TagLib::ID3v2::TextIdentificationFrame p_frame( p_byte ); \
+ p_frame.setText( psz_meta ); \
+ p_id3tag->addFrame( &p_frame ); \
+ free( psz_meta ); \
+ } \
+
+ WRITE( Publisher, "TPUB" );
+ WRITE( Copyright, "TCOP" );
+ WRITE( EncodedBy, "TENC" );
+ WRITE( Language, "TLAN" );
+
+#undef WRITE
+ }
+
+ f.save();
+ return VLC_SUCCESS;