tags: writeID3v2Tags: write comment tag properly
This commit is contained in:
19
src/tags.cpp
19
src/tags.cpp
@@ -31,10 +31,12 @@
|
||||
#include <vorbisfile.h>
|
||||
#include <tag.h>
|
||||
#include <textidentificationframe.h>
|
||||
#include <commentsframe.h>
|
||||
#include <xiphcomment.h>
|
||||
|
||||
#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));
|
||||
|
||||
@@ -31,6 +31,27 @@ template <size_t N> 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 <typename CollectionT, typename StringT>
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user