From c962d78a57436c4f377f1c52fd97cf70858f226c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Mon, 2 Nov 2009 19:41:12 +0000 Subject: [PATCH] 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 --- taglib/flac/flacfile.cpp | 10 ++++++--- tests/CMakeLists.txt | 1 + tests/data/multiple-vc.flac | Bin 0 -> 4754 bytes tests/test_flac.cpp | 40 ++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/data/multiple-vc.flac create mode 100644 tests/test_flac.cpp 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 0000000000000000000000000000000000000000..93d9a8a14a2eb60b75cbb1be5c7975a095407b18 GIT binary patch literal 4754 zcmeI$%PWLY9LDi8jLQr&USo`5#&u@nGP#vYk!EC~rrc(MTpAkESO~c-l#s&SWrvl8 zVkZfOg(N#EJ3D28gq86=9=861bL#Z=>381Eclqo01!{#5IVNFJKSm)G{ki8^L`vVbfg3&;Y01;U^0RuQ6mLz<{0X*9Qu7ITpq}xq zrKk%XoVi`d>YzG%pj0Pyl?SD{sMkHnmPZ9IAbSlpI}fE-P?i@cqnIiTL78RLK?any dOnrHw>=kOT6v|nkns&mUQ&xxeWQ}gC`vy%NpK<^I literal 0 HcmV?d00001 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);