diff options
-rw-r--r-- | taglib/mpeg/id3v2/id3v2tag.cpp | 19 | ||||
-rw-r--r-- | tests/test_id3v2.cpp | 13 |
2 files changed, 30 insertions, 2 deletions
diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 81255dcc..91dd887d 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -495,6 +495,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const ID3v2::TextIdentificationFrame *frameTDRC = 0; ID3v2::TextIdentificationFrame *frameTIPL = 0; ID3v2::TextIdentificationFrame *frameTMCL = 0; + ID3v2::TextIdentificationFrame *frameTCON = 0; for(FrameList::ConstIterator it = d->frameList.begin(); it != d->frameList.end(); it++) { ID3v2::Frame *frame = *it; @@ -516,6 +517,8 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const frameTIPL = dynamic_cast<ID3v2::TextIdentificationFrame *>(frame); else if(frameID == "TMCL") frameTMCL = dynamic_cast<ID3v2::TextIdentificationFrame *>(frame); + else if(frame && frameID == "TCON") + frameTCON = dynamic_cast<ID3v2::TextIdentificationFrame *>(frame); else frames->append(frame); } @@ -582,6 +585,22 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const frames->append(frameIPLS); newFrames->append(frameIPLS); } + + if(frameTCON) { + StringList genres = frameTCON->fieldList(); + String combined; + + for(StringList::ConstIterator it = genres.begin(); it != genres.end(); ++it) { + bool ok = false; + int number = it->toInt(&ok); + combined += (ok && number >= 0 && number <= 255) ? ('(' + *it + ')') : *it; + } + + frameTCON = new ID3v2::TextIdentificationFrame("TCON", String::Latin1); + frameTCON->setText(combined); + frames->append(frameTCON); + newFrames->append(frameTCON); + } } ByteVector ID3v2::Tag::render(int version) const diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 6e5452ba..dd260c0f 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -1,4 +1,4 @@ -/*************************************************************************** + /*************************************************************************** copyright : (C) 2007 by Lukas Lalinsky email : lukas@oxygene.sk ***************************************************************************/ @@ -798,7 +798,16 @@ public: CPPUNIT_ASSERT(!bar.ID3v2Tag()->frameListMap().contains("TSOP")); #endif CPPUNIT_ASSERT(!bar.ID3v2Tag()->frameListMap().contains("TSST")); -} + } + + ScopedFileCopy rareFramesCopy("rare_frames", ".mp3"); + + { + MPEG::File f(rareFramesCopy.fileName().c_str()); + f.save(MPEG::File::AllTags, File::StripOthers, ID3v2::v3); + f.seek(f.find("TCON") + 11); + CPPUNIT_ASSERT_EQUAL(ByteVector("(13)"), f.readBlock(4)); + } } void testCompressedFrameWithBrokenLength() |