diff --git a/src/plugins/taglib_plugin/TaglibMetadataReader.cpp b/src/plugins/taglib_plugin/TaglibMetadataReader.cpp index 4949eb1b2..e12e6d25b 100644 --- a/src/plugins/taglib_plugin/TaglibMetadataReader.cpp +++ b/src/plugins/taglib_plugin/TaglibMetadataReader.cpp @@ -189,20 +189,34 @@ bool TaglibMetadataReader::ReadGeneric(const char* uri, musik::core::sdk::ITrack this->ReadFromMap(tag->properties(), target); /* taglib hides certain properties (like album artist) in the XiphComment's - field list. see if we're dealing with a FLAC file with a Xiph comment. if so, - extract those as well. */ + field list. if we're dealing with a straight-up Xiph tag, process it now */ auto xiphTag = dynamic_cast(tag); if (xiphTag) { this->ReadFromMap(xiphTag->fieldListMap(), target); } - /* flac files may have more than one type of tag embedded. see if there's - see if there's a xiph comment burried deep. */ + /* if this isn't a xiph tag, the file format may have some other custom + properties. let's see if we can pull them out here... */ if (!xiphTag) { + 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. */ auto flacFile = dynamic_cast(file.file()); - if (flacFile) { - if (flacFile->hasXiphComment()) { - this->ReadFromMap(flacFile->xiphComment()->fieldListMap(), target); + if (flacFile && flacFile->hasXiphComment()) { + this->ReadFromMap(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 + handling here... */ + if (!handled) { + auto mp4File = dynamic_cast(file.file()); + if (mp4File && mp4File->hasMP4Tag()) { + auto mp4TagMap = static_cast(tag)->itemListMap(); + this->ExtractValueForKey(mp4TagMap, "aART", "album_artist", target); + this->ExtractValueForKey(mp4TagMap, "disk", "disc", target); } } } @@ -217,6 +231,20 @@ bool TaglibMetadataReader::ReadGeneric(const char* uri, musik::core::sdk::ITrack return false; } +void TaglibMetadataReader::ExtractValueForKey( + const TagLib::MP4::ItemMap& map, + const std::string& inputKey, + const std::string& outputKey, + musik::core::sdk::ITrackWriter *target) +{ + if (map.contains(inputKey.c_str())) { + TagLib::StringList value = map[inputKey.c_str()].toStringList(); + if (value.size()) { + this->SetTagValue(outputKey.c_str(), value[0], target); + } + } +} + template void TaglibMetadataReader::ExtractValueForKey( const T& map, diff --git a/src/plugins/taglib_plugin/TaglibMetadataReader.h b/src/plugins/taglib_plugin/TaglibMetadataReader.h index f53b0c534..55e7a7a82 100644 --- a/src/plugins/taglib_plugin/TaglibMetadataReader.h +++ b/src/plugins/taglib_plugin/TaglibMetadataReader.h @@ -43,6 +43,7 @@ #include #include #include + #include #else #include #include @@ -50,6 +51,7 @@ #include #include #include + #include #endif #include @@ -74,6 +76,12 @@ class TaglibMetadataReader : public musik::core::sdk::IMetadataReader { const std::string& outputKey, musik::core::sdk::ITrackWriter *target); + void ExtractValueForKey( + const TagLib::MP4::ItemMap& map, + const std::string& inputKey, + const std::string& outputKey, + musik::core::sdk::ITrackWriter *target); + void SetTagValue( const char* key, const char* string,musik::core::sdk::ITrackWriter *target);