Support tag language

This commit is contained in:
complexlogic
2023-10-08 08:11:01 -07:00
committed by Urs Fleisch
parent b4e79a4a27
commit 6342f00e8b
7 changed files with 64 additions and 13 deletions

View File

@ -44,6 +44,8 @@ int main(int argc, char *argv[])
PRINT_PRETTY("Target Type Value",
targetTypeValue == 0 ? "None" : TagLib::Utils::formatString("%i", targetTypeValue).toCString(false)
);
const TagLib::String &language = t->language();
PRINT_PRETTY("Language", !language.isEmpty() ? language.toCString(false) : "Not set");
printf("\n");
}

View File

@ -23,6 +23,7 @@ int main(int argc, char *argv[])
simpleTag->setName("Test Name 1");
simpleTag->setTargetTypeValue(TagLib::Matroska::SimpleTag::TargetTypeValue::Track);
simpleTag->setValue("Test Value 1");
simpleTag->setLanguage("en");
tag->addSimpleTag(simpleTag);
simpleTag = new TagLib::Matroska::SimpleTagString();

View File

@ -59,16 +59,18 @@ namespace TagLib {
};
namespace ElementIDs {
inline constexpr Element::Id EBMLHeader = 0x1A45DFA3;
inline constexpr Element::Id MkSegment = 0x18538067;
inline constexpr Element::Id MkTags = 0x1254C367;
inline constexpr Element::Id MkTag = 0x7373;
inline constexpr Element::Id MkTagTargets = 0x63C0;
inline constexpr Element::Id MkTagTargetTypeValue = 0x68CA;
inline constexpr Element::Id MkSimpleTag = 0x67C8;
inline constexpr Element::Id MkTagName = 0x45A3;
inline constexpr Element::Id MkTagLanguage = 0x447A;
inline constexpr Element::Id MkTagString = 0x4487;
inline constexpr Element::Id EBMLHeader = 0x1A45DFA3;
inline constexpr Element::Id MkSegment = 0x18538067;
inline constexpr Element::Id MkTags = 0x1254C367;
inline constexpr Element::Id MkTag = 0x7373;
inline constexpr Element::Id MkTagTargets = 0x63C0;
inline constexpr Element::Id MkTagTargetTypeValue = 0x68CA;
inline constexpr Element::Id MkSimpleTag = 0x67C8;
inline constexpr Element::Id MkTagName = 0x45A3;
inline constexpr Element::Id MkTagLanguage = 0x447A;
inline constexpr Element::Id MkTagString = 0x4487;
inline constexpr Element::Id MkTagsTagLanguage = 0x447A;
inline constexpr Element::Id MkTagsLanguageDefault = 0x4484;
}
}
}

View File

@ -71,6 +71,8 @@ Matroska::Tag* EBML::MkTags::parse()
const String *tagName = nullptr;
const String *tagValueString = nullptr;
const ByteVector *tagValueBinary = nullptr;
const String *language = nullptr;
bool defaultLanguageFlag = true;
for (auto simpleTagChild : *simpleTag) {
Id id = simpleTagChild->getId();
@ -78,6 +80,10 @@ Matroska::Tag* EBML::MkTags::parse()
tagName = &(static_cast<UTF8StringElement*>(simpleTagChild)->getValue());
else if (id == ElementIDs::MkTagString && !tagValueString)
tagValueString = &(static_cast<UTF8StringElement*>(simpleTagChild)->getValue());
else if (id == ElementIDs::MkTagsTagLanguage && !language)
language = &(static_cast<Latin1StringElement*>(simpleTagChild)->getValue());
else if (id == ElementIDs::MkTagsLanguageDefault)
defaultLanguageFlag = static_cast<UIntElement*>(simpleTagChild)->getValue() ? true : false;
}
if (!tagName || (tagValueString && tagValueBinary) || (!tagValueString && !tagValueBinary))
continue;
@ -97,6 +103,9 @@ Matroska::Tag* EBML::MkTags::parse()
sTag = sTagBinary;
}
sTag->setName(*tagName);
if (language)
sTag->setLanguage(*language);
sTag->setDefaultLanguageFlag(defaultLanguageFlag);
mTag->addSimpleTag(sTag);
}
}

View File

@ -31,6 +31,8 @@ class Matroska::SimpleTag::SimpleTagPrivate
SimpleTagPrivate() = default;
SimpleTag::TargetTypeValue targetTypeValue = TargetTypeValue::None;
String name;
String language;
bool defaultLanguageFlag = true;
};
@ -73,6 +75,26 @@ const String& Matroska::SimpleTag::name() const
return d->name;
}
const String& Matroska::SimpleTag::language() const
{
return d->language;
}
void Matroska::SimpleTag::setLanguage(const String &language)
{
d->language = language;
}
bool Matroska::SimpleTag::defaultLanguageFlag() const
{
return d->defaultLanguageFlag;
}
void Matroska::SimpleTag::setDefaultLanguageFlag(bool flag)
{
d->defaultLanguageFlag = flag;
}
void Matroska::SimpleTag::setName(const String &name)
{
d->name = name;

View File

@ -44,8 +44,12 @@ namespace TagLib {
};
const String& name() const;
TargetTypeValue targetTypeValue() const;
void setTargetTypeValue(TargetTypeValue targetTypeValue);
const String& language() const;
bool defaultLanguageFlag() const;
void setName(const String &name);
void setTargetTypeValue(TargetTypeValue targetTypeValue);
void setLanguage(const String &language);
void setDefaultLanguageFlag(bool flag);
virtual ~SimpleTag();
private:

View File

@ -210,7 +210,7 @@ ByteVector Matroska::Tag::render()
auto targetTypeValue = frontTag->targetTypeValue();
auto tag = new EBML::MasterElement(EBML::ElementIDs::MkTag);
// Build <Tag Targets element>
// Build <Tag Targets> element
auto targets = new EBML::MasterElement(EBML::ElementIDs::MkTagTargets);
if (targetTypeValue != Matroska::SimpleTag::TargetTypeValue::None) {
auto element = new EBML::UIntElement(EBML::ElementIDs::MkTagTargetTypeValue);
@ -226,6 +226,7 @@ ByteVector Matroska::Tag::render()
tagName->setValue(simpleTag->name());
t->appendElement(tagName);
// Tag Value
Matroska::SimpleTagString *tStr = nullptr;
Matroska::SimpleTagBinary *tBin = nullptr;
if((tStr = dynamic_cast<Matroska::SimpleTagString*>(simpleTag))) {
@ -237,7 +238,17 @@ ByteVector Matroska::Tag::render()
// Todo
}
// Todo: language
// Language
auto language = new EBML::Latin1StringElement(EBML::ElementIDs::MkTagsTagLanguage);
const String &lang = simpleTag->language();
language->setValue(!lang.isEmpty() ? lang : "und");
t->appendElement(language);
// Default language flag
auto dlf = new EBML::UIntElement(EBML::ElementIDs::MkTagsLanguageDefault);
dlf->setValue(simpleTag->defaultLanguageFlag() ? 1 : 0);
t->appendElement(dlf);
tag->appendElement(t);
}
tags.appendElement(tag);