Removed duplicated tag values, fixes #415, fixes #611

This commit is contained in:
emeric
2025-02-22 10:57:44 +01:00
parent 506e2c45db
commit 04a86357fa
+39 -12
View File
@@ -19,6 +19,7 @@
#include "TagLibTagReader.hpp"
#include <algorithm>
#include <unordered_map>
#include <taglib/aifffile.h>
@@ -191,6 +192,28 @@ namespace lms::metadata
}
}
void dedupTagValues(TagLib::PropertyMap& propertyMap, const std::filesystem::path& file)
{
for (auto& [key, values] : propertyMap)
{
if (values.size() <= 1)
continue;
TagLib::StringList newList;
for (const TagLib::String& value : values)
{
if (!std::any_of(std::cbegin(newList), std::cend(newList), [&](const TagLib::String& v) { return v == value; }))
newList.append(value);
}
if (values != newList)
{
LMS_LOG(METADATA, DEBUG, "File " << file << ": removed " << (values.size() - newList.size()) << " duplicated value(s) in tag '" << key << "', " << newList.size() << " remaining value(s)");
values = newList;
}
}
}
TagLib::FileRef parseFile(const std::filesystem::path& p, ParserReadStyle parserReadStyle)
{
LMS_SCOPED_TRACE_DETAILED("MetaData", "TagLibParseFile");
@@ -220,6 +243,18 @@ namespace lms::metadata
_propertyMap = _file.file()->properties();
if (debug && core::Service<core::logging::ILogger>::get()->isSeverityActive(core::logging::Severity::DEBUG))
{
for (const auto& [key, values] : _propertyMap)
{
for (const auto& value : values)
LMS_LOG(METADATA, DEBUG, "Key = '" << key << "', value = '" << value.to8Bit(true) << "'");
}
for (const auto& value : _propertyMap.unsupportedData())
LMS_LOG(METADATA, DEBUG, "Unknown value: '" << value.to8Bit(true) << "'");
}
// Some tags may not be known by TagLib
auto getAPETags = [&](const TagLib::APE::Tag* apeTag) {
if (!apeTag)
@@ -229,6 +264,10 @@ namespace lms::metadata
};
auto processID3v2Tags = [&](TagLib::ID3v2::Tag& id3v2Tags) {
// Dedup values for some tags that may be written in both a standard tag and in a custom tag
dedupTagValues(_propertyMap, p);
const auto& frameListMap{ id3v2Tags.frameListMap() };
// Not that good embedded pictures handling
@@ -406,18 +445,6 @@ namespace lms::metadata
if (wavFile->hasID3v2Tag())
processID3v2Tags(*wavFile->ID3v2Tag());
}
if (debug && core::Service<core::logging::ILogger>::get()->isSeverityActive(core::logging::Severity::DEBUG))
{
for (const auto& [key, values] : _propertyMap)
{
for (const auto& value : values)
LMS_LOG(METADATA, DEBUG, "Key = '" << key << "', value = '" << value.to8Bit(true) << "'");
}
for (const auto& value : _propertyMap.unsupportedData())
LMS_LOG(METADATA, DEBUG, "Unknown value: '" << value.to8Bit(true) << "'");
}
}
void TagLibTagReader::computeAudioProperties()