Handling multiple genres in id3v2?

Andrew Lake jamboarder at gmail.com
Fri Jan 7 19:00:56 CET 2011


On Fri, Jan 7, 2011 at 9:45 AM, Sander Jansen wrote:
> * So how do we store multiple genres/tags, one TCON frame with
> multiple strings or multiple TCON frames with one string each.

Here's what I did (id3v2 is a TagLib::ID3v2::Tag*):

Read genres:
TagLib::ID3v2::TextIdentificationFrame *tFrame =
dynamic_cast<TagLib::ID3v2::TextIdentificationFrame
*>(id3v2->frameListMap()["TCON"].front());
TagLib::StringList genres = tFrame->fieldList();

Write genres:
if (!id3v2->frameListMap()["TCON"].isEmpty()) {
    TagLib::ID3v2::TextIdentificationFrame *tFrame =
dynamic_cast<TagLib::ID3v2::TextIdentificationFrame
*>(id3v2->frameListMap()["TCON"].front());
    tFrame->setText(tValues);
} else {
    TagLib::ID3v2::TextIdentificationFrame *tFrame = new
TagLib::ID3v2::TextIdentificationFrame("TCON", TagLib::String::UTF8);
    id3v2->addFrame(tFrame);
    tFrame->setText(genres);
}

Hope this helps,
Andrew


More information about the taglib-devel mailing list