From 6402b6f9c9aad20180079d8b35f55267634028f2 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 28 Oct 2014 20:07:07 +0100 Subject: [PATCH] tags: writeID3v2Tags: write comment tag properly --- src/tags.cpp | 19 ++++++++++++++++--- src/utility/string.h | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/tags.cpp b/src/tags.cpp index 7405cde..03a8330 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -31,10 +31,12 @@ #include #include #include +#include #include #include "global.h" #include "settings.h" +#include "utility/string.h" #include "utility/wide_string.h" namespace {// @@ -151,9 +153,20 @@ void writeID3v2Tags(const MPD::MutableSong &s, TagLib::ID3v2::Tag *tag) tag->removeFrames(type); if (!list.isEmpty()) { - auto frame = new TagLib::ID3v2::TextIdentificationFrame(type, TagLib::String::UTF8); - frame->setText(list); - tag->addFrame(frame); + if (type == "COMM") // comment needs to be handled separately + { + auto frame = new TagLib::ID3v2::CommentsFrame(TagLib::String::UTF8); + // apparently there can't be multiple comments, + // so if there is more than one, join them. + frame->setText(join(list, TagLib::String(Config.tags_separator, TagLib::String::UTF8))); + tag->addFrame(frame); + } + else + { + auto frame = new TagLib::ID3v2::TextIdentificationFrame(type, TagLib::String::UTF8); + frame->setText(list); + tag->addFrame(frame); + } } }; writeID3v2("TIT2", tagList(s, &MPD::Song::getTitle)); diff --git a/src/utility/string.h b/src/utility/string.h index 9c69c1c..c6cd5fe 100644 --- a/src/utility/string.h +++ b/src/utility/string.h @@ -31,6 +31,27 @@ template size_t const_strlen(const char (&)[N]) { return N-1; } +// it's present in boost for std::string, but we want more general version. +template +StringT join(CollectionT &&collection, StringT &&separator) +{ + StringT result; + auto first = std::begin(collection), last = std::end(collection); + if (first != last) + { + while (true) + { + result += *first; + ++first; + if (first != last) + result += separator; + else + break; + } + } + return result; +} + std::string getBasename(const std::string &path); std::string getParentDirectory(const std::string &path); std::string getSharedDirectory(const std::string &dir1, const std::string &dir2); -- 2.11.4.GIT