10#include <taglib/xiphcomment.h>
25 QByteArray fname =
filename.toLocal8Bit();
26 auto *flacfile =
new TagLib::FLAC::File(fname.constData());
28 if (!flacfile->isOpen())
56 TagLib::Ogg::XiphComment *tag = flacfile->xiphComment(
true);
69 tag->addField(
"MUSICBRAINZ_ALBUMARTISTID",
71 tag->addField(
"COMPILATION_ARTIST",
77 if (tag->contains(
"MUSICBRAINZ_ALBUMARTISTID") &&
78 (tag->fieldListMap()[
"MUSICBRAINZ_ALBUMARTISTID"].toString() ==
81 tag->removeFields(
"MUSICBRAINZ_ALBUMARTISTID");
83 tag->removeFields(
"COMPILATION_ARTIST");
87 bool result = flacfile->save();
105 TagLib::Ogg::XiphComment *tag = flacfile->xiphComment();
117 bool compilation =
false;
119 if (tag->contains(
"COMPILATION_ARTIST"))
121 QString compilation_artist = TStringToQString(
122 tag->fieldListMap()[
"COMPILATION_ARTIST"].toString()).trimmed();
123 if (compilation_artist != metadata->Artist())
125 metadata->setCompilationArtist(compilation_artist);
129 else if (tag->contains(
"ALBUMARTIST"))
131 QString compilation_artist = TStringToQString(
132 tag->fieldListMap()[
"ALBUMARTIST"].toString()).trimmed();
133 if (compilation_artist != metadata->Artist())
135 metadata->setCompilationArtist(compilation_artist);
140 if (!compilation && tag->contains(
"MUSICBRAINZ_ALBUMARTISTID"))
142 QString musicbrainzcode = TStringToQString(
143 tag->fieldListMap()[
"MUSICBRAINZ_ALBUMARTISTID"].toString()).trimmed();
148 metadata->setCompilation(compilation);
150 if (metadata->Length() <= 0ms)
153 if (tag->contains(
"DISCNUMBER"))
156 int n = tag->fieldListMap()[
"DISCNUMBER"].toString().toInt(&valid);
158 metadata->setDiscNumber(n);
161 if (tag->contains(
"TOTALTRACKS"))
164 int n = tag->fieldListMap()[
"TOTALTRACKS"].toString().toInt(&valid);
166 metadata->setTrackCount(n);
169 if (tag->contains(
"TOTALDISCS"))
172 int n = tag->fieldListMap()[
"TOTALDISCS"].toString().toInt(&valid);
174 metadata->setDiscCount(n);
191 auto *picture =
new QImage();
199 picture->loadFromData((
const uchar *)pic->data().data(),
215 TagLib::FLAC::File *flacfile,
218 TagLib::FLAC::Picture *pic =
nullptr;
225 const TagLib::List<TagLib::FLAC::Picture *>& picList = flacfile->pictureList();
227 for (
auto *entry : picList)
229 if (entry->type() == artType)
243 TagLib::FLAC::Picture::Type artType = TagLib::FLAC::Picture::Other;
247 artType = TagLib::FLAC::Picture::Other;
250 artType = TagLib::FLAC::Picture::FrontCover;
253 artType = TagLib::FLAC::Picture::BackCover;
256 artType = TagLib::FLAC::Picture::Media;
259 artType = TagLib::FLAC::Picture::LeafletPage;
262 artType = TagLib::FLAC::Picture::Artist;
265 return TagLib::FLAC::Picture::Other;
283 const TagLib::List<TagLib::FLAC::Picture *>& picList = flacfile->pictureList();
285 for (
auto *pic : picList)
289 if (pic->data().size() < 100)
291 LOG(VB_GENERAL, LOG_NOTICE,
292 "Music Scanner - Discarding picture "
293 "with size less than 100 bytes");
299 if (pic->description().isEmpty())
300 art->m_description.clear();
302 art->m_description = TStringToQString(pic->description());
304 art->m_embedded =
true;
308 TStringToQString(pic->mimeType()).toLower());
312 case TagLib::FLAC::Picture::FrontCover :
314 art->m_filename = QString(
"front") + ext;
316 case TagLib::FLAC::Picture::BackCover :
318 art->m_filename = QString(
"back") + ext;
320 case TagLib::FLAC::Picture::Media :
321 art->m_imageType =
IT_CD;
322 art->m_filename = QString(
"cd") + ext;
324 case TagLib::FLAC::Picture::LeafletPage :
326 art->m_filename = QString(
"inlay") + ext;
328 case TagLib::FLAC::Picture::Artist :
330 art->m_filename = QString(
"artist") + ext;
332 case TagLib::FLAC::Picture::Other :
334 art->m_filename = QString(
"unknown") + ext;
337 LOG(VB_GENERAL, LOG_ERR,
"Music Scanner - picture found "
338 "with unsupported type");
363#if TAGLIB_MAJOR_VERSION == 1 && TAGLIB_MINOR_VERSION >= 8
364 if (
filename.isEmpty() || !albumart)
373 QByteArray imageData;
374 QBuffer buffer(&imageData);
375 buffer.open(QIODevice::WriteOnly);
377 image.save(&buffer,
"JPEG");
390 flacfile->removePicture(pic,
false);
395 pic =
new TagLib::FLAC::Picture();
399 TagLib::ByteVector bytevector;
400 bytevector.setData(imageData.data(), imageData.size());
402 pic->setData(bytevector);
403 QString mimetype =
"image/jpeg";
405 pic->setMimeType(QStringToTString(mimetype));
406 pic->setDescription(QStringToTString(albumart->
m_description));
408 flacfile->addPicture(pic);
411 retval = flacfile->save();
423 LOG(VB_GENERAL, LOG_WARNING,
424 "TagLib 1.8.0 or later is required to write albumart to flac xiphComment tags");
439#if TAGLIB_MAJOR_VERSION == 1 && TAGLIB_MINOR_VERSION >= 8
441 if (
filename.isEmpty() || !albumart)
457 flacfile->removePicture(pic,
false);
475 LOG(VB_GENERAL, LOG_WARNING,
476 "TagLib 1.8.0 or later is required to remove albumart from flac xiphComment tags");
485 if (
filename.isEmpty() || !albumart)
529 TagLib::Ogg::XiphComment *tag = flacfile->xiphComment(
false);
532 if (tag && !tag->isEmpty())
542 if (mimeType ==
"image/png")
544 if (mimeType ==
"image/jpeg" || mimeType ==
"image/jpg")
546 if (mimeType ==
"image/gif")
548 if (mimeType ==
"image/bmp")
551 LOG(VB_GENERAL, LOG_ERR,
552 "Music Scanner - Unknown image mimetype found - " + mimeType);
QString GetHostName(void)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)