Tag Parser 12.3.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
tag.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_TAG_H
2#define TAG_PARSER_TAG_H
3
4#include "./tagtarget.h"
5#include "./tagtype.h"
6#include "./tagvalue.h"
7
8#include <c++utilities/io/binaryreader.h>
9
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <type_traits>
14
15namespace TagParser {
16
29enum class KnownField : unsigned int {
30 Invalid = std::numeric_limits<unsigned int>::max(),
31 Title = 0,
32 Album,
33 Artist,
34 Genre,
35 Comment,
36 Bpm,
37 Bps,
38 Lyricist,
43 Encoder,
46 Length,
47 Language,
49 Lyrics,
51 Grouping,
53 Cover,
54 Composer,
55 Rating,
57 Vendor,
62 Arranger,
63 Conductor,
64 Director,
72 Actor,
73 Character,
74 WrittenBy,
76 EditedBy,
77 Producer,
82 EncodedBy,
83 MixedBy,
84 RemixedBy,
86 ThanksTo,
87 Publisher,
88 Mood,
91 Subject,
92 Keywords,
93 Summary,
94 Synopsis,
96 Period,
97 LawRating,
108 Measure,
109 Tuning,
110 ISRC,
111 MCDI,
112 ISBN,
113 Barcode,
115 LabelCode,
116 LCCN,
117 IMDB,
118 TMDB,
119 TVDB,
125 Copyright,
127 License,
128 TermsOfUse,
131};
132
137
142
146constexpr unsigned int knownFieldArraySize = static_cast<unsigned int>(lastKnownField) + 1;
147
152{
153 CPP_UTILITIES_UNUSED(field)
154 return false;
155}
156
161{
162 const auto next = field == lastKnownField ? KnownField::Invalid : static_cast<KnownField>(static_cast<int>(field) + 1);
163 return isKnownFieldDeprecated(next) ? nextKnownField(next) : next;
164}
165
166struct TagPrivate;
167
168class TAG_PARSER_EXPORT Tag {
169public:
170 virtual ~Tag();
171
172 virtual TagType type() const;
173 virtual std::string_view typeName() const;
174 std::string toString() const;
175 virtual TagTextEncoding proposedTextEncoding() const;
176 virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
177 virtual const TagValue &value(KnownField field) const = 0;
178 virtual std::vector<const TagValue *> values(KnownField field) const;
179 virtual bool setValue(KnownField field, const TagValue &value) = 0;
180 virtual bool setValues(KnownField field, const std::vector<TagValue> &values);
181 virtual bool hasField(KnownField field) const = 0;
182 virtual void removeAllFields() = 0;
183 const std::string &version() const;
184 std::uint64_t size() const;
185 virtual bool supportsTarget() const;
186 const TagTarget &target() const;
187 TagTarget &target();
188 void setTarget(const TagTarget &target);
189 virtual TagTargetLevel targetLevel() const;
190 std::string_view targetLevelName() const;
191 bool isTargetingLevel(TagTargetLevel tagTargetLevel) const;
192 std::string targetString() const;
193 virtual std::size_t fieldCount() const = 0;
194 virtual bool supportsField(KnownField field) const = 0;
195 virtual TagDataType proposedDataType(KnownField field) const;
196 virtual bool supportsDescription(KnownField field) const;
197 virtual bool supportsMimeType(KnownField field) const;
198 virtual bool supportsMultipleValues(KnownField field) const;
199 virtual std::size_t insertValues(const Tag &from, bool overwrite);
201
202protected:
203 Tag();
204
205 std::string m_version;
206 std::uint64_t m_size;
207 std::unique_ptr<TagPrivate> m_p;
209};
210
211inline TagType Tag::type() const
212{
214}
215
216inline std::string_view Tag::typeName() const
217{
218 return "unspecified";
219}
220
225
226inline bool Tag::canEncodingBeUsed(TagTextEncoding encoding) const
227{
228 return encoding == proposedTextEncoding();
229}
230
231inline const std::string &Tag::version() const
232{
233 return m_version;
234}
235
236inline std::uint64_t Tag::size() const
237{
238 return m_size;
239}
240
241inline bool Tag::supportsTarget() const
242{
243 return false;
244}
245
246inline const TagTarget &Tag::target() const
247{
248 return m_target;
249}
250
252{
253 return m_target;
254}
255
256inline void Tag::setTarget(const TagTarget &target)
257{
259}
260
265
266inline std::string_view Tag::targetLevelName() const
267{
268 return supportsTarget() ? tagTargetLevelName(targetLevel()) : std::string_view();
269}
270
271inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const
272{
273 return !supportsTarget() || static_cast<std::uint8_t>(targetLevel()) >= static_cast<std::uint8_t>(tagTargetLevel);
274}
275
276inline std::string Tag::targetString() const
277{
278 return target().toString(targetLevel());
279}
280
282{
283 switch (field) {
284 case KnownField::Bpm:
285 case KnownField::Bps:
299 case KnownField::MCDI:
300 return TagDataType::Binary;
302 // could also be a plain integer but popularity should generally be used (and can be converted
303 // to an integer)
306 // not supported
308 default:
309 return TagDataType::Text;
310 }
311}
312
314{
315 return false;
316}
317
319{
320 return false;
321}
322
324{
325 return false;
326}
327
328} // namespace TagParser
329
330#endif // TAG_PARSER_TAG_H
The TagTarget class specifies the target of a tag.
std::string toString(const std::function< TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition tagtarget.h:217
The TagValue class wraps values of different types.
The Tag class is used to store, read and write tag information.
virtual TagTargetLevel targetLevel() const
Returns the name of the current tag target level.
Definition tag.h:261
virtual bool setValue(KnownField field, const TagValue &value)=0
Assigns the given value to the specified field.
virtual void ensureTextValuesAreProperlyEncoded()=0
Ensures the encoding of all assigned text values is supported by the tag by converting the character ...
std::string m_version
Definition tag.h:205
std::uint64_t m_size
Definition tag.h:206
std::uint64_t size() const
Returns the size the tag within the file it is parsed from in bytes.
Definition tag.h:236
void setTarget(const TagTarget &target)
Sets the target of tag.
Definition tag.h:256
std::unique_ptr< TagPrivate > m_p
Definition tag.h:207
virtual bool canEncodingBeUsed(TagTextEncoding encoding) const
Returns an indication whether the specified encoding can be used to provide string values for the tag...
Definition tag.h:226
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition tag.h:241
std::string_view targetLevelName() const
Returns the name of the current target level.
Definition tag.h:266
virtual TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition tag.h:221
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition tag.h:216
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
Definition tag.h:211
TagTarget m_target
Definition tag.h:208
const TagTarget & target() const
Definition tag.h:246
virtual bool supportsField(KnownField field) const =0
Returns an indication whether the specified field is supported by the tag.
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
Definition tag.h:281
virtual bool supportsMultipleValues(KnownField field) const
Returns an indications whether the specified field supports multiple values.
Definition tag.h:323
virtual void removeAllFields()=0
Removes all fields from the tag.
bool isTargetingLevel(TagTargetLevel tagTargetLevel) const
Returns whether the tag is targeting the specified tagTargetLevel.
Definition tag.h:271
const std::string & version() const
Returns the version of the tag as std::string.
Definition tag.h:231
virtual bool hasField(KnownField field) const =0
Returns an indication whether the specified field is present.
virtual bool supportsMimeType(KnownField field) const
Returns an indications whether the specified field supports mime types.
Definition tag.h:318
virtual bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition tag.h:313
virtual const TagValue & value(KnownField field) const =0
Returns the value of the specified field.
virtual std::size_t fieldCount() const =0
Returns the number of present fields.
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition tag.h:276
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
KnownField
Specifies the field.
Definition tag.h:29
TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
Returns a string representation for the specified tagTargetLevel.
Definition tagtarget.cpp:17
constexpr unsigned int knownFieldArraySize
The number of valid entries in the TagParser::KnownField enum.
Definition tag.h:146
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition tagtarget.h:16
constexpr KnownField nextKnownField(KnownField field)
Returns the next known field skipping any deprecated fields.
Definition tag.h:160
TagTextEncoding
Specifies the text encoding.
Definition tagvalue.h:29
constexpr KnownField lastKnownField
The last valid entry in the TagParser::KnownField enum.
Definition tag.h:141
TagType
Specifies the tag type.
Definition tagtype.h:11
constexpr KnownField firstKnownField
The first valid entry in the TagParser::KnownField enum.
Definition tag.h:136
constexpr bool isKnownFieldDeprecated(KnownField field)
Returns whether the specified field is deprecated and should not be used anymore.
Definition tag.h:151
TagDataType
Specifies the data type.
Definition tagvalue.h:119