From cc6e5a6c69e7a73f9d5a8f5018762f60b790fec8 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Mon, 2 Sep 2024 23:48:25 +0200 Subject: [PATCH] TagReaderTagLib: Handle multiple mbids for MP4 Fixes #1531 --- .../tagreadertaglib.cpp | 22 +++++++++++++++---- ext/libstrawberry-tagreader/tagreadertaglib.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ext/libstrawberry-tagreader/tagreadertaglib.cpp b/ext/libstrawberry-tagreader/tagreadertaglib.cpp index ed8978c19..041a80db6 100644 --- a/ext/libstrawberry-tagreader/tagreadertaglib.cpp +++ b/ext/libstrawberry-tagreader/tagreadertaglib.cpp @@ -798,13 +798,13 @@ void TagReaderTagLib::ParseMP4Tags(TagLib::MP4::Tag *tag, QString *disc, QString } if (tag->contains(kMP4_MusicBrainz_AlbumArtistId)) { - AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_AlbumArtistId).toStringList().toString(), song->mutable_musicbrainz_album_artist_id()); + AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_AlbumArtistId).toStringList()), song->mutable_musicbrainz_album_artist_id()); } if (tag->contains(kMP4_MusicBrainz_ArtistId)) { - AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_ArtistId).toStringList().toString(), song->mutable_musicbrainz_artist_id()); + AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_ArtistId).toStringList()), song->mutable_musicbrainz_artist_id()); } if (tag->contains(kMP4_MusicBrainz_OriginalArtistId)) { - AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_OriginalArtistId).toStringList().toString(), song->mutable_musicbrainz_original_artist_id()); + AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_OriginalArtistId).toStringList()), song->mutable_musicbrainz_original_artist_id()); } if (tag->contains(kMP4_MusicBrainz_AlbumId)) { AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_AlbumId).toStringList().toString(), song->mutable_musicbrainz_album_id()); @@ -825,7 +825,7 @@ void TagReaderTagLib::ParseMP4Tags(TagLib::MP4::Tag *tag, QString *disc, QString AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_ReleaseGroupId).toStringList().toString(), song->mutable_musicbrainz_release_group_id()); } if (tag->contains(kMP4_MusicBrainz_WorkId)) { - AssignTagLibStringToStdString(tag->item(kMP4_MusicBrainz_WorkId).toStringList().toString(), song->mutable_musicbrainz_work_id()); + AssignTagLibStringToStdString(TagLibStringListToSlashSeparatedString(tag->item(kMP4_MusicBrainz_WorkId).toStringList()), song->mutable_musicbrainz_work_id()); } } @@ -1870,3 +1870,17 @@ TagReaderBase::Result TagReaderTagLib::SaveSongRatingToFile(const QString &filen return success ? Result::ErrorCode::Success : Result::ErrorCode::FileSaveError; } + +TagLib::String TagReaderTagLib::TagLibStringListToSlashSeparatedString(const TagLib::StringList &taglib_string_list) { + + TagLib::String result_string; + for (const TagLib::String &taglib_string : taglib_string_list) { + if (!result_string.isEmpty()) { + result_string += '/'; + } + result_string += taglib_string; + } + + return result_string; + +} diff --git a/ext/libstrawberry-tagreader/tagreadertaglib.h b/ext/libstrawberry-tagreader/tagreadertaglib.h index d66a8ab89..deb79be03 100644 --- a/ext/libstrawberry-tagreader/tagreadertaglib.h +++ b/ext/libstrawberry-tagreader/tagreadertaglib.h @@ -136,6 +136,8 @@ class TagReaderTagLib : public TagReaderBase { void SetEmbeddedArt(TagLib::ID3v2::Tag *tag, const QByteArray &data, const QString &mime_type) const; void SetEmbeddedArt(TagLib::MP4::File *aac_file, TagLib::MP4::Tag *tag, const QByteArray &data, const QString &mime_type) const; + static TagLib::String TagLibStringListToSlashSeparatedString(const TagLib::StringList &taglib_string_list); + private: FileRefFactory *factory_;