4#include "../diagnostics.h"
6#include <initializer_list>
8#include <unordered_map>
22 using namespace MatroskaTagIds;
25 return std::string(
artist());
27 return std::string(
album());
35 return std::string(
title());
37 return std::string(
genre());
47 return std::string(
bpm());
49 return std::string(
bps());
51 return std::string(
rating());
55 return std::string(
lyrics());
57 return std::string(
label());
59 return std::string(
actor());
95 return std::string(
actor());
127 return std::string(
mood());
143 return std::string(
period());
167 return std::string(
tuning());
169 return std::string(
isrc());
171 return std::string(
mcdi());
173 return std::string(
isbn());
181 return std::string(
lccn());
183 return std::string(
imdb());
185 return std::string(
tmdb());
187 return std::string(
tvdb());
207 return std::string();
213 using namespace MatroskaTagIds;
214 static const std::unordered_map<std::string_view, KnownField> fieldMap({
331 static const string context(
"parsing Matroska tag");
333 tagElement.
parse(diag);
334 if (tagElement.
totalSize() > numeric_limits<std::uint32_t>::max()) {
342 switch (child->id()) {
346 field.reparse(*child, diag,
true);
348 auto normalizedId = field.id();
351 field.id() = std::move(normalizedId);
354 fields().emplace(field.id(), std::move(field));
360 parseTargets(*child, diag);
375 static const string context(
"parsing targets of Matroska tag");
377 bool targetTypeValueFound =
false;
378 bool targetTypeFound =
false;
379 targetsElement.
parse(diag);
383 }
catch (
const Failure &) {
384 diag.emplace_back(
DiagLevel::Critical,
"Unable to parse children of Targets element.", context);
387 switch (child->id()) {
389 if (!targetTypeValueFound) {
391 targetTypeValueFound =
true;
394 DiagLevel::Warning,
"Targets element contains multiple TargetTypeValue elements. Surplus elements will be ignored.", context);
398 if (!targetTypeFound) {
400 targetTypeFound =
true;
403 DiagLevel::Warning,
"Targets element contains multiple TargetType elements. Surplus elements will be ignored.", context);
419 diag.emplace_back(
DiagLevel::Warning,
"Targets element contains unknown element. It will be ignored.", context);
438MatroskaTagMaker::MatroskaTagMaker(MatroskaTag &tag, Diagnostics &diag)
443 if (m_tag.target().level() != 50) {
447 if (!m_tag.target().levelName().empty()) {
451 for (
const auto &v : initializer_list<vector<std::uint64_t>>{
452 m_tag.target().tracks(), m_tag.target().editions(), m_tag.target().chapters(), m_tag.target().attachments() }) {
460 m_maker.reserve(m_tag.fields().size());
461 m_simpleTagsSize = 0;
462 for (
auto &pair : m_tag.fields()) {
463 if (pair.second.value().isNull()) {
467 m_maker.emplace_back(pair.second.prepareMaking(diag));
468 m_simpleTagsSize += m_maker.back().requiredSize();
469 }
catch (
const Failure &) {
472 m_tagSize += m_simpleTagsSize;
488 stream.write(buff, 2);
490 stream.write(buff, len);
493 stream.write(buff, 2);
495 stream.write(buff, len);
497 if (t.
level() != 50) {
500 stream.write(buff, 2);
502 stream.put(
static_cast<char>(0x80 | len));
503 stream.write(buff, len);
508 stream.write(buff, 2);
510 stream.write(buff, len);
511 stream.write(t.
levelName().c_str(),
static_cast<std::streamsize
>(t.
levelName().size()));
514 using p = pair<std::uint16_t, vector<std::uint64_t>>;
517 if (!pair.second.empty()) {
518 BE::getBytes(pair.first, buff);
519 for (
auto uid : pair.second) {
521 *(buff + 2) =
static_cast<char>(0x80 | len);
522 stream.write(buff, 3 + len);
527 for (
const auto &maker : m_maker) {
The Diagnostics class is a container for DiagMessage.
The EbmlElement class helps to parse EBML files such as Matroska files.
static std::uint8_t makeUInteger(std::uint64_t value, char *buff)
Writes value to buff.
static std::uint8_t calculateSizeDenotationLength(std::uint64_t size)
Returns the length of the size denotation for the specified size in byte.
static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff)
Makes the size denotation for the specified size and stores it to buff.
static std::uint8_t calculateUIntegerLength(std::uint64_t integer)
Returns the length of the specified unsigned integer in byte.
The class inherits from std::exception and serves as base class for exceptions thrown by the elements...
typename FieldMapBasedTagTraits< MatroskaTag >::FieldType::IdentifierType IdentifierType
const std::multimap< IdentifierType, FieldType, Compare > & fields() const
Returns the fields of the tag by providing direct access to the field map of the tag.
KnownField knownField(const IdentifierType &id) const
Returns the field for the specified ID.
ImplementationType * nextSibling()
Returns the next sibling of the element.
ImplementationType * firstChild()
Returns the first child of the element.
std::uint64_t totalSize() const
Returns the total size of the element.
void parse(Diagnostics &diag)
Parses the header information of the element which is read from the related stream at the start offse...
The MatroskaTagField class is used by MatroskaTag to store the fields.
static void normalizeId(std::string &id)
Ensures the specified id is upper-case as recommended by the Matroska spec.
void make(std::ostream &stream) const
Saves the tag (specified when constructing the object) to the specified stream (makes a "Tag"-element...
void parse(EbmlElement &tagElement, Diagnostics &diag)
Parses tag information from the specified tagElement.
void parse2(EbmlElement &tagElement, MatroskaTagFlags flags, Diagnostics &diag)
Parses tag information from the specified tagElement.
IdentifierType internallyGetFieldId(KnownField field) const
KnownField internallyGetKnownField(const IdentifierType &id) const
This exception is thrown when the an operation is invoked that has not been implemented yet.
The TagTarget class specifies the target of a tag.
const IdContainerType & tracks() const
Returns the tracks.
const IdContainerType & chapters() const
Returns the chapters.
std::uint64_t level() const
Returns the level.
const std::string & levelName() const
Returns the level name.
const IdContainerType & editions() const
Returns the editions.
void clear()
Clears the TagTarget.
const IdContainerType & attachments() const
Returns the attachments.
void setLevel(std::uint64_t level)
Sets the level.
void setLevelName(const std::string &levelName)
Sets the level name.
const TagTarget & target() const
constexpr TAG_PARSER_EXPORT std::string_view dateDigitized()
constexpr TAG_PARSER_EXPORT std::string_view lccn()
constexpr TAG_PARSER_EXPORT std::string_view bps()
constexpr TAG_PARSER_EXPORT std::string_view tvdb()
constexpr TAG_PARSER_EXPORT std::string_view dateWritten()
constexpr TAG_PARSER_EXPORT std::string_view accompaniment()
constexpr TAG_PARSER_EXPORT std::string_view synopsis()
constexpr TAG_PARSER_EXPORT std::string_view rating()
constexpr TAG_PARSER_EXPORT std::string_view album()
constexpr TAG_PARSER_EXPORT std::string_view soundEngineer()
constexpr TAG_PARSER_EXPORT std::string_view costumeDesigner()
constexpr TAG_PARSER_EXPORT std::string_view encoderSettings()
constexpr TAG_PARSER_EXPORT std::string_view mixedBy()
constexpr TAG_PARSER_EXPORT std::string_view contentType()
constexpr TAG_PARSER_EXPORT std::string_view originalMediaType()
constexpr TAG_PARSER_EXPORT std::string_view choregrapher()
constexpr TAG_PARSER_EXPORT std::string_view encodedBy()
constexpr TAG_PARSER_EXPORT std::string_view subject()
constexpr TAG_PARSER_EXPORT std::string_view purchaseCurrency()
constexpr TAG_PARSER_EXPORT std::string_view tuning()
constexpr TAG_PARSER_EXPORT std::string_view masteredBy()
constexpr TAG_PARSER_EXPORT std::string_view distributedBy()
constexpr TAG_PARSER_EXPORT std::string_view editedBy()
constexpr TAG_PARSER_EXPORT std::string_view description()
constexpr TAG_PARSER_EXPORT std::string_view directorOfPhotography()
constexpr TAG_PARSER_EXPORT std::string_view thanksTo()
constexpr TAG_PARSER_EXPORT std::string_view measure()
constexpr TAG_PARSER_EXPORT std::string_view publisher()
constexpr TAG_PARSER_EXPORT std::string_view purchaseOwner()
constexpr TAG_PARSER_EXPORT std::string_view isrc()
constexpr TAG_PARSER_EXPORT std::string_view executiveProducer()
constexpr TAG_PARSER_EXPORT std::string_view title()
constexpr TAG_PARSER_EXPORT std::string_view comment()
constexpr TAG_PARSER_EXPORT std::string_view language()
constexpr TAG_PARSER_EXPORT std::string_view actor()
constexpr TAG_PARSER_EXPORT std::string_view composer()
constexpr TAG_PARSER_EXPORT std::string_view partNumber()
constexpr TAG_PARSER_EXPORT std::string_view lawRating()
constexpr TAG_PARSER_EXPORT std::string_view conductor()
constexpr TAG_PARSER_EXPORT std::string_view imdb()
constexpr TAG_PARSER_EXPORT std::string_view dateTagged()
constexpr TAG_PARSER_EXPORT std::string_view summary()
constexpr TAG_PARSER_EXPORT std::string_view productionCopyright()
constexpr TAG_PARSER_EXPORT std::string_view bpm()
constexpr TAG_PARSER_EXPORT std::string_view artDirector()
constexpr TAG_PARSER_EXPORT std::string_view tmdb()
constexpr TAG_PARSER_EXPORT std::string_view purchaseInfo()
constexpr TAG_PARSER_EXPORT std::string_view composerNationality()
constexpr TAG_PARSER_EXPORT std::string_view termsOfUse()
constexpr TAG_PARSER_EXPORT std::string_view director()
constexpr TAG_PARSER_EXPORT std::string_view screenplayBy()
constexpr TAG_PARSER_EXPORT std::string_view arranger()
constexpr TAG_PARSER_EXPORT std::string_view initialKey()
constexpr TAG_PARSER_EXPORT std::string_view purchaseItem()
constexpr TAG_PARSER_EXPORT std::string_view period()
constexpr TAG_PARSER_EXPORT std::string_view producer()
constexpr TAG_PARSER_EXPORT std::string_view genre()
constexpr TAG_PARSER_EXPORT std::string_view mcdi()
constexpr TAG_PARSER_EXPORT std::string_view duration()
constexpr TAG_PARSER_EXPORT std::string_view artist()
constexpr TAG_PARSER_EXPORT std::string_view isbn()
constexpr TAG_PARSER_EXPORT std::string_view copyright()
constexpr TAG_PARSER_EXPORT std::string_view datePurchased()
constexpr TAG_PARSER_EXPORT std::string_view dateEncoded()
constexpr TAG_PARSER_EXPORT std::string_view assistantDirector()
constexpr TAG_PARSER_EXPORT std::string_view leadPerformer()
constexpr TAG_PARSER_EXPORT std::string_view lyrics()
constexpr TAG_PARSER_EXPORT std::string_view encoder()
constexpr TAG_PARSER_EXPORT std::string_view writtenBy()
constexpr TAG_PARSER_EXPORT std::string_view playCounter()
constexpr TAG_PARSER_EXPORT std::string_view subtitle()
constexpr TAG_PARSER_EXPORT std::string_view productionDesigner()
constexpr TAG_PARSER_EXPORT std::string_view purchasePrice()
constexpr TAG_PARSER_EXPORT std::string_view keywords()
constexpr TAG_PARSER_EXPORT std::string_view coproducer()
constexpr TAG_PARSER_EXPORT std::string_view labelCode()
constexpr TAG_PARSER_EXPORT std::string_view dateRelease()
constexpr TAG_PARSER_EXPORT std::string_view license()
constexpr TAG_PARSER_EXPORT std::string_view totalParts()
constexpr TAG_PARSER_EXPORT std::string_view dateRecorded()
constexpr TAG_PARSER_EXPORT std::string_view remixedBy()
constexpr TAG_PARSER_EXPORT std::string_view catalogNumber()
constexpr TAG_PARSER_EXPORT std::string_view barcode()
constexpr TAG_PARSER_EXPORT std::string_view lyricist()
constexpr TAG_PARSER_EXPORT std::string_view compositionLocation()
constexpr TAG_PARSER_EXPORT std::string_view character()
constexpr TAG_PARSER_EXPORT std::string_view productionStudio()
constexpr TAG_PARSER_EXPORT std::string_view mood()
constexpr TAG_PARSER_EXPORT std::string_view recordingLocation()
Contains all classes and functions of the TagInfo library.
KnownField
Specifies the field.
MatroskaTagFlags
The MatroskaTagFlags enum specifies flags which controls parsing and making of Matroska tags.