From d4f869152b7c6d297ca4e4e3a740be95090bb1c0 Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Thu, 3 Jul 2025 02:04:27 +0000 Subject: [PATCH] fix(scanner): read cover art from dsf, wavpak, fix wma test (#4296) * fix(taglib): read cover art from dsf * address feedback and alsi realize wma/wavpack are missing * feedback * more const char and remove unused import --- adapters/taglib/end_to_end_test.go | 40 +++++++++++++++++++++++++++++- adapters/taglib/taglib_test.go | 2 +- adapters/taglib/taglib_wrapper.cpp | 38 ++++++++++++++++++++-------- 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/adapters/taglib/end_to_end_test.go b/adapters/taglib/end_to_end_test.go index 0b5126542..e192bbdd7 100644 --- a/adapters/taglib/end_to_end_test.go +++ b/adapters/taglib/end_to_end_test.go @@ -168,11 +168,49 @@ var _ = Describe("Extractor", func() { Entry("FLAC format", "flac"), Entry("M4a format", "m4a"), Entry("OGG format", "ogg"), - Entry("WMA format", "wv"), + Entry("WV format", "wv"), Entry("MP3 format", "mp3"), Entry("WAV format", "wav"), Entry("AIFF format", "aiff"), ) + + It("should parse wma", func() { + path := "tests/fixtures/test.wma" + mds, err := e.Parse(path) + Expect(err).ToNot(HaveOccurred()) + + info := mds[path] + fileInfo, _ := os.Stat(path) + info.FileInfo = testFileInfo{FileInfo: fileInfo} + + metadata := metadata.New(path, info) + mf := metadata.ToMediaFile(1, "folderID") + + for _, data := range roles { + role := data.Role + artists := data.ParticipantList + actual := mf.Participants[role] + + // WMA has no Arranger role + if role == model.RoleArranger { + Expect(actual).To(HaveLen(0)) + continue + } + + Expect(actual).To(HaveLen(len(artists)), role.String()) + + // For some bizarre reason, the order is inverted. We also don't get + // sort names or MBIDs + for i := range artists { + idx := len(artists) - 1 - i + + actualArtist := actual[i] + expectedArtist := artists[idx] + + Expect(actualArtist.Name).To(Equal(expectedArtist.Name)) + } + } + }) }) }) diff --git a/adapters/taglib/taglib_test.go b/adapters/taglib/taglib_test.go index 37b012763..f24c0e839 100644 --- a/adapters/taglib/taglib_test.go +++ b/adapters/taglib/taglib_test.go @@ -179,7 +179,7 @@ var _ = Describe("Extractor", func() { Entry("correctly parses wma/asf tags", "test.wma", "1.02s", 1, 44100, 16, "3.27 dB", "0.132914", "3.27 dB", "0.132914", false, true), // ffmpeg -f lavfi -i "sine=frequency=800:duration=1" test.wv - Entry("correctly parses wv (wavpak) tags", "test.wv", "1s", 1, 44100, 16, "3.43 dB", "0.125061", "3.43 dB", "0.125061", false, false), + Entry("correctly parses wv (wavpak) tags", "test.wv", "1s", 1, 44100, 16, "3.43 dB", "0.125061", "3.43 dB", "0.125061", false, true), // ffmpeg -f lavfi -i "sine=frequency=1000:duration=1" test.wav Entry("correctly parses wav tags", "test.wav", "1s", 1, 44100, 16, "3.06 dB", "0.125056", "3.06 dB", "0.125056", true, true), diff --git a/adapters/taglib/taglib_wrapper.cpp b/adapters/taglib/taglib_wrapper.cpp index 17c95bfc0..224642c6d 100644 --- a/adapters/taglib/taglib_wrapper.cpp +++ b/adapters/taglib/taglib_wrapper.cpp @@ -1,6 +1,5 @@ #include #include -#include #define TAGLIB_STATIC #include @@ -113,7 +112,7 @@ int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) { strncpy(language, bv.data(), 3); } - char *val = (char *)frame->text().toCString(true); + char *val = const_cast(frame->text().toCString(true)); goPutLyrics(id, language, val); } @@ -132,7 +131,7 @@ int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) { if (format == TagLib::ID3v2::SynchronizedLyricsFrame::AbsoluteMilliseconds) { for (const auto &line: frame->synchedText()) { - char *text = (char *)line.text.toCString(true); + char *text = const_cast(line.text.toCString(true)); goPutLyricLine(id, language, text, line.time); } } else if (format == TagLib::ID3v2::SynchronizedLyricsFrame::AbsoluteMpegFrames) { @@ -141,7 +140,7 @@ int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) { if (sampleRate != 0) { for (const auto &line: frame->synchedText()) { const int timeInMs = (line.time * 1000) / sampleRate; - char *text = (char *)line.text.toCString(true); + char *text = const_cast(line.text.toCString(true)); goPutLyricLine(id, language, text, timeInMs); } } @@ -160,9 +159,9 @@ int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) { if (m4afile != NULL) { const auto itemListMap = m4afile->tag()->itemMap(); for (const auto item: itemListMap) { - char *key = (char *)item.first.toCString(true); + char *key = const_cast(item.first.toCString(true)); for (const auto value: item.second.toStringList()) { - char *val = (char *)value.toCString(true); + char *val = const_cast(value.toCString(true)); goPutM4AStr(id, key, val); } } @@ -174,17 +173,24 @@ int taglib_read(const FILENAME_CHAR_T *filename, unsigned long id) { const TagLib::ASF::Tag *asfTags{asfFile->tag()}; const auto itemListMap = asfTags->attributeListMap(); for (const auto item : itemListMap) { - tags.insert(item.first, item.second.front().toString()); + char *key = const_cast(item.first.toCString(true)); + + for (auto j = item.second.begin(); + j != item.second.end(); ++j) { + + char *val = const_cast(j->toString().toCString(true)); + goPutStr(id, key, val); + } } } // Send all collected tags to the Go map for (TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end(); ++i) { - char *key = (char *)i->first.toCString(true); + char *key = const_cast(i->first.toCString(true)); for (TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j) { - char *val = (char *)(*j).toCString(true); + char *val = const_cast((*j).toCString(true)); goPutStr(id, key, val); } } @@ -242,7 +248,19 @@ char has_cover(const TagLib::FileRef f) { // ----- WMA else if (TagLib::ASF::File * asfFile{dynamic_cast(f.file())}) { const TagLib::ASF::Tag *tag{ asfFile->tag() }; - hasCover = tag && asfFile->tag()->attributeListMap().contains("WM/Picture"); + hasCover = tag && tag->attributeListMap().contains("WM/Picture"); + } + // ----- DSF + else if (TagLib::DSF::File * dsffile{ dynamic_cast(f.file())}) { + const TagLib::ID3v2::Tag *tag { dsffile->tag() }; + hasCover = tag && !tag->frameListMap()["APIC"].isEmpty(); + } + // ----- WAVPAK (APE tag) + else if (TagLib::WavPack::File * wvFile{dynamic_cast(f.file())}) { + if (wvFile->hasAPETag()) { + // This is the particular string that Picard uses + hasCover = !wvFile->APETag()->itemListMap()["COVER ART (FRONT)"].isEmpty(); + } } return hasCover;