2015-07-12 96 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标签。