From f311ad4de7ee842005a36c63acc34779ec463598 Mon Sep 17 00:00:00 2001 From: casey langen Date: Tue, 19 Jul 2022 19:27:06 -0700 Subject: [PATCH] Fix xiph album art extraction. --- CHANGELOG.txt | 8 ++++- .../taglib_plugin/TaglibMetadataReader.cpp | 34 +++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9504cd268..b6f9f5838 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,10 @@ -0.98 +0.98.1 + +* fixed album art extraction for xiph comments. + +-------------------------------------------------------------------------------- + +0.98.0 * added the ability to click the browse and tracklist headers to change filter options diff --git a/src/plugins/taglib_plugin/TaglibMetadataReader.cpp b/src/plugins/taglib_plugin/TaglibMetadataReader.cpp index 1e805bd7e..9c03d00fd 100644 --- a/src/plugins/taglib_plugin/TaglibMetadataReader.cpp +++ b/src/plugins/taglib_plugin/TaglibMetadataReader.cpp @@ -225,6 +225,18 @@ static inline bool replayGainValid(ReplayGain& rg) { rg.trackGain != 1.0 || rg.trackPeak != 1.0; } +static inline void processAlbumArt(TagLib::List pictures, ITagStore* target) { + for (auto picture : pictures) { + if (picture->type() == TagLib::FLAC::Picture::FrontCover) { + auto byteVector = picture->data(); + if (byteVector.size()) { + target->SetThumbnail(byteVector.data(), byteVector.size()); + } + break; + } + } +} + TaglibMetadataReader::TaglibMetadataReader() { } @@ -337,6 +349,7 @@ bool TaglibMetadataReader::ReadGeneric( field list. if we're dealing with a straight-up Xiph tag, process it now */ const auto xiphTag = dynamic_cast(tag); if (xiphTag) { + processAlbumArt(xiphTag->pictureList(), target); this->ReadFromMap(xiphTag->fieldListMap(), target); this->ExtractReplayGain(xiphTag->fieldListMap(), target); } @@ -347,25 +360,16 @@ bool TaglibMetadataReader::ReadGeneric( bool handled = false; /* flac files may have more than one type of tag embedded. see if there's - see if there's a xiph comment burried deep. */ + see if there's a xiph comment buried deep. */ auto flacFile = dynamic_cast(file.file()); if (flacFile) { - auto pictures = flacFile->pictureList(); - for (auto picture : pictures) { - if (picture->type() == TagLib::FLAC::Picture::FrontCover) { - auto byteVector = picture->data(); - if (byteVector.size()) { - target->SetThumbnail(byteVector.data(), byteVector.size()); - } - break; - } + processAlbumArt(flacFile->pictureList(), target); + if (flacFile->hasXiphComment()) { + this->ReadFromMap(flacFile->xiphComment()->fieldListMap(), target); + this->ExtractReplayGain(flacFile->xiphComment()->fieldListMap(), target); + handled = true; } } - if (flacFile && flacFile->hasXiphComment()) { - this->ReadFromMap(flacFile->xiphComment()->fieldListMap(), target); - this->ExtractReplayGain(flacFile->xiphComment()->fieldListMap(), target); - handled = true; - } /* similarly, mp4 buries disc number and album artist. however, taglib does NOT exposed a map with normalized keys, so we have to do special property