9 #include <xiphcomment.h>
24 QByteArray fname =
filename.toLocal8Bit();
25 auto *flacfile =
new TagLib::FLAC::File(fname.constData());
27 if (!flacfile->isOpen())
55 TagLib::Ogg::XiphComment *tag = flacfile->xiphComment(
true);
68 tag->addField(
"MUSICBRAINZ_ALBUMARTISTID",
70 tag->addField(
"COMPILATION_ARTIST",
76 if (tag->contains(
"MUSICBRAINZ_ALBUMARTISTID") &&
77 (tag->fieldListMap()[
"MUSICBRAINZ_ALBUMARTISTID"].toString() ==
80 tag->removeFields(
"MUSICBRAINZ_ALBUMARTISTID");
82 tag->removeFields(
"COMPILATION_ARTIST");
86 bool result = flacfile->save();
104 TagLib::Ogg::XiphComment *tag = flacfile->xiphComment();
116 bool compilation =
false;
118 if (tag->contains(
"COMPILATION_ARTIST"))
120 QString compilation_artist = TStringToQString(
121 tag->fieldListMap()[
"COMPILATION_ARTIST"].toString()).trimmed();
122 if (compilation_artist != metadata->Artist())
124 metadata->setCompilationArtist(compilation_artist);
128 else if (tag->contains(
"ALBUMARTIST"))
130 QString compilation_artist = TStringToQString(
131 tag->fieldListMap()[
"ALBUMARTIST"].toString()).trimmed();
132 if (compilation_artist != metadata->Artist())
134 metadata->setCompilationArtist(compilation_artist);
139 if (!compilation && tag->contains(
"MUSICBRAINZ_ALBUMARTISTID"))
141 QString musicbrainzcode = TStringToQString(
142 tag->fieldListMap()[
"MUSICBRAINZ_ALBUMARTISTID"].toString()).trimmed();
147 metadata->setCompilation(compilation);
149 if (metadata->Length() <= 0ms)
152 if (tag->contains(
"DISCNUMBER"))
155 int n = tag->fieldListMap()[
"DISCNUMBER"].toString().toInt(&valid);
157 metadata->setDiscNumber(n);
160 if (tag->contains(
"TOTALTRACKS"))
163 int n = tag->fieldListMap()[
"TOTALTRACKS"].toString().toInt(&valid);
165 metadata->setTrackCount(n);
168 if (tag->contains(
"TOTALDISCS"))
171 int n = tag->fieldListMap()[
"TOTALDISCS"].toString().toInt(&valid);
173 metadata->setDiscCount(n);
190 auto *picture =
new QImage();
198 picture->loadFromData((
const uchar *)pic->data().data(),
214 TagLib::FLAC::File *flacfile,
217 using TagLib::FLAC::Picture;
219 Picture *pic =
nullptr;
226 const TagLib::List<Picture *>& picList = flacfile->pictureList();
228 for (
auto *entry : picList)
230 if (entry->type() == artType)
244 using TagLib::FLAC::Picture;
245 Picture::Type artType = Picture::Other;
249 artType = Picture::Other;
252 artType = Picture::FrontCover;
255 artType = Picture::BackCover;
258 artType = Picture::Media;
261 artType = Picture::LeafletPage;
264 artType = Picture::Artist;
267 return Picture::Other;
280 using TagLib::FLAC::Picture;
286 const TagLib::List<Picture *>& picList = flacfile->pictureList();
288 for (
auto *pic : picList)
292 if (pic->data().size() < 100)
294 LOG(VB_GENERAL, LOG_NOTICE,
295 "Music Scanner - Discarding picture "
296 "with size less than 100 bytes");
302 if (pic->description().isEmpty())
303 art->m_description.clear();
305 art->m_description = TStringToQString(pic->description());
307 art->m_embedded =
true;
311 TStringToQString(pic->mimeType()).toLower());
315 case Picture::FrontCover :
317 art->m_filename = QString(
"front") + ext;
319 case Picture::BackCover :
321 art->m_filename = QString(
"back") + ext;
323 case Picture::Media :
324 art->m_imageType =
IT_CD;
325 art->m_filename = QString(
"cd") + ext;
327 case Picture::LeafletPage :
329 art->m_filename = QString(
"inlay") + ext;
331 case Picture::Artist :
333 art->m_filename = QString(
"artist") + ext;
335 case Picture::Other :
337 art->m_filename = QString(
"unknown") + ext;
340 LOG(VB_GENERAL, LOG_ERR,
"Music Scanner - picture found "
341 "with unsupported type");
366 #if TAGLIB_MAJOR_VERSION == 1 && TAGLIB_MINOR_VERSION >= 8
367 using TagLib::FLAC::Picture;
368 if (
filename.isEmpty() || !albumart)
377 QByteArray imageData;
378 QBuffer buffer(&imageData);
379 buffer.open(QIODevice::WriteOnly);
381 image.save(&buffer,
"JPEG");
394 flacfile->removePicture(pic,
false);
403 TagLib::ByteVector bytevector;
404 bytevector.setData(imageData.data(), imageData.size());
406 pic->setData(bytevector);
407 QString mimetype =
"image/jpeg";
409 pic->setMimeType(QStringToTString(mimetype));
410 pic->setDescription(QStringToTString(albumart->
m_description));
412 flacfile->addPicture(pic);
415 retval = flacfile->save();
427 LOG(VB_GENERAL, LOG_WARNING,
428 "TagLib 1.8.0 or later is required to write albumart to flac xiphComment tags");
443 #if TAGLIB_MAJOR_VERSION == 1 && TAGLIB_MINOR_VERSION >= 8
445 if (
filename.isEmpty() || !albumart)
461 flacfile->removePicture(pic,
false);
479 LOG(VB_GENERAL, LOG_WARNING,
480 "TagLib 1.8.0 or later is required to remove albumart from flac xiphComment tags");
489 if (
filename.isEmpty() || !albumart)
533 TagLib::Ogg::XiphComment *tag = flacfile->xiphComment(
false);
536 if (tag && !tag->isEmpty())
546 if (mimeType ==
"image/png")
548 if (mimeType ==
"image/jpeg" || mimeType ==
"image/jpg")
550 if (mimeType ==
"image/gif")
552 if (mimeType ==
"image/bmp")
555 LOG(VB_GENERAL, LOG_ERR,
556 "Music Scanner - Unknown image mimetype found - " + mimeType);