问题
How to modify the "Album Artist" field of a MP3 file with the library TagLib ? Is there something similar to :
f.tag()->setArtist("blabla");
?
回答1:
ID3v2 doesn't actually support a field called "album artist". iTunes uses the TPE2 frame, which is supposed to be:
TPE2
The 'Band/Orchestra/Accompaniment' frame is used for additional information about the performers in the recording.
For a complete list of frames see http://id3.org/id3v2.3.0#Declared_ID3v2_frames.
To write that with TagLib, this would do the trick:
#include <mpegfile.h>
#include <id3v2tag.h>
#include <textidentificationframe.h>
int main()
{
TagLib::MPEG::File file("foo.mp3");
TagLib::ByteVector handle = "TPE2";
TagLib::String value = "bar";
TagLib::ID3v2::Tag *tag = file.ID3v2Tag(true);
if(!tag->frameList(handle).isEmpty())
{
tag->frameList(handle).front()->setText(value);
}
else
{
TagLib::ID3v2::TextIdentificationFrame *frame =
new TagLib::ID3v2::TextIdentificationFrame(handle, TagLib::String::UTF8);
tag->addFrame(frame);
frame->setText(value);
}
file.save();
return 0;
}
If you just want to remove the frames, you can simply do:
TagLib::MPEG::File file("foo.mp3");
TagLib::ID3v2::Tag *tag = file.ID3v2Tag();
if(tag)
{
tag->removeFrames("TPE2");
file.save();
}
来源:https://stackoverflow.com/questions/16628798/taglib-how-to-edit-album-artist