vlc_linux/vlc-3.0.16/modules/meta_engine/taglib.cpp
/**
 * Set the tags to the file using TagLib
 * @param p_this: the demux object
 * @return VLC_SUCCESS if the operation success
 */
Set the tags to the file using TagLib
@param p_this: the demux object
@return VLC_SUCCESS if the operation 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 )
{
    vlc_mutex_locker locker (&taglib_lock);
    meta_export_t *p_export = (meta_export_t *)p_this;
    input_item_t *p_item = p_export->p_item;
    FileRef f;
    if( !p_item )
    {
        msg_Err( p_this, "Can't save meta data of an empty input" );
        return VLC_EGENERIC;
    }
#if defined(_WIN32)
    wchar_t *wpath = ToWide( p_export->psz_file );
    if( wpath == NULL )
        return VLC_EGENERIC;
    f = FileRef( wpath, false );
    free( wpath );
#else
    f = FileRef( p_export->psz_file, false );
#endif
    if( f.isNull() || !f.tag() || f.file()->readOnly() )
    {
        msg_Err( p_this, "File %s can't be opened for tag writing",
                 p_export->psz_file );
        return VLC_EGENERIC;
    }
    msg_Dbg( p_this, "Writing metadata for %s", p_export->psz_file );
    Tag *p_tag = f.tag();
    char *psz_meta;
#define SET( a, b )                                             \
    psz_meta = input_item_Get ## a( p_item );                   \
    if( psz_meta )                                              \
    {                                                           \
        String tmp( psz_meta, String::UTF8 );                   \
        p_tag->set##b( tmp );                                   \
    }                                                           \
    free( psz_meta );
    SET( TitleFbName, Title );
    SET( Artist, Artist );
    SET( Album, Album );
    SET( Description, Comment );
    SET( Genre, Genre );
#undef SET
    psz_meta = input_item_GetDate( p_item );
    if( !EMPTY_STR(psz_meta) ) p_tag->setYear( atoi( psz_meta ) );
    else p_tag->setYear( 0 );
    free( psz_meta );
    psz_meta = input_item_GetTrackNum( p_item );
    if( !EMPTY_STR(psz_meta) ) p_tag->setTrack( atoi( psz_meta ) );
    else p_tag->setTrack( 0 );
    free( psz_meta );
    if( APE::File* ape = dynamic_cast<APE::File*>(f.file()) )
    {
        if( ape->APETag() )
            WriteMetaToAPE( ape->APETag(), p_item );
    }
    else
    if( FLAC::File* flac = dynamic_cast<FLAC::File*>(f.file()) )
    {
        if( flac->ID3v2Tag() )
            WriteMetaToId3v2( 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() )
            WriteMetaToId3v2( mpeg->ID3v2Tag(), p_item );
        else if( mpeg->APETag() )
            WriteMetaToAPE( mpeg->APETag(), p_item );
    }
    else if( 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 );
#if defined(TAGLIB_OPUSFILE_H)
        else if( Ogg::Opus::File* ogg_opus = dynamic_cast<Ogg::Opus::File*>(f.file()) )
            WriteMetaToXiph( ogg_opus->tag(), p_item );
#endif
    }
    else if( dynamic_cast<RIFF::File*>(f.file()) )
    {
        if( RIFF::AIFF::File* riff_aiff = dynamic_cast<RIFF::AIFF::File*>(f.file()) )
            WriteMetaToId3v2( riff_aiff->tag(), p_item );
        else if( RIFF::WAV::File* riff_wav = dynamic_cast<RIFF::WAV::File*>(f.file()) )
            WriteMetaToId3v2( riff_wav->tag(), p_item );
    }
    else if( TrueAudio::File* trueaudio = dynamic_cast<TrueAudio::File*>(f.file()) )
    {
        if( trueaudio->ID3v2Tag() )
            WriteMetaToId3v2( trueaudio->ID3v2Tag(), p_item );
    }
    else if( WavPack::File* wavpack = dynamic_cast<WavPack::File*>(f.file()) )
    {
        if( wavpack->APETag() )
            WriteMetaToAPE( wavpack->APETag(), p_item );
    }
    f.save();
    return VLC_SUCCESS;
}
static int WriteMeta ( vlc_object_t * p_this ) { vlc_mutex_locker locker ( & taglib_lock ) ; meta_export_t * p_export = ( meta_export_t * ) p_this ; input_item_t * p_item = p_export -> p_item ; FileRef f ; if ( ! p_item ) { msg_Err ( p_this , " " ) ; return VLC_EGENERIC ; } #if defined ( _WIN32 ) wchar_t * wpath = ToWide ( p_export -> psz_file ) ; if ( wpath == NULL ) return VLC_EGENERIC ; f = FileRef ( wpath , false ) ; free ( wpath ) ; #else f = FileRef ( p_export -> psz_file , false ) ; #endif if ( f . isNull ( ) || ! f . tag ( ) || f . file ( ) -> readOnly ( ) ) { msg_Err ( p_this , " " , p_export -> psz_file ) ; return VLC_EGENERIC ; } msg_Dbg ( p_this , " " , p_export -> psz_file ) ; Tag * p_tag = f . tag ( ) ; char * psz_meta ; #define SET ( a , b )                                              \
    psz_meta = input_item_Get ## a( p_item );                   \
    if( psz_meta )                                              \
    {                                                           \
        String tmp( psz_meta, String::UTF8 );                   \
        p_tag->set##b( tmp );                                   \
    }                                                           \
    free( psz_meta ); SET ( TitleFbName , Title ) ; SET ( Artist , Artist ) ; SET ( Album , Album ) ; SET ( Description , Comment ) ; SET ( Genre , Genre ) ; #undef  SET psz_meta = input_item_GetDate ( p_item ) ; if ( ! EMPTY_STR ( psz_meta ) ) p_tag -> setYear ( atoi ( psz_meta ) ) ; else p_tag -> setYear ( 0 ) ; free ( psz_meta ) ; psz_meta = input_item_GetTrackNum ( p_item ) ; if ( ! EMPTY_STR ( psz_meta ) ) p_tag -> setTrack ( atoi ( psz_meta ) ) ; else p_tag -> setTrack ( 0 ) ; free ( psz_meta ) ; if ( APE :: File * ape = dynamic_cast < APE :: File * > ( f . file ( ) ) ) { if ( ape -> APETag ( ) ) WriteMetaToAPE ( ape -> APETag ( ) , p_item ) ; } else if ( FLAC :: File * flac = dynamic_cast < FLAC :: File * > ( f . file ( ) ) ) { if ( flac -> ID3v2Tag ( ) ) WriteMetaToId3v2 ( 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 ( ) ) WriteMetaToId3v2 ( mpeg -> ID3v2Tag ( ) , p_item ) ; else if ( mpeg -> APETag ( ) ) WriteMetaToAPE ( mpeg -> APETag ( ) , p_item ) ; } else if ( 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 ) ; #if defined ( TAGLIB_OPUSFILE_H ) else if ( Ogg :: Opus :: File * ogg_opus = dynamic_cast < Ogg :: Opus :: File * > ( f . file ( ) ) ) WriteMetaToXiph ( ogg_opus -> tag ( ) , p_item ) ; #endif } else if ( dynamic_cast < RIFF :: File * > ( f . file ( ) ) ) { if ( RIFF :: AIFF :: File * riff_aiff = dynamic_cast < RIFF :: AIFF :: File * > ( f . file ( ) ) ) WriteMetaToId3v2 ( riff_aiff -> tag ( ) , p_item ) ; else if ( RIFF :: WAV :: File * riff_wav = dynamic_cast < RIFF :: WAV :: File * > ( f . file ( ) ) ) WriteMetaToId3v2 ( riff_wav -> tag ( ) , p_item ) ; } else if ( TrueAudio :: File * trueaudio = dynamic_cast < TrueAudio :: File * > ( f . file ( ) ) ) { if ( trueaudio -> ID3v2Tag ( ) ) WriteMetaToId3v2 ( trueaudio -> ID3v2Tag ( ) , p_item ) ; } else if ( WavPack :: File * wavpack = dynamic_cast < WavPack :: File * > ( f . file ( ) ) ) { if ( wavpack -> APETag ( ) ) WriteMetaToAPE ( wavpack -> APETag ( ) , p_item ) ; } f . save ( ) ; return VLC_SUCCESS ; }
Set the tags to the file using TagLib
 @param p_this: the demux object
 @return VLC_SUCCESS if the operation success
Set the tags to the file using TagLib @param p_this : the demux object @return VLC_SUCCESS if the operation success
// Saving all common fields // If the title is empty, use the name // Try now to write special tags // Save the meta data