From: Lukáš Lalinský Date: Mon, 2 Nov 2009 19:41:12 +0000 (+0000) Subject: Always read tags from the first Vorbis Comment block in FLAC files X-Git-Tag: v1.6.2~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c962d78a57436c4f377f1c52fd97cf70858f226c;p=taglib Always read tags from the first Vorbis Comment block in FLAC files Prevously TagLib saved tags to the first block, but read them from the last one. Having multiple VC blocks is a non-standard situation, but this is the best we can do (libFLAC also uses the first block in the case of multiple VC blocks). BUG:211089 git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1043985 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index ed3d6db9..7f3d9023 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -406,7 +406,6 @@ void FLAC::File::scan() nextBlockOffset += length + 4; // Search through the remaining metadata - while(!isLastBlock) { header = readBlock(4); @@ -416,8 +415,13 @@ void FLAC::File::scan() // Found the vorbis-comment if(blockType == VorbisComment) { - d->xiphCommentData = readBlock(length); - d->hasXiphComment = true; + if(!d->hasXiphComment) { + d->xiphCommentData = readBlock(length); + d->hasXiphComment = true; + } + else { + debug("FLAC::File::scan() -- multiple Vorbis Comment blocks found, using the first one"); + } } nextBlockOffset += length + 4; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0e42ffce..005b7a5a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,6 +36,7 @@ SET(test_runner_SRCS test_riff.cpp test_ogg.cpp test_oggflac.cpp + test_flac.cpp ) IF(WITH_MP4) SET(test_runner_SRCS ${test_runner_SRCS} diff --git a/tests/data/multiple-vc.flac b/tests/data/multiple-vc.flac new file mode 100644 index 00000000..93d9a8a1 Binary files /dev/null and b/tests/data/multiple-vc.flac differ diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp new file mode 100644 index 00000000..acccc871 --- /dev/null +++ b/tests/test_flac.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" + +using namespace std; +using namespace TagLib; + +class TestFLAC : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(TestFLAC); + CPPUNIT_TEST(testMultipleCommentBlocks); + CPPUNIT_TEST_SUITE_END(); + +public: + + void testMultipleCommentBlocks() + { + string newname = copyFile("multiple-vc", ".flac"); + + FLAC::File *f = new FLAC::File(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("Artist 1"), f->tag()->artist()); + f->tag()->setArtist("The Artist"); + f->save(); + delete f; + + f = new FLAC::File(newname.c_str()); + CPPUNIT_ASSERT_EQUAL(String("The Artist"), f->tag()->artist()); + delete f; + + deleteFile(newname); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);