Changeset 9af6b8bc8db835166ad386934c536db7928c089a
- Timestamp:
- 20/08/07 23:54:24 (1 year ago)
- git-parent:
- Files:
-
- modules/meta_engine/taglib.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/meta_engine/taglib.cpp
ra1c8d9c r9af6b8b 6 6 * 7 7 * Authors: Clément Stenac <zorglub@videolan.org> 8 * Rafaël Carré <funman@videolanorg> 8 9 * 9 10 * This program is free software; you can redistribute it and/or modify … … 31 32 #include <tstring.h> 32 33 #include <id3v2tag.h> 34 #include <textidentificationframe.h> 35 #include <tbytevector.h> 33 36 #include <mpegfile.h> 34 37 #include <flacfile.h> … … 61 64 vlc_module_end(); 62 65 63 static bool checkID3Image( const TagLib::ID3v2::Tag * tag )64 { 65 TagLib::ID3v2::FrameList l = tag->frameListMap()[ "APIC" ];66 static bool checkID3Image( const TagLib::ID3v2::Tag *p_tag ) 67 { 68 TagLib::ID3v2::FrameList l = p_tag->frameListMap()[ "APIC" ]; 66 69 return !l.isEmpty(); 67 70 } … … 112 115 p_demux->p_private = (void*)vlc_meta_New(); 113 116 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(); 115 118 116 119 if( TagLib::MPEG::File *p_mpeg = … … 119 122 if( p_mpeg->ID3v2Tag() ) 120 123 { 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"]; 123 126 TagLib::ID3v2::UniqueFileIdentifierFrame* p_ufid; 124 127 for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); … … 143 146 } 144 147 145 list = tag->frameListMap()["TXXX"];148 list = p_tag->frameListMap()["TXXX"]; 146 149 TagLib::ID3v2::UserTextIdentificationFrame* p_txxx; 147 150 for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); … … 150 153 p_txxx = dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>(*iter); 151 154 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 #endif160 155 vlc_meta_AddExtra( p_meta, psz_desc, 161 156 p_txxx->fieldList().toString().toCString()); 162 157 } 163 158 #if 0 164 list = tag->frameListMap()["RVA2"];159 list = p_tag->frameListMap()["RVA2"]; 165 160 TagLib::ID3v2::RelativeVolumeFrame* p_rva2; 166 161 for( TagLib::ID3v2::FrameList::Iterator iter = list.begin(); … … 171 166 } 172 167 #endif 173 list = tag->frameList();168 list = p_tag->frameList(); 174 169 TagLib::ID3v2::Frame* p_t; 175 170 char psz_tag[4]; … … 258 253 } 259 254 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)) 261 256 #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 } 266 261 267 262 SET( Title, title ); … … 280 275 } 281 276 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 289 277 static int WriteMeta( vlc_object_t *p_this ) 290 278 { … … 300 288 301 289 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; 344 366 } 345 367 … … 351 373 return VLC_EGENERIC; 352 374 } 375
