Changeset 9af6b8bc8db835166ad386934c536db7928c089a

Show
Ignore:
Timestamp:
20/08/07 23:54:24 (1 year ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1187646864 +0000
git-parent:

[46cfe47bb41aacaf84fab5d1cb2b73cc83e0347d]

git-author:
Rafaël Carré <funman@videolan.org> 1187646864 +0000
Message:

Adds some metadata writing capability (ref #1248 )

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/meta_engine/taglib.cpp

    ra1c8d9c r9af6b8b  
    66 * 
    77 * Authors: Clément Stenac <zorglub@videolan.org> 
     8 *          Rafaël Carré <funman@videolanorg> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    3132#include <tstring.h> 
    3233#include <id3v2tag.h> 
     34#include <textidentificationframe.h> 
     35#include <tbytevector.h> 
    3336#include <mpegfile.h> 
    3437#include <flacfile.h> 
     
    6164vlc_module_end(); 
    6265 
    63 static bool checkID3Image( const TagLib::ID3v2::Tag *tag ) 
    64 { 
    65     TagLib::ID3v2::FrameList l = tag->frameListMap()[ "APIC" ]; 
     66static bool checkID3Image( const TagLib::ID3v2::Tag *p_tag ) 
     67{ 
     68    TagLib::ID3v2::FrameList l = p_tag->frameListMap()[ "APIC" ]; 
    6669    return !l.isEmpty(); 
    6770} 
     
    112115        p_demux->p_private = (void*)vlc_meta_New(); 
    113116    vlc_meta_t *p_meta = (vlc_meta_t *)(p_demux->p_private ); 
    114     TagLib::Tag *tag = f.tag(); 
     117    TagLib::Tag *p_tag = f.tag(); 
    115118 
    116119    if( TagLib::MPEG::File *p_mpeg = 
     
    119122        if( p_mpeg->ID3v2Tag() ) 
    120123        { 
    121             TagLib::ID3v2::Tag *tag = p_mpeg->ID3v2Tag(); 
    122             TagLib::ID3v2::FrameList list = tag->frameListMap()["UFID"]; 
     124            TagLib::ID3v2::Tag *p_tag = p_mpeg->ID3v2Tag(); 
     125            TagLib::ID3v2::FrameList list = p_tag->frameListMap()["UFID"]; 
    123126            TagLib::ID3v2::UniqueFileIdentifierFrame* p_ufid; 
    124127            for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); 
     
    143146            } 
    144147 
    145             list = tag->frameListMap()["TXXX"]; 
     148            list = p_tag->frameListMap()["TXXX"]; 
    146149            TagLib::ID3v2::UserTextIdentificationFrame* p_txxx; 
    147150            for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); 
     
    150153                p_txxx = dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>(*iter); 
    151154                const char *psz_desc= p_txxx->description().toCString(); 
    152 #if 0 /* musicbrainz artist and album id: not useful (yet?) */ 
    153                 if( !strncmp( psz_desc, "MusicBrainz Artist Id", 21 ) ) 
    154                     vlc_meta_SetArtistID( p_meta, 
    155                             p_txxx->fieldList().toString().toCString()); 
    156                 if( !strncmp( psz_desc, "MusicBrainz Album Id", 20 ) ) 
    157                     vlc_meta_SetAlbumID( p_meta, 
    158                             p_txxx->fieldList().toString().toCString()); 
    159 #endif 
    160155                vlc_meta_AddExtra( p_meta, psz_desc,  
    161156                            p_txxx->fieldList().toString().toCString()); 
    162157            } 
    163158#if 0 
    164             list = tag->frameListMap()["RVA2"]; 
     159            list = p_tag->frameListMap()["RVA2"]; 
    165160            TagLib::ID3v2::RelativeVolumeFrame* p_rva2; 
    166161            for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); 
     
    171166            } 
    172167#endif 
    173             list = tag->frameList(); 
     168            list = p_tag->frameList(); 
    174169            TagLib::ID3v2::Frame* p_t; 
    175170            char psz_tag[4]; 
     
    258253    } 
    259254 
    260 #define SET( foo, bar ) vlc_meta_Set##foo( p_meta, tag->bar ().toCString(true)) 
     255#define SET( foo, bar ) vlc_meta_Set##foo( p_meta, p_tag->bar ().toCString(true)) 
    261256#define SETINT( foo, bar ) { \ 
    262     char psz_tmp[10]; \ 
    263     snprintf( (char*)psz_tmp, 10, "%d", tag->bar() ); \ 
    264     vlc_meta_Set##foo( p_meta, (char*)psz_tmp ); \ 
    265 
     257        char psz_tmp[10]; \ 
     258        snprintf( (char*)psz_tmp, 10, "%d", p_tag->bar() ); \ 
     259        vlc_meta_Set##foo( p_meta, (char*)psz_tmp ); \ 
     260   
    266261 
    267262    SET( Title, title ); 
     
    280275} 
    281276 
    282 #define SET(a,b) if(b) { \ 
    283         TagLib::String *psz_##a = new TagLib::String( b, \ 
    284             TagLib::String::UTF8 ); \ 
    285         tag->set##a( *psz_##a ); \ 
    286         delete psz_##a; \ 
    287     } 
    288  
    289277static int WriteMeta( vlc_object_t *p_this ) 
    290278{ 
     
    300288 
    301289    TagLib::FileRef f( p_export->psz_file ); 
    302     if( !f.isNull() && f.tag() ) 
    303     { 
    304         msg_Dbg( p_this, "Updating metadata for %s", p_export->psz_file ); 
    305  
    306         TagLib::Tag *tag = f.tag(); 
    307  
    308         char *psz_meta; 
    309  
    310         psz_meta = input_item_GetArtist( p_item ); 
    311         SET( Artist, psz_meta ); 
    312         free( psz_meta ); 
    313  
    314         psz_meta = input_item_GetTitle( p_item ); 
    315         if( !psz_meta ) psz_meta = input_item_GetName( p_item ); 
    316         TagLib::String *psz_title = new TagLib::String( psz_meta, 
    317             TagLib::String::UTF8 ); 
    318         tag->setTitle( *psz_title ); 
    319         delete psz_title; 
    320         free( psz_meta ); 
    321  
    322         psz_meta = input_item_GetAlbum( p_item ); 
    323         SET( Album, psz_meta ); 
    324         free( psz_meta ); 
    325  
    326         psz_meta = input_item_GetGenre( p_item ); 
    327         SET( Genre, psz_meta ); 
    328         free( psz_meta ); 
    329  
    330         psz_meta = input_item_GetDate( p_item ); 
    331         if( psz_meta ) tag->setYear( atoi( psz_meta ) ); 
    332         free( psz_meta ); 
    333  
    334         psz_meta = input_item_GetTrackNum( p_item ); 
    335         if( psz_meta ) tag->setTrack( atoi( psz_meta ) ); 
    336         free( psz_meta ); 
    337  
    338         f.save(); 
    339         return VLC_SUCCESS; 
    340     } 
    341     msg_Err( p_this, "File %s can't be opened for tag writing\n", 
    342         p_export->psz_file ); 
    343     return VLC_EGENERIC; 
     290    if( f.isNull() || !f.tag() || f.file()->readOnly() ) 
     291    { 
     292        msg_Err( p_this, "File %s can't be opened for tag writing\n", 
     293            p_export->psz_file ); 
     294        return VLC_EGENERIC; 
     295    } 
     296 
     297    msg_Dbg( p_this, "Writing metadata for %s", p_export->psz_file ); 
     298 
     299    TagLib::Tag *p_tag = f.tag(); 
     300 
     301    char *psz_meta; 
     302 
     303#define SET(a,b) \ 
     304        if(b) { \ 
     305            TagLib::String *psz_##a = new TagLib::String( b, \ 
     306                TagLib::String::UTF8 ); \ 
     307            p_tag->set##a( *psz_##a ); \ 
     308            delete psz_##a; \ 
     309        } 
     310 
     311 
     312    psz_meta = input_item_GetArtist( p_item ); 
     313    SET( Artist, psz_meta ); 
     314    free( psz_meta ); 
     315 
     316    psz_meta = input_item_GetTitle( p_item ); 
     317    if( !psz_meta ) psz_meta = input_item_GetName( p_item ); 
     318    TagLib::String *psz_title = new TagLib::String( psz_meta, 
     319        TagLib::String::UTF8 ); 
     320    p_tag->setTitle( *psz_title ); 
     321    delete psz_title; 
     322    free( psz_meta ); 
     323 
     324    psz_meta = input_item_GetAlbum( p_item ); 
     325    SET( Album, psz_meta ); 
     326    free( psz_meta ); 
     327 
     328    psz_meta = input_item_GetGenre( p_item ); 
     329    SET( Genre, psz_meta ); 
     330    free( psz_meta ); 
     331 
     332#undef SET 
     333 
     334    psz_meta = input_item_GetDate( p_item ); 
     335    if( psz_meta ) p_tag->setYear( atoi( psz_meta ) ); 
     336    free( psz_meta ); 
     337 
     338    psz_meta = input_item_GetTrackNum( p_item ); 
     339    if( psz_meta ) p_tag->setTrack( atoi( psz_meta ) ); 
     340    free( psz_meta ); 
     341 
     342    if( TagLib::ID3v2::Tag *p_id3tag = 
     343        dynamic_cast<TagLib::ID3v2::Tag *>(p_tag) ) 
     344    { 
     345#define WRITE( foo, bar ) \ 
     346        psz_meta = input_item_Get##foo( p_item ); \ 
     347        if( psz_meta ) \ 
     348        { \ 
     349            TagLib::ByteVector p_byte( bar, 4 ); \ 
     350            TagLib::ID3v2::TextIdentificationFrame p_frame( p_byte ); \ 
     351            p_frame.setText( psz_meta ); \ 
     352            p_id3tag->addFrame( &p_frame ); \ 
     353        } \ 
     354        else free( psz_meta ); 
     355 
     356        WRITE( Publisher, "TPUB" ); 
     357        WRITE( Copyright, "TCOP" ); 
     358        WRITE( EncodedBy, "TENC" ); 
     359        WRITE( Language, "TLAN" ); 
     360         
     361#undef WRITE 
     362    } 
     363 
     364    f.save(); 
     365    return VLC_SUCCESS; 
    344366} 
    345367 
     
    351373    return VLC_EGENERIC; 
    352374} 
     375