#include "track/taglib/trackmetadata_id3v2.h"
#include <taglib/attachedpictureframe.h>
#include <taglib/commentsframe.h>
#include <taglib/generalencapsulatedobjectframe.h>
#include <taglib/textidentificationframe.h>
#include <taglib/unknownframe.h>
#include <array>
#if defined(__EXTRA_METADATA__)
#include <taglib/uniquefileidentifierframe.h>
#endif // __EXTRA_METADATA__
#include "track/tracknumbers.h"
#include "util/logger.h"
namespace mixxx {
namespace {
Logger kLogger("TagLib");
} // anonymous namespace
namespace taglib {
namespace {
// Only ID3v2.3 and ID3v2.4 are supported for both importing and
// exporting text frames. ID3v2.2 uses different frame identifiers,
// i.e. only 3 instead of 4 characters.
// https://en.wikipedia.org/wiki/ID3#ID3v2
// http://id3.org/Developer%20Information
const unsigned int kMinVersion = 3;
bool checkHeaderVersionSupported(
const TagLib::ID3v2::Header& header) {
if (header.majorVersion() < kMinVersion) {
kLogger.warning().noquote()
<< QString(QStringLiteral("ID3v2.%1 is only partially supported - please convert your file tags to at least ID3v2.%2"))
.arg(QString::number(header.majorVersion()), QString::number(kMinVersion));
return false;
} else {
return true;
}
}
// Preferred picture types for cover art sorted by priority
const std::array<TagLib::ID3v2::AttachedPictureFrame::Type, 4> kPreferredPictureTypes = {
TagLib::ID3v2::AttachedPictureFrame::FrontCover, // Front cover image of the album
TagLib::ID3v2::AttachedPictureFrame::Media, // Image from the album itself
TagLib::ID3v2::AttachedPictureFrame::Illustration, // Illustration related to the track
TagLib::ID3v2::AttachedPictureFrame::Other,
};
// http://id3.org/id3v2.3.0
// "TYER: The 'Year' frame is a numeric string with a year of the
// recording. This frame is always four characters long (until
// the year 10000)."
const QString kFormatTYER = QStringLiteral("yyyy");
// http://id3.org/id3v2.3.0
// "TDAT: The 'Date' frame is a numeric string in the DDMM
// format containing the date for the recording. This field
// is always four characters long."
const QString kFormatTDAT = QStringLiteral("ddMM");
// Owners of ID3v2 UFID frames.
// NOTE(uklotzde, 2019-09-28): This is the owner string for MusicBrainz
// as written by MusicBrainz Picard 2.1.3 although the mapping table
// doesn't mention any "http://" prefix.
// See also: https://picard.musicbrainz.org/docs/mappings
const QString kMusicBrainzOwner = QStringLiteral("http://musicbrainz.org");
// Serato frames
const QString kFrameDescriptionSeratoMarkers = QStringLiteral("Serato Markers_");
const QString kFrameDescriptionSeratoMarkersV2 = QStringLiteral("Serato Markers2");
// Returns the text of an ID3v2 frame as a string.
inline QString frameToQString(
const TagLib::ID3v2::Frame& frame) {
return toQString(frame.toString());
}
// Returns the first frame of an ID3v2 tag as a string.
QString firstNonEmptyFrameToQString(