2015-07-12 100 views
2

我是一個古典音樂迷。我的音樂收藏(mp3)已經使用「composer」(例如「Surname name(DOB-DOD)」)進行了仔細的分類,我經常從導入音樂,抓取或在線數據庫中獲得「藝術家」,因爲我的手機音樂玩家(Xbox)只能通過「藝術家」訂購,我想要「交換」: album_artist =藝術家 藝術家=作曲家 和作曲家只是保持不變(和藝術家一樣)(Visual Studio 2013,W7,taglib1 .9.1):taglib,C++,tags tags

TagLib::PropertyMap tags = f.file()->properties(); 

unsigned int longest = 0; 
for (TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { 
    if (i->first.size() > longest) { 
     longest = i->first.size(); 
    } 
} 

cout << "-- TAG (properties) --" << endl; 

for (TagLib::PropertyMap::Iterator i = tags.begin(); i != tags.end(); ++i) { 
    if (i->first == "COMPOSER") { 
     composer = i->second; 
     composer_key = i->first; 
    } 
    if (i->first == "ARTIST") { 
     artist.append(i->second); 
     artist_key = i->first; 
    } 
    if (i->first == "ALBUMARTIST") { 
     album_artist.append(i->second); 
     album_artist_key = i->first; 
    } 
    cout << left << std::setw(longest) << i->first << " - " << '"' << i->second << '"' << endl; 
} 

if (!tags.replace(album_artist_key, artist)) 
    cout << "album_artist_key is wrong"; 
else 
    cout << "replacing " << album_artist_key << " with " << artist << endl; 

if (!tags.replace(artist_key, composer)) 
    cout << "artist is wrong"; 
else 
    cout << "replacing " << artist_key << " with " << composer << endl; 
tag->setArtist(composer.toString()); 
f.save(); 

注:此代碼被修改從庫中的實例中發現的tagreader.cpp代碼開始 這將編譯,但在運行後,所有的ID3標籤信息消失(貪污),作爲?由Windows資源管理器看到,所以我做了一個實驗並評論了所有對標籤進行更改的內容。基本上,只需打開文件(FileRef)並執行f.save()即可。這僅僅導致標籤消失。 兩個問題(我認爲我完全錯了......)

  1. f.save會導致元數據損壞的任何原因?
  2. 我正在遵循的想法(tags.replace和f.save)是否正確?

回答

0

這不是腐敗; Windows資源管理器只是仍然無法讀取ID3v2.4標籤,這是15年前發佈的標準,並且是TagLib中的默認標籤。然而,TagLib也可以編寫ID3v2.3標籤。