aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2008-06-11 21:40:01 +0200
committerOlivier Tilloy <olivier@tilloy.net>2008-06-11 21:40:01 +0200
commita4e47a8357d35520157654008cbd2049da48abde (patch)
tree2263cb410e61ec7368c259ca87e3f09620ad9924 /src
parenteec684f0ee33e579835d51ffadc6577290d6fcb0 (diff)
downloadpyexiv2-a4e47a8357d35520157654008cbd2049da48abde.tar.gz
Retrieve more data for an IPTC tag (low-level).
Diffstat (limited to 'src')
-rw-r--r--src/exiv2wrapper.cpp84
-rw-r--r--src/exiv2wrapper.hpp19
-rw-r--r--src/exiv2wrapper_python.cpp4
-rw-r--r--src/pyexiv2.py3
4 files changed, 72 insertions, 38 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index d06f370..a0a69d5 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -58,7 +58,7 @@ void Image::readMetadata()
{
_image->readMetadata();
_exifData = _image->exifData();
- //_iptcData = _image->iptcData();
+ _iptcData = _image->iptcData();
_dataRead = true;
}
@@ -122,26 +122,7 @@ boost::python::tuple Image::getExifTag(std::string key)
}
}
-/*std::string Image::getExifTagToString(std::string key)
-{
- if(_dataRead)
- {
- Exiv2::ExifKey exifKey = Exiv2::ExifKey(key);
- Exiv2::ExifMetadata::iterator i = _exifData.findKey(exifKey);
- if(i != _exifData.end())
- {
- Exiv2::Exifdatum exifDatum = _exifData[key];
- std::ostringstream buffer;
- buffer << exifDatum;
- return buffer.str();
- }
- else
- throw Exiv2::Error(KEY_NOT_FOUND, key);
- }
- else
- throw Exiv2::Error(METADATA_NOT_READ);
-}
-
+/*
boost::python::tuple Image::setExifTag(std::string key, std::string value)
{
boost::python::tuple returnValue;
@@ -189,27 +170,70 @@ boost::python::tuple Image::deleteExifTag(std::string key)
}
else
throw Exiv2::Error(METADATA_NOT_READ);
-}
+}*/
boost::python::list Image::iptcKeys()
{
- boost::python::list list;
+ boost::python::list keys;
if(_dataRead)
{
- for(Exiv2::IptcMetadata::iterator i = _iptcData.begin() ; i != _iptcData.end() ; i++)
+ for(Exiv2::IptcMetadata::iterator i = _iptcData.begin();
+ i != _iptcData.end();
+ ++i)
{
- // The key is appended to the list if and only if it is not
- // already present.
- if (list.count(i->key()) == 0)
- list.append(i->key());
+ // The key is appended to the list if and only if it is not already
+ // present.
+ if (keys.count(i->key()) == 0)
+ {
+ keys.append(i->key());
+ }
}
- return list;
+ return keys;
}
else
+ {
throw Exiv2::Error(METADATA_NOT_READ);
+ }
+}
+
+boost::python::tuple Image::getIptcTag(std::string key)
+{
+ if(_dataRead)
+ {
+ Exiv2::IptcKey iptcKey = Exiv2::IptcKey(key);
+ boost::python::list values;
+ unsigned int occurences = 0;
+ std::string sTagType;
+ for (Exiv2::IptcMetadata::iterator i = _iptcData.begin();
+ i != _iptcData.end();
+ ++i)
+ {
+ if (i->key() == key)
+ {
+ values.append(i->toString());
+ ++occurences;
+ sTagType = i->typeName();
+ }
+ }
+ if (occurences > 0)
+ {
+ std::string sTagName = iptcKey.tagName();
+ std::string sTagLabel = iptcKey.tagLabel();
+ std::string sTagDesc(Exiv2::IptcDataSets::dataSetDesc(iptcKey.tag(), iptcKey.record()));
+ return boost::python::make_tuple(key, sTagName, sTagLabel, sTagDesc, sTagType, values);
+ }
+ else
+ {
+ throw Exiv2::Error(KEY_NOT_FOUND, key);
+ }
+ }
+ else
+ {
+ throw Exiv2::Error(METADATA_NOT_READ);
+ }
}
-boost::python::list Image::getIptcTag(std::string key)
+/*boost::python::list Image::getIptcTag(std::string key)
{
if(_dataRead)
{
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index 763a398..371cfe3 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -30,7 +30,7 @@
#include <string>
#include "exiv2/image.hpp"
-#include "exiv2/exif.hpp"
+//#include "exiv2/exif.hpp"
//#include "exiv2/iptc.hpp"
#include "boost/python.hpp"
@@ -90,12 +90,19 @@ public:
// Returns a list of all the keys of available IPTC tags set in the
// image. This list has no duplicates: each of its items is unique,
// even if a tag is present more than once.
- //boost::python::list iptcKeys();
+ boost::python::list iptcKeys();
- // Return a list of tuples, each containing the type (as a string) and
- // the value (as a string as well) of the required IPTC tag.
+ // Return a tuple containing the type (as a string) and the value
+ // (as a string as well) of the required IPTC tag.
// Throw an exception if the tag is not set.
- //boost::python::list getIptcTag(std::string key);
+ // key
+ // tagname
+ // taglabel
+ // tagdesc
+ // type
+ // tagvalue (list)
+ // tagvalue (human-readable) (list)
+ boost::python::tuple getIptcTag(std::string key);
// Set the IPTC tag's value and return a tuple containing the
// type and previous value of the tag (empty strings if not previously
@@ -146,7 +153,7 @@ private:
std::string _filename;
Exiv2::Image::AutoPtr _image;
Exiv2::ExifData _exifData;
- //Exiv2::IptcData _iptcData;
+ Exiv2::IptcData _iptcData;
// true if the image's internal metadata has already been read,
// false otherwise
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index fabaf6b..3b431d9 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -49,8 +49,8 @@ BOOST_PYTHON_MODULE(libexiv2python)
// .def("_Image__setExifTag", &Image::setExifTag)
// .def("_Image__deleteExifTag", &Image::deleteExifTag)
-// .def("iptcKeys", &Image::iptcKeys)
-// .def("_Image__getIptcTag", &Image::getIptcTag)
+ .def("iptcKeys", &Image::iptcKeys)
+ .def("_Image__getIptcTag", &Image::getIptcTag)
// .def("_Image__setIptcTag", &Image::setIptcTag)
// .def("_Image__deleteIptcTag", &Image::deleteIptcTag)
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 41660fa..afed270 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -387,6 +387,9 @@ class MetadataTag(object):
"""
DOCME
+
+ TODO: determine which attributes are common to all types of tags (EXIF,
+ IPTC and XMP), and which are specific.
"""
def __init__(self, key, name, label, description, type, value, svalue):