taglib : how to edit Album Artist?

限于喜欢 提交于 2020-02-02 13:36:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!