*
* Authors: Clément Stenac <zorglub@videolan.org>
* Rafaël Carré <funman@videolanorg>
+ * Rémi Duraffort <ivoire@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
# include <unistd.h>
#endif
-#include <fileref.h>
+// Taglib headers
+#include <fileref.h>
#include <tag.h>
+#include <tbytevector.h>
+
+#include <apetag.h>
#include <id3v2tag.h>
#include <xiphcomment.h>
-#include <apetag.h>
#include <flacfile.h>
#include <mpcfile.h>
#include <oggfile.h>
#include <oggflacfile.h>
#include <speexfile.h>
-#include <vorbisfile.h>
#include <trueaudiofile.h>
+#include <vorbisfile.h>
#include <wavpackfile.h>
-#include <tstring.h>
-#include <textidentificationframe.h>
-#include <tbytevector.h>
#include <attachedpictureframe.h>
-//#include <oggflacfile.h> /* ogg flac files aren't auto-casted by TagLib */
-#include <flacproperties.h>
-#include <vorbisfile.h>
-#include <vorbisproperties.h>
-#include <uniquefileidentifierframe.h>
#include <textidentificationframe.h>
-//#include <relativevolumeframe.h> /* parse the tags without TagLib helpers? */
+#include <uniquefileidentifierframe.h>
+
-static int ReadMeta ( vlc_object_t * );
-static int DownloadArt ( vlc_object_t * );
-static int WriteMeta ( vlc_object_t * );
+// Local functions
+static int ReadMeta ( vlc_object_t * );
+static int DownloadArt ( vlc_object_t * );
+static int WriteMeta ( vlc_object_t * );
vlc_module_begin ()
set_capability( "meta reader", 1000 )
using namespace TagLib;
-
/* Try detecting embedded art */
static void DetectImage( FileRef f, demux_t *p_demux )
{
/**
- * read meta information from id3v2 tags
+ * Read meta information from id3v2 tags
* @param tag: the id3v2 tag
* @param p_meta: the meta
* @return VLC_SUCCESS if everything goes ok
* terminated string */
char psz_ufid[64];
int j = 0;
- while( ( j < 63 ) &&
- ( j < p_ufid->identifier().size() ) )
+ int max_size = p_ufid->identifier().size() < 63 ?
+ p_ufid->identifier().size() : 63;
+ while( j < max_size )
psz_ufid[j] = p_ufid->identifier()[j++];
psz_ufid[j] = '\0';
vlc_meta_SetTrackID( p_meta, psz_ufid );
*/
static int ReadMetaFromXiph( Ogg::XiphComment* tag, vlc_meta_t* p_meta )
{
+#define SET( metaName, keyName ) \
+ StringList list = tag->fieldListMap()[keyName]; \
+ if( !list.isEmpty() ) \
+ vlc_meta_Set##metaName( p_meta, (*list.begin()).toCString( true ) );
+
+ SET( Copyright, "COPYRIGHT" );
+#undef SET
return VLC_SUCCESS;
}
}
+
+/**
+ * Write meta informations to APE tags
+ * @param tag: the APE tag
+ * @param p_input: the input item
+ * @return VLC_SUCCESS if everything goes ok
+ */
+static int WriteMetaToAPE( APE::Tag* tag, input_item_t* p_input )
+{
+ return VLC_SUCCESS;
+}
+
+
+
+/**
+ * Write meta information to id3v2 tags
+ * @param tag: the id3v2 tag
+ * @param p_input: the input item
+ * @return VLC_SUCCESS if everything goes ok
+ */
+static int WriteMetaToId2v2( ID3v2::Tag* tag, input_item_t* p_item )
+{
+ char* psz_meta;
+#define WRITE( metaName, tagName ) \
+ psz_meta = input_item_Get##metaName( p_item ); \
+ if( psz_meta ) \
+ { \
+ ByteVector p_byte( tagName, 4 ); \
+ tag->removeFrames( p_byte ); \
+ ID3v2::TextIdentificationFrame* p_frame = \
+ new ID3v2::TextIdentificationFrame( p_byte, String::UTF8 ); \
+ p_frame->setText( psz_meta ); \
+ tag->addFrame( p_frame ); \
+ } \
+ free( psz_meta );
+
+ WRITE( Copyright, "TCOP" );
+ WRITE( EncodedBy, "TENC" );
+ WRITE( Language, "TLAN" );
+ WRITE( Publisher, "TPUB" );
+
+#undef WRITE
+ return VLC_SUCCESS;
+}
+
+
+
+/**
+ * Write the meta informations to XiphComments
+ * @param tag: the Xiph Comment
+ * @param p_input: the input item
+ * @return VLC_SUCCESS if everything goes ok
+ */
+static int WriteMetaToXiph( Ogg::XiphComment* tag, input_item_t* p_item )
+{
+ char* psz_meta;
+#define WRITE( metaName, keyName ) \
+ psz_meta = input_item_Get##metaName( p_item ); \
+ if( psz_meta ) \
+ { \
+ String key( keyName, String::UTF8 ); \
+ String value( psz_meta, String::UTF8 ); \
+ tag->addField( key, value, true ); \
+ } \
+ free( psz_meta );
+
+ WRITE( Copyright, "COPYRIGHT" );
+
+#undef WRITE
+ return VLC_SUCCESS;
+}
+
+
+
+/**
+ * Set the tags to the file using TagLib
+ * @param p_this: the demux object
+ * @return VLC_SUCCESS if the operation success
+ */
+
static int WriteMeta( vlc_object_t *p_this )
{
playlist_t *p_playlist = (playlist_t *)p_this;
meta_export_t *p_export = (meta_export_t *)p_playlist->p_private;
input_item_t *p_item = p_export->p_item;
- if( p_item == NULL )
+ if( !p_item )
{
msg_Err( p_this, "Can't save meta data of an empty input" );
return VLC_EGENERIC;
char *psz_meta;
-#define SET(a,b) \
- if(b) { \
- String *psz_##a = new String( b, \
- String::UTF8 ); \
- p_tag->set##a( *psz_##a ); \
- delete psz_##a; \
- }
+#define SET( a, b ) \
+ if( b ) \
+ { \
+ String* psz_tmp = new String( b, String::UTF8 ); \
+ p_tag->set##a( *psz_tmp ); \
+ delete psz_tmp; \
+ }
+ // Saving all common fields
+ // If the title is empty, use the name
+ psz_meta = input_item_GetTitle( p_item );
+ if( !psz_meta ) psz_meta = input_item_GetName( p_item );
+ SET( Title, psz_meta );
+ free( psz_meta );
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 );
- String *psz_title = new String( psz_meta,
- 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_GetDescription( p_item );
+ SET( Comment, psz_meta );
+ free( psz_meta );
+
psz_meta = input_item_GetGenre( p_item );
SET( Genre, psz_meta );
free( psz_meta );
if( psz_meta ) p_tag->setTrack( atoi( psz_meta ) );
free( psz_meta );
- if( ID3v2::Tag *p_id3tag =
- dynamic_cast<ID3v2::Tag *>(p_tag) )
- {
-#define WRITE( foo, bar ) \
- psz_meta = input_item_Get##foo( p_item ); \
- if( psz_meta ) \
- { \
- ByteVector p_byte( bar, 4 ); \
- 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
+ // Try now to write special tags
+ if( FLAC::File* flac = dynamic_cast<FLAC::File*>(f.file()) )
+ {
+ if( flac->ID3v2Tag() )
+ WriteMetaToId2v2( flac->ID3v2Tag(), p_item );
+ else if( flac->xiphComment() )
+ WriteMetaToXiph( flac->xiphComment(), p_item );
+ }
+ else if( MPC::File* mpc = dynamic_cast<MPC::File*>(f.file()) )
+ {
+ if( mpc->APETag() )
+ WriteMetaToAPE( mpc->APETag(), p_item );
+ }
+ else if( MPEG::File* mpeg = dynamic_cast<MPEG::File*>(f.file()) )
+ {
+ if( mpeg->ID3v2Tag() )
+ WriteMetaToId2v2( mpeg->ID3v2Tag(), p_item );
+ else if( mpeg->APETag() )
+ WriteMetaToAPE( mpeg->APETag(), p_item );
+ }
+ else if( Ogg::File* ogg = dynamic_cast<Ogg::File*>(f.file()) )
+ {
+ if( Ogg::FLAC::File* ogg_flac = dynamic_cast<Ogg::FLAC::File*>(f.file()))
+ WriteMetaToXiph( ogg_flac->tag(), p_item );
+ else if( Ogg::Speex::File* ogg_speex = dynamic_cast<Ogg::Speex::File*>(f.file()) )
+ WriteMetaToXiph( ogg_speex->tag(), p_item );
+ else if( Ogg::Vorbis::File* ogg_vorbis = dynamic_cast<Ogg::Vorbis::File*>(f.file()) )
+ WriteMetaToXiph( ogg_vorbis->tag(), p_item );
+ }
+ else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
+ {
+ if( trueaudio->ID3v2Tag() )
+ WriteMetaToId2v2( trueaudio->ID3v2Tag(), p_item );
+ }
+ else if( WavPack::File* wavpack = dynamic_cast<WavPack::File*>(f.file()) )
+ {
+ if( wavpack->APETag() )
+ WriteMetaToAPE( wavpack->APETag(), p_item );
}
+ // Save the meta data
f.save();
+
return VLC_SUCCESS;
}
+
+
static int DownloadArt( vlc_object_t *p_this )
{
/* We need to be passed the file name