aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/exiv2wrapper.cpp44
-rw-r--r--src/exiv2wrapper.hpp4
-rw-r--r--src/exiv2wrapper_python.cpp4
-rw-r--r--src/pyexiv2/metadata.py11
4 files changed, 56 insertions, 7 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index 1b356c7..3ea5ec3 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -329,14 +329,54 @@ const XmpTag Image::getXmpTag(std::string key)
return XmpTag(key, &_xmpData[key]);
}
-void Image::setXmpTagValue(std::string key, std::string value)
+void Image::setXmpTagTextValue(const std::string& key, const std::string& value)
{
if (!_dataRead)
{
throw Exiv2::Error(METADATA_NOT_READ);
}
- _xmpData[key] = value;
+ _xmpData[key].setValue(value);
+}
+
+void Image::setXmpTagArrayValue(const std::string& key, const boost::python::list& values)
+{
+ if (!_dataRead)
+ {
+ throw Exiv2::Error(METADATA_NOT_READ);
+ }
+
+ Exiv2::Xmpdatum& datum = _xmpData[key];
+ // Reset the value
+ datum.setValue(0);
+
+ for(boost::python::stl_input_iterator<std::string> iterator(values);
+ iterator != boost::python::stl_input_iterator<std::string>();
+ ++iterator)
+ {
+ datum.setValue(*iterator);
+ }
+}
+
+void Image::setXmpTagLangAltValue(const std::string& key, const boost::python::dict& values)
+{
+ if (!_dataRead)
+ {
+ throw Exiv2::Error(METADATA_NOT_READ);
+ }
+
+ Exiv2::Xmpdatum& datum = _xmpData[key];
+ // Reset the value
+ datum.setValue(0);
+
+ for(boost::python::stl_input_iterator<std::string> iterator(values);
+ iterator != boost::python::stl_input_iterator<std::string>();
+ ++iterator)
+ {
+ std::string key = *iterator;
+ std::string value = boost::python::extract<std::string>(values.get(key));
+ datum.setValue("lang=\"" + key + "\" " + value);
+ }
}
void Image::deleteXmpTag(std::string key)
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index 8a0d885..91a4c77 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -190,7 +190,9 @@ public:
// Throw an exception if the tag is not set.
const XmpTag getXmpTag(std::string key);
- void setXmpTagValue(std::string key, std::string value);
+ void setXmpTagTextValue(const std::string& key, const std::string& value);
+ void setXmpTagArrayValue(const std::string& key, const boost::python::list& values);
+ void setXmpTagLangAltValue(const std::string& key, const boost::python::dict& values);
// Delete the required XMP tag.
// Throw an exception if the tag was not set.
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index e2bdea5..f2e4831 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -111,7 +111,9 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("xmpKeys", &Image::xmpKeys)
.def("getXmpTag", &Image::getXmpTag)
- .def("setXmpTagValue", &Image::setXmpTagValue)
+ .def("setXmpTagTextValue", &Image::setXmpTagTextValue)
+ .def("setXmpTagArrayValue", &Image::setXmpTagArrayValue)
+ .def("setXmpTagLangAltValue", &Image::setXmpTagLangAltValue)
.def("deleteXmpTag", &Image::deleteXmpTag)
// .def("getThumbnailData", &Image::getThumbnailData)
diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py
index 1396f24..de6e809 100644
--- a/src/pyexiv2/metadata.py
+++ b/src/pyexiv2/metadata.py
@@ -213,9 +213,14 @@ class ImageMetadata(object):
# state).
if key not in self.xmp_keys:
raise KeyError('Cannot set the value of an inexistent tag')
- if type(value) is not str:
- raise TypeError('Expecting a string')
- self._image.setXmpTagValue(key, value)
+ if isinstance(value, str):
+ self._image.setXmpTagTextValue(key, value)
+ elif isinstance(value, (list, tuple)):
+ self._image.setXmpTagArrayValue(key, value)
+ elif isinstance(value, dict):
+ self._image.setXmpTagLangAltValue(key, value)
+ else:
+ raise TypeError('Expecting either a string, a list, a tuple or a dict')
def __setitem__(self, key, tag):
"""