Add functions to return only tags which have actually been parsed

This commit is contained in:
Martchus 2021-08-08 00:04:12 +02:00
parent e095c7d87d
commit 3f5d5e3098
3 changed files with 73 additions and 15 deletions

View File

@ -9,8 +9,8 @@ set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags") set(META_APP_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags")
set(META_VERSION_MAJOR 10) set(META_VERSION_MAJOR 10)
set(META_VERSION_MINOR 0) set(META_VERSION_MINOR 1)
set(META_VERSION_PATCH 1) set(META_VERSION_PATCH 0)
set(META_REQUIRED_CPP_UNIT_VERSION 1.14.0) set(META_REQUIRED_CPP_UNIT_VERSION 1.14.0)
set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON) set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON)

View File

@ -1463,13 +1463,14 @@ bool MediaFileInfo::removeVorbisComment()
/*! /*!
* \brief Stores all tags assigned to the current file in the specified vector. * \brief Stores all tags assigned to the current file in the specified vector.
* * \remarks
* Previous elements of the vector will not be cleared. * - Previous elements of the vector will not be cleared.
* * - Includes tags which have only been assigned, e.g. via createAppropriateTags(), even if
* \remarks The MediaFileInfo keeps the ownership over the tags which will be * those tags have not been stored to disk yet via applyChanges().
* destroyed when the MediaFileInfo is invalidated. * - The MediaFileInfo keeps the ownership over the tags which will be
* destroyed when the MediaFileInfo is invalidated.
*/ */
void MediaFileInfo::tags(vector<Tag *> &tags) const void MediaFileInfo::tags(std::vector<Tag *> &tags) const
{ {
if (hasId3v1Tag()) { if (hasId3v1Tag()) {
tags.push_back(m_id3v1Tag.get()); tags.push_back(m_id3v1Tag.get());
@ -1489,8 +1490,26 @@ void MediaFileInfo::tags(vector<Tag *> &tags) const
} }
} }
/*!
* \brief Returns all tags assigned to the current file.
* \remarks
* - Includes tags which have only been assigned, e.g. via createAppropriateTags(), even if
* those tags have not been stored to disk yet via applyChanges().
* - The MediaFileInfo keeps the ownership over the tags which will be
* destroyed when the MediaFileInfo is invalidated.
*/
vector<Tag *> MediaFileInfo::tags() const
{
auto res = vector<Tag *>();
tags(res);
return res;
}
/*! /*!
* \brief Returns an indication whether a tag of any format is assigned. * \brief Returns an indication whether a tag of any format is assigned.
* \remarks
* - Includes tags which have only been assigned, e.g. via createAppropriateTags(), even if
* those tags have not been stored to disk yet via applyChanges().
*/ */
bool MediaFileInfo::hasAnyTag() const bool MediaFileInfo::hasAnyTag() const
{ {
@ -1499,15 +1518,52 @@ bool MediaFileInfo::hasAnyTag() const
} }
/*! /*!
* \brief Returns all tags assigned to the current file. * \brief Returns all tags parsed from the current file.
* * \remarks
* \remarks The MediaFileInfo keeps the ownership over the tags which will be * - Previous elements of the vector will not be cleared.
* destroyed when the MediaFileInfo is invalidated. * - Does **not** include tags which have been assigned, e.g. via createAppropriateTags() but
* have not been stored to disk yet via applyChanges().
* - The MediaFileInfo keeps the ownership over the tags which will be
* destroyed when the MediaFileInfo is invalidated.
*/ */
vector<Tag *> MediaFileInfo::tags() const void MediaFileInfo::parsedTags(std::vector<Tag *> &tags) const
{ {
vector<Tag *> res; if (hasId3v1Tag() && m_id3v1Tag->size()) {
tags(res); tags.push_back(m_id3v1Tag.get());
}
for (const unique_ptr<Id3v2Tag> &tag : m_id3v2Tags) {
if (tag->size()) {
tags.push_back(tag.get());
}
}
if (m_containerFormat == ContainerFormat::Flac && m_singleTrack) {
if (auto *const vorbisComment = static_cast<const FlacStream *>(m_singleTrack.get())->vorbisComment()) {
if (vorbisComment->size()) {
tags.push_back(vorbisComment);
}
}
}
if (m_container) {
for (size_t i = 0, count = m_container->tagCount(); i < count; ++i) {
if (auto *const tag = m_container->tag(i); tag->size()) {
tags.push_back(tag);
}
}
}
}
/*!
* \brief Returns all tags parsed from the current file.
* \remarks
* - Does **not** include tags which have been assigned, e.g. via createAppropriateTags() but
* have not been stored to disk yet via applyChanges().
* - The MediaFileInfo keeps the ownership over the tags which will be
* destroyed when the MediaFileInfo is invalidated.
*/
std::vector<Tag *> MediaFileInfo::parsedTags() const
{
auto res = vector<Tag *>();
parsedTags(res);
return res; return res;
} }

View File

@ -130,6 +130,8 @@ public:
const std::vector<std::unique_ptr<Id3v2Tag>> &id3v2Tags() const; const std::vector<std::unique_ptr<Id3v2Tag>> &id3v2Tags() const;
void tags(std::vector<Tag *> &tags) const; void tags(std::vector<Tag *> &tags) const;
std::vector<Tag *> tags() const; std::vector<Tag *> tags() const;
void parsedTags(std::vector<Tag *> &tags) const;
std::vector<Tag *> parsedTags() const;
Mp4Tag *mp4Tag() const; Mp4Tag *mp4Tag() const;
const std::vector<std::unique_ptr<MatroskaTag>> &matroskaTags() const; const std::vector<std::unique_ptr<MatroskaTag>> &matroskaTags() const;
VorbisComment *vorbisComment() const; VorbisComment *vorbisComment() const;