mirror of
https://github.com/taglib/taglib.git
synced 2025-07-14 02:54:27 -04:00
Remove MP4 meta atom when empty tag is saved
Currently, MP4 tags can only grow. If items are removed, they are just replaced by padding in the form of "free" atoms. This change will remove the whole "meta" atom when an MP4 tag without items is saved. This will make it possible, to bring the file back to its pristine state without metadata.
This commit is contained in:
@ -65,6 +65,7 @@ class TestMP4 : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST(testRepeatedSave);
|
||||
CPPUNIT_TEST(testWithZeroLengthAtom);
|
||||
CPPUNIT_TEST(testEmptyValuesRemoveItems);
|
||||
CPPUNIT_TEST(testRemoveMetadata);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
@ -654,6 +655,39 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(zeroUInt, tag->track());
|
||||
CPPUNIT_ASSERT(!tag->contains("trkn"));
|
||||
}
|
||||
|
||||
void testRemoveMetadata()
|
||||
{
|
||||
ScopedFileCopy copy("no-tags", ".m4a");
|
||||
|
||||
{
|
||||
MP4::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.isValid());
|
||||
CPPUNIT_ASSERT(!f.hasMP4Tag());
|
||||
MP4::Tag *tag = f.tag();
|
||||
CPPUNIT_ASSERT(tag->isEmpty());
|
||||
tag->setTitle("TITLE");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
MP4::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.isValid());
|
||||
CPPUNIT_ASSERT(f.hasMP4Tag());
|
||||
MP4::Tag *tag = f.tag();
|
||||
CPPUNIT_ASSERT(!tag->isEmpty());
|
||||
tag->setTitle("");
|
||||
f.save();
|
||||
}
|
||||
{
|
||||
MP4::File f(copy.fileName().c_str());
|
||||
CPPUNIT_ASSERT(f.isValid());
|
||||
CPPUNIT_ASSERT(!f.hasMP4Tag());
|
||||
CPPUNIT_ASSERT(f.tag()->isEmpty());
|
||||
CPPUNIT_ASSERT(fileEqual(
|
||||
copy.fileName(),
|
||||
TEST_FILE_PATH_C("no-tags.m4a")));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);
|
||||
|
Reference in New Issue
Block a user