Skip to content

Commit

Permalink
Handle FLAC files with no file tags but only a picture list
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Mar 7, 2020
1 parent 3688aa9 commit 35b89e9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
27 changes: 19 additions & 8 deletions src/sources/metadatasourcetaglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,34 @@ MetadataSourceTagLib::importTrackMetadataAndCoverImage(
if (!taglib::readAudioProperties(pTrackMetadata, file)) {
break;
}
// Read cover art directly from the file first. Will be
// overwritten with cover art contained in on of the tags.
if (pCoverImage) {
*pCoverImage = taglib::importCoverImageFromVorbisCommentPictureList(file.pictureList());
}
bool importSucceeded = false;
bool coverImageImported = false;
// VorbisComment tag takes precedence over ID3v2 tag
if (taglib::hasXiphComment(file)) {
TagLib::Ogg::XiphComment* pTag = file.xiphComment();
DEBUG_ASSERT(pTag);
taglib::importTrackMetadataFromVorbisCommentTag(pTrackMetadata, *pTag);
taglib::importCoverImageFromVorbisCommentTag(pCoverImage, *pTag);
return afterImport(ImportResult::Succeeded);
coverImageImported = taglib::importCoverImageFromVorbisCommentTag(pCoverImage, *pTag);
importSucceeded = true;
} else if (taglib::hasID3v2Tag(file)) {
const TagLib::ID3v2::Tag* pTag = file.ID3v2Tag();
DEBUG_ASSERT(pTag);
taglib::importTrackMetadataFromID3v2Tag(pTrackMetadata, *pTag);
taglib::importCoverImageFromID3v2Tag(pCoverImage, *pTag);
coverImageImported = taglib::importCoverImageFromID3v2Tag(pCoverImage, *pTag);
importSucceeded = true;
}
// Only import cover images from picture list as a fallback if file tags
// are available but no cover image has been found yet! Otherwise until
// file tags have been successfully imported once, Mixxx would retry to
// import the missing file tags over and over again when loading the
// cover image.
if (pCoverImage && // cover image is requested
importSucceeded &&
!coverImageImported) { // no cover image found in file tags
// Read cover art directly from the file as a fallback
*pCoverImage = taglib::importCoverImageFromVorbisCommentPictureList(file.pictureList());
}
if (importSucceeded) {
return afterImport(ImportResult::Succeeded);
}
break;
Expand Down
48 changes: 33 additions & 15 deletions src/track/trackmetadatataglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,17 +1168,17 @@ const T* downcastID3v2Frame(TagLib::ID3v2::Frame* frame) {
return downcastFrame;
}

void importCoverImageFromID3v2Tag(QImage* pCoverArt, const TagLib::ID3v2::Tag& tag) {
bool importCoverImageFromID3v2Tag(QImage* pCoverArt, const TagLib::ID3v2::Tag& tag) {
if (!pCoverArt) {
return; // nothing to do
return false; // nothing to do
}

const auto iterAPIC = tag.frameListMap().find("APIC");
if ((iterAPIC == tag.frameListMap().end()) || iterAPIC->second.isEmpty()) {
if (kLogger.debugEnabled()) {
kLogger.debug() << "No cover art: None or empty list of ID3v2 APIC frames";
}
return; // abort
return false; // abort
}

const TagLib::ID3v2::FrameList pFrames = iterAPIC->second;
Expand All @@ -1195,7 +1195,7 @@ void importCoverImageFromID3v2Tag(QImage* pCoverArt, const TagLib::ID3v2::Tag& t
continue;
} else {
*pCoverArt = image;
return; // success
return true; // success
}
}
}
Expand All @@ -1214,15 +1214,20 @@ void importCoverImageFromID3v2Tag(QImage* pCoverArt, const TagLib::ID3v2::Tag& t
continue;
} else {
*pCoverArt = image;
return; // success
return true; // success
}
}
}

if (kLogger.debugEnabled()) {
kLogger.debug() << "No cover art found in ID3v2 tag";
}
return false;
}

void importCoverImageFromAPETag(QImage* pCoverArt, const TagLib::APE::Tag& tag) {
bool importCoverImageFromAPETag(QImage* pCoverArt, const TagLib::APE::Tag& tag) {
if (!pCoverArt) {
return; // nothing to do
return false; // nothing to do
}

if (tag.itemListMap().contains("COVER ART (FRONT)")) {
Expand All @@ -1238,22 +1243,28 @@ void importCoverImageFromAPETag(QImage* pCoverArt, const TagLib::APE::Tag& tag)
<< "Failed to load image from APE tag";
} else {
*pCoverArt = image; // success
return true;
}
}
}

if (kLogger.debugEnabled()) {
kLogger.debug() << "No cover art found in APE tag";
}
return false;
}

void importCoverImageFromVorbisCommentTag(QImage* pCoverArt, TagLib::Ogg::XiphComment& tag) {
bool importCoverImageFromVorbisCommentTag(QImage* pCoverArt, TagLib::Ogg::XiphComment& tag) {
if (!pCoverArt) {
return; // nothing to do
return false; // nothing to do
}

#if (TAGLIB_HAS_VORBIS_COMMENT_PICTURES)
const QImage image=
importCoverImageFromVorbisCommentPictureList(tag.pictureList());
if (!image.isNull()) {
*pCoverArt = image;
return; // done
return false; // done
}
#endif

Expand Down Expand Up @@ -1287,7 +1298,7 @@ void importCoverImageFromVorbisCommentTag(QImage* pCoverArt, TagLib::Ogg::XiphCo
continue;
} else {
*pCoverArt = image;
return; // done
return true; // done
}
} else {
kLogger.warning()
Expand Down Expand Up @@ -1315,18 +1326,20 @@ void importCoverImageFromVorbisCommentTag(QImage* pCoverArt, TagLib::Ogg::XiphCo
continue;
} else {
*pCoverArt = image;
return; // done
return true; // done
}
}
}

if (kLogger.debugEnabled()) {
kLogger.debug() << "No cover art found in VorbisComment tag";
}
return false;
}

void importCoverImageFromMP4Tag(QImage* pCoverArt, const TagLib::MP4::Tag& tag) {
bool importCoverImageFromMP4Tag(QImage* pCoverArt, const TagLib::MP4::Tag& tag) {
if (!pCoverArt) {
return; // nothing to do
return false; // nothing to do
}

if (getItemListMap(tag).contains("covr")) {
Expand All @@ -1340,10 +1353,15 @@ void importCoverImageFromMP4Tag(QImage* pCoverArt, const TagLib::MP4::Tag& tag)
continue;
} else {
*pCoverArt = image;
return; // done
return true; // done
}
}
}

if (kLogger.debugEnabled()) {
kLogger.debug() << "No cover art found in MP4 tag";
}
return false;
}

void importTrackMetadataFromTag(
Expand Down
8 changes: 4 additions & 4 deletions src/track/trackmetadatataglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ bool readAudioProperties(
TrackMetadata* pTrackMetadata,
const TagLib::File& file);

void importCoverImageFromID3v2Tag(QImage* pCoverArt, const TagLib::ID3v2::Tag& tag);
void importCoverImageFromAPETag(QImage* pCoverArt, const TagLib::APE::Tag& tag);
void importCoverImageFromVorbisCommentTag(QImage* pCoverArt, TagLib::Ogg::XiphComment& tag);
void importCoverImageFromMP4Tag(QImage* pCoverArt, const TagLib::MP4::Tag& tag);
bool importCoverImageFromID3v2Tag(QImage* pCoverArt, const TagLib::ID3v2::Tag& tag);
bool importCoverImageFromAPETag(QImage* pCoverArt, const TagLib::APE::Tag& tag);
bool importCoverImageFromVorbisCommentTag(QImage* pCoverArt, TagLib::Ogg::XiphComment& tag);
bool importCoverImageFromMP4Tag(QImage* pCoverArt, const TagLib::MP4::Tag& tag);

QImage importCoverImageFromVorbisCommentPictureList(const TagLib::List<TagLib::FLAC::Picture*>& pictures);

Expand Down

0 comments on commit 35b89e9

Please sign in to comment.