Generalise sign language video tag handling and add test.
[libdcp.git] / src / cpl.cc
index 5467fef3b1db0b38ebf859e5d4adf623e7342dd7..da4e056377de9b3c6ac81ae886c61212c2f58309 100644 (file)
@@ -345,21 +345,31 @@ CPL::read_composition_metadata_asset (cxml::ConstNodePtr node)
        }
 
        auto eml = node->optional_node_child ("ExtensionMetadataList");
-       if (eml) {
+
+       auto extension_metadata = [eml](string scope, string name, string property) -> boost::optional<std::string> {
+               if (!eml) {
+                       return {};
+               }
+
                for (auto i: eml->node_children("ExtensionMetadata")) {
-                       auto name = i->optional_string_child("Name");
-                       if (name && *name == "Sign Language Video") {
+                       auto xml_scope = i->optional_string_attribute("scope");
+                       auto xml_name = i->optional_string_child("Name");
+                       if (xml_scope && *xml_scope == scope && xml_name && *xml_name == name) {
                                auto property_list = i->node_child("PropertyList");
                                for (auto j: property_list->node_children("Property")) {
-                                       auto name = j->optional_string_child("Name");
-                                       auto value = j->optional_string_child("Value");
-                                       if (name && value && *name == "Language Tag") {
-                                               _sign_language_video_language = *value;
+                                       auto property_name = j->optional_string_child("Name");
+                                       auto property_value = j->optional_string_child("Value");
+                                       if (property_name && property_value && *property_name == property) {
+                                               return property_value;
                                        }
                                }
                        }
                }
-       }
+
+               return {};
+       };
+
+       _sign_language_video_language = extension_metadata("http://isdcf.com/2017/10/SignLanguageVideo", "Sign Language Video", "Language Tag");
 }