From 3f5d5e3098db4a5bec5f70b0877c45e479eac758 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 8 Aug 2021 00:04:12 +0200 Subject: [PATCH] Add functions to return only tags which have actually been parsed --- CMakeLists.txt | 4 +-- mediafileinfo.cpp | 82 +++++++++++++++++++++++++++++++++++++++-------- mediafileinfo.h | 2 ++ 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dac822..1621845 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags") set(META_VERSION_MAJOR 10) -set(META_VERSION_MINOR 0) -set(META_VERSION_PATCH 1) +set(META_VERSION_MINOR 1) +set(META_VERSION_PATCH 0) set(META_REQUIRED_CPP_UNIT_VERSION 1.14.0) set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON) diff --git a/mediafileinfo.cpp b/mediafileinfo.cpp index 55b41d6..b996a32 100644 --- a/mediafileinfo.cpp +++ b/mediafileinfo.cpp @@ -1463,13 +1463,14 @@ bool MediaFileInfo::removeVorbisComment() /*! * \brief Stores all tags assigned to the current file in the specified vector. - * - * Previous elements of the vector will not be cleared. - * - * \remarks The MediaFileInfo keeps the ownership over the tags which will be - * destroyed when the MediaFileInfo is invalidated. + * \remarks + * - Previous elements of the vector will not be cleared. + * - 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. */ -void MediaFileInfo::tags(vector &tags) const +void MediaFileInfo::tags(std::vector &tags) const { if (hasId3v1Tag()) { tags.push_back(m_id3v1Tag.get()); @@ -1489,8 +1490,26 @@ void MediaFileInfo::tags(vector &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 MediaFileInfo::tags() const +{ + auto res = vector(); + tags(res); + return res; +} + /*! * \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 { @@ -1499,15 +1518,52 @@ bool MediaFileInfo::hasAnyTag() const } /*! - * \brief Returns all tags assigned to the current file. - * - * \remarks The MediaFileInfo keeps the ownership over the tags which will be - * destroyed when the MediaFileInfo is invalidated. + * \brief Returns all tags parsed from the current file. + * \remarks + * - Previous elements of the vector will not be cleared. + * - 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 MediaFileInfo::tags() const +void MediaFileInfo::parsedTags(std::vector &tags) const { - vector res; - tags(res); + if (hasId3v1Tag() && m_id3v1Tag->size()) { + tags.push_back(m_id3v1Tag.get()); + } + for (const unique_ptr &tag : m_id3v2Tags) { + if (tag->size()) { + tags.push_back(tag.get()); + } + } + if (m_containerFormat == ContainerFormat::Flac && m_singleTrack) { + if (auto *const vorbisComment = static_cast(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 MediaFileInfo::parsedTags() const +{ + auto res = vector(); + parsedTags(res); return res; } diff --git a/mediafileinfo.h b/mediafileinfo.h index 9b35d61..8a3a456 100644 --- a/mediafileinfo.h +++ b/mediafileinfo.h @@ -130,6 +130,8 @@ public: const std::vector> &id3v2Tags() const; void tags(std::vector &tags) const; std::vector tags() const; + void parsedTags(std::vector &tags) const; + std::vector parsedTags() const; Mp4Tag *mp4Tag() const; const std::vector> &matroskaTags() const; VorbisComment *vorbisComment() const;