@@ -333,7 +333,7 @@ namespace
333333 );
334334 if (it != simpleTagsTranslation.end ())
335335 return { std::get<1 >(*it), std::get<2 >(*it), std::get<3 >(*it) };
336- if (!key.isEmpty () && !key. startsWith ( " _ " ) )
336+ if (!key.isEmpty ())
337337 return { key, Matroska::SimpleTag::TargetTypeValue::Track, false };
338338 return { String (), Matroska::SimpleTag::TargetTypeValue::None, false };
339339 }
@@ -352,8 +352,7 @@ namespace
352352 return it != simpleTagsTranslation.end ()
353353 ? String (std::get<0 >(*it), String::UTF8)
354354 : (targetTypeValue == Matroska::SimpleTag::TargetTypeValue::Track ||
355- targetTypeValue == Matroska::SimpleTag::TargetTypeValue::None) &&
356- !name.startsWith (" _" )
355+ targetTypeValue == Matroska::SimpleTag::TargetTypeValue::None)
357356 ? name
358357 : String ();
359358 }
@@ -399,6 +398,21 @@ String Matroska::Tag::TagPrivate::getTag(const String &key) const
399398 return it != tags.end () ? it->toString () : String ();
400399}
401400
401+ PropertyMap Matroska::Tag::properties () const
402+ {
403+ PropertyMap properties;
404+ for (const auto &simpleTag : std::as_const (d->tags )) {
405+ if (simpleTag.type () == SimpleTag::StringType) {
406+ String key = translateTag (simpleTag.name (), simpleTag.targetTypeValue ());
407+ if (!key.isEmpty ())
408+ properties[key].append (simpleTag.toString ());
409+ else
410+ properties.addUnsupportedData (simpleTag.name ());
411+ }
412+ }
413+ return properties;
414+ }
415+
402416PropertyMap Matroska::Tag::setProperties (const PropertyMap &propertyMap)
403417{
404418 // Remove all simple tags which would be returned in properties()
@@ -442,7 +456,8 @@ StringList Matroska::Tag::complexPropertyKeys() const
442456{
443457 StringList keys;
444458 for (const SimpleTag &t : std::as_const (d->tags )) {
445- if (t.type () == SimpleTag::BinaryType) {
459+ if (t.type () != SimpleTag::StringType ||
460+ translateTag (t.name (), t.targetTypeValue ()).isEmpty ()) {
446461 keys.append (t.name ());
447462 }
448463 }
@@ -454,9 +469,16 @@ List<VariantMap> Matroska::Tag::complexProperties(const String& key) const
454469 List<VariantMap> props;
455470 if (key.upper () != " PICTURE" ) { // Pictures are handled at the file level
456471 for (const SimpleTag &t : std::as_const (d->tags )) {
457- if (t.type () == SimpleTag::BinaryType) {
472+ if (t.name () == key &&
473+ (t.type () != SimpleTag::StringType ||
474+ translateTag (t.name (), t.targetTypeValue ()).isEmpty ())) {
458475 VariantMap property;
459- property.insert (" data" , t.toByteVector ());
476+ if (t.type () != SimpleTag::StringType) {
477+ property.insert (" data" , t.toByteVector ());
478+ }
479+ else {
480+ property.insert (" value" , t.toString ());
481+ }
460482 property.insert (" name" , t.name ());
461483 property.insert (" targetTypeValue" , t.targetTypeValue ());
462484 property.insert (" language" , t.language ());
@@ -476,36 +498,39 @@ bool Matroska::Tag::setComplexProperties(const String& key, const List<VariantMa
476498 }
477499 d->removeSimpleTags (
478500 [&key](const SimpleTag &t) {
479- return t.name () == key && t.type () == SimpleTag::BinaryType;
501+ return t.name () == key &&
502+ (t.type () != SimpleTag::StringType ||
503+ translateTag (t.name (), t.targetTypeValue ()).isEmpty ());
480504 }
481505 );
482506 bool result = false ;
483507 for (const auto &property : value) {
484- if (property.value (" name" ).value <String>() == key && property.contains (" data" )) {
485- d->tags .append (SimpleTag (
486- key,
487- property.value (" data" ).value <ByteVector>(),
488- static_cast <SimpleTag::TargetTypeValue>(
489- property.value (" targetTypeValue" , 0 ).value <int >()),
490- property.value (" language" ).value <String>(),
491- property.value (" defaultLanguage" , true ).value <bool >()));
508+ if (property.value (" name" ).value <String>() == key &&
509+ (property.contains (" data" ) || property.contains (" value" ) )) {
510+ SimpleTag::TargetTypeValue targetTypeValue;
511+ Variant targetTypeValueVar = property.value (" targetTypeValue" , 0 );
512+ switch (targetTypeValueVar.type ()) {
513+ case Variant::UInt:
514+ targetTypeValue = static_cast <SimpleTag::TargetTypeValue>(targetTypeValueVar.value <unsigned int >());
515+ break ;
516+ case Variant::LongLong:
517+ targetTypeValue = static_cast <SimpleTag::TargetTypeValue>(targetTypeValueVar.value <long long >());
518+ break ;
519+ case Variant::ULongLong:
520+ targetTypeValue = static_cast <SimpleTag::TargetTypeValue>(targetTypeValueVar.value <unsigned long long >());
521+ break ;
522+ default :
523+ targetTypeValue = static_cast <SimpleTag::TargetTypeValue>(targetTypeValueVar.value <int >());
524+ }
525+ auto language = property.value (" language" ).value <String>();
526+ bool defaultLanguage = property.value (" defaultLanguage" , true ).value <bool >();
527+ d->tags .append (property.contains (" data" )
528+ ? SimpleTag (key, property.value (" data" ).value <ByteVector>(),
529+ targetTypeValue, language, defaultLanguage)
530+ : SimpleTag (key, property.value (" value" ).value <String>(),
531+ targetTypeValue, language, defaultLanguage));
492532 result = true ;
493533 }
494534 }
495535 return result;
496536}
497-
498- PropertyMap Matroska::Tag::properties () const
499- {
500- PropertyMap properties;
501- for (const auto &simpleTag : std::as_const (d->tags )) {
502- if (simpleTag.type () == SimpleTag::StringType) {
503- String key = translateTag (simpleTag.name (), simpleTag.targetTypeValue ());
504- if (!key.isEmpty ())
505- properties[key].append (simpleTag.toString ());
506- else
507- properties.addUnsupportedData (simpleTag.name ());
508- }
509- }
510- return properties;
511- }
0 commit comments