From 231c0970c953f5c8213cb293cba54398b45e0647 Mon Sep 17 00:00:00 2001 From: tibequadorian Date: Thu, 8 Apr 2021 22:56:14 +0200 Subject: [PATCH] Fix vorbis comment and add support for Opus (#463) * fix multiple values for vorbis comment * add vorbis comment support for opus --- src/tags.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/tags.cpp b/src/tags.cpp index a8b34ab7..db0e113c 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -174,7 +175,7 @@ void writeXiphComments(const MPD::MutableSong &s, TagLib::Ogg::XiphComment *tag) { auto writeXiph = [&](const TagLib::String &type, const TagLib::StringList &list) { for (auto it = list.begin(); it != list.end(); ++it) - tag->addField(type, *it); + tag->addField(type, *it, it == list.begin()); }; // remove field previously used as album artist tag->removeFields("ALBUM ARTIST"); @@ -229,15 +230,21 @@ bool extendedSetSupported(const TagLib::File *f) { return dynamic_cast(f) || dynamic_cast(f) + || dynamic_cast(f) || dynamic_cast(f); } ReplayGainInfo readReplayGain(TagLib::File *f) { ReplayGainInfo result; - if (auto ogg_file = dynamic_cast(f)) + if (auto vorbis_file = dynamic_cast(f)) { - if (auto xiph = ogg_file->tag()) + if (auto xiph = vorbis_file->tag()) + result = getReplayGain(xiph); + } + else if (auto opus_file = dynamic_cast(f)) + { + if (auto xiph = opus_file->tag()) result = getReplayGain(xiph); } else if (auto flac_file = dynamic_cast(f)) @@ -264,9 +271,14 @@ void read(mpd_song *s) else if (auto id3v1 = mpeg_file->ID3v1Tag()) readID3v1Tags(s, id3v1); } - else if (auto ogg_file = dynamic_cast(f.file())) + else if (auto vorbis_file = dynamic_cast(f.file())) { - if (auto xiph = ogg_file->tag()) + if (auto xiph = vorbis_file->tag()) + readXiphComments(s, xiph); + } + else if (auto opus_file = dynamic_cast(f.file())) + { + if (auto xiph = opus_file->tag()) readXiphComments(s, xiph); } else if (auto flac_file = dynamic_cast(f.file())) @@ -299,9 +311,13 @@ bool write(MPD::MutableSong &s) // do not call generic save() as it will duplicate tags saved = true; } - else if (auto ogg_file = dynamic_cast(f.file())) + else if (auto vorbis_file = dynamic_cast(f.file())) { - writeXiphComments(s, ogg_file->tag()); + writeXiphComments(s, vorbis_file->tag()); + } + else if (auto opus_file = dynamic_cast(f.file())) + { + writeXiphComments(s, opus_file->tag()); } else if (auto flac_file = dynamic_cast(f.file())) {