tagparser/id3/id3v2frameids.cpp
Martchus d26e594777 Deprecate 'Year' in favor of 'RecordDate' and 'ReleaseDate', fix handling in ID3v2
1. Convert TYER and related fields of old ID3v2 versions to the new TDRC
  field and only expose that via the generic accessors.
2. When writing an old ID3v2 tag, convert TDRC back to the old fields.
3. One can still manually unset the via 1. auto-populated TDRC to disable 2.
   and write the old fields directly. So the automatic handling does not
   reduce the flexibility of the library.
4. Deprecate 'Year'; it is replaced by the already existing 'RecordDate'
   which is now supposed to be used everywhere where 'Year' was used before
5. Introduce 'ReleaseDate' to support this field which is supported in
   ID3v2.4.0 and Matroska via the generic accessors.
6. Use ISO format when converting tag values of the type DateTime to/from
   string. This is closer to what's used in ID3v2 tags internally. (The
   library still allows the old format as fallback when parsing for
   compatibility.)
2020-04-24 23:15:13 +02:00

184 lines
4.6 KiB
C++

#include "./id3v2frameids.h"
#include "../exceptions.h"
namespace TagParser {
/*!
* \brief Encapsulates the most common ID3v2 frame IDs and related functions.
*
* There are short frame IDs (used by the first version of ID3v2) and long
* frame IDs (used by newer versions of ID3v2).
*
* The short IDs start with "s" and the long IDs with "l". To convert between
* these IDs the functions convertToShortId() and convertToLongId() can be
* used.
*
* \sa
* - See https://id3.org/id3v2.3.0 for the specification of ID3v2.3.0 frame IDs.
* - See https://id3.org/id3v2.4.0-frames for the specification of ID3v2.4.0 frame IDs.
*/
namespace Id3v2FrameIds {
/*!
* \brief Converts the specified long frame ID to the equivalent short frame ID.
* \returns Returns the short ID if available; otherwise returns 0.
*/
std::uint32_t convertToShortId(std::uint32_t id)
{
switch (id) {
case lAlbum:
return sAlbum;
case lArtist:
return sArtist;
case lComment:
return sComment;
case lYear:
return sYear;
case lOriginalYear:
return sOriginalYear;
case lRecordingDates:
return sRecordingDates;
case lDate:
return sDate;
case lTime:
return sTime;
case lTitle:
return sTitle;
case lGenre:
return sGenre;
case lTrackPosition:
return sTrackPosition;
case lDiskPosition:
return sDiskPosition;
case lEncoder:
return sEncoder;
case lBpm:
return sBpm;
case lCover:
return sCover;
case lWriter:
return sWriter;
case lLength:
return sLength;
case lLanguage:
return sLanguage;
case lEncoderSettings:
return sEncoderSettings;
case lUnsynchronizedLyrics:
return sUnsynchronizedLyrics;
case lAlbumArtist:
return sAlbumArtist;
case lContentGroupDescription:
return sContentGroupDescription;
case lRecordLabel:
return sRecordLabel;
case lUserDefinedText:
return sUserDefinedText;
default:
return 0;
}
}
/*!
* \brief Converts the specified short frame ID to the equivalent long frame ID.
* \returns Returns the long ID if available; otherwise returns 0.
*/
std::uint32_t convertToLongId(std::uint32_t id)
{
switch (id) {
case sAlbum:
return lAlbum;
case sArtist:
return lArtist;
case sComment:
return lComment;
case sYear:
return lYear;
case sOriginalYear:
return lOriginalYear;
case sRecordingDates:
return lRecordingDates;
case sDate:
return lDate;
case sTime:
return lTime;
case sTitle:
return lTitle;
case sGenre:
return lGenre;
case sTrackPosition:
return lTrackPosition;
case sDiskPosition:
return lDiskPosition;
case sEncoder:
return lEncoder;
case sBpm:
return lBpm;
case sCover:
return lCover;
case sWriter:
return lWriter;
case sLength:
return lLength;
case sLanguage:
return lLanguage;
case sEncoderSettings:
return lEncoderSettings;
case sUnsynchronizedLyrics:
return lUnsynchronizedLyrics;
case sAlbumArtist:
return lAlbumArtist;
case sContentGroupDescription:
return lContentGroupDescription;
case sRecordLabel:
return lRecordLabel;
case sUserDefinedText:
return lUserDefinedText;
default:
return 0;
}
}
/*!
* \brief Returns whether \a id is only supported in ID3v2.3.x and older and therefore can not be used in an ID3v2.4.x tag.
* \remarks
* - This function is intended to show warnings. Unknown IDs will be treated as supported everywhere.
* - Any short ID is obviously not ID3v2.4.x compatible. Only long IDs are considered here. Short IDs need to be converted to
* long IDs before passing them to this function.
*/
bool isPreId3v24Id(uint32_t id)
{
switch (id) {
case lYear:
case lOriginalYear:
case lRecordingDates:
case lDate:
case lTime:
return true;
default:
return false;
}
}
/*!
* \brief Returns whether \a id is only supported inID3v2.4.x and therefore can not be used in older versions.
* \remarks This function is intended to show warnings. Unknown IDs will be treated as supported everywhere.
*/
bool isOnlyId3v24Id(uint32_t id)
{
switch (id) {
case lRecordingTime:
case lReleaseTime:
case lOriginalReleaseTime:
case lTaggingTime:
return true;
default:
return false;
}
}
} // namespace Id3v2FrameIds
} // namespace TagParser