Skip duplicate ID3v2 tags and treat them as an extra blank of the first one.

This enables all the file formats to handle duplicate ID3v2 tags properly and erase them automatically.
This commit is contained in:
Tsuda Kageyu
2015-11-13 11:55:56 +09:00
parent a25e1e9f90
commit 11fbf394a3
3 changed files with 74 additions and 30 deletions

View File

@ -93,6 +93,7 @@ class TestID3v2 : public CppUnit::TestFixture
CPPUNIT_TEST(testRenderTableOfContentsFrame);
CPPUNIT_TEST(testShrinkPadding);
CPPUNIT_TEST(testEmptyFrame);
CPPUNIT_TEST(testDuplicateTags);
CPPUNIT_TEST_SUITE_END();
public:
@ -1117,6 +1118,41 @@ public:
}
}
void testDuplicateTags()
{
ScopedFileCopy copy("duplicate_id3v2", ".mp3");
ByteVector audioStream;
{
MPEG::File f(copy.fileName().c_str());
f.seek(f.ID3v2Tag()->header()->completeTagSize());
audioStream = f.readBlock(2089);
// duplicate_id3v2.mp3 has duplicate ID3v2 tags.
// Sample rate will be 32000 if we can't skip the second tag.
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL((TagLib::uint)8049, f.ID3v2Tag()->header()->completeTagSize());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
f.ID3v2Tag()->setArtist("Artist A");
f.save(MPEG::File::ID3v2, true);
}
{
MPEG::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(f.hasID3v2Tag());
CPPUNIT_ASSERT_EQUAL((long)3594, f.length());
CPPUNIT_ASSERT_EQUAL((TagLib::uint)1505, f.ID3v2Tag()->header()->completeTagSize());
CPPUNIT_ASSERT_EQUAL(String("Artist A"), f.ID3v2Tag()->artist());
CPPUNIT_ASSERT_EQUAL(44100, f.audioProperties()->sampleRate());
f.seek(f.ID3v2Tag()->header()->completeTagSize());
CPPUNIT_ASSERT_EQUAL(f.readBlock(2089), audioStream);
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);