aboutsummaryrefslogtreecommitdiffstats
path: root/src/pyexiv2.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyexiv2.py')
-rw-r--r--src/pyexiv2.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 9435ba7..eefda51 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -286,6 +286,11 @@ class Image(libpyexiv2.Image):
setIptcTagValue -- set the value associated to a key in IPTC metadata
"""
+ def __init__(self, filename):
+ libpyexiv2.Image.__init__(self, filename)
+ self.__exifTagsDict = {}
+ self.__iptcTagsDict = {}
+
def getExifTagValue(self, key):
"""
Get the value associated to a key in EXIF metadata.
@@ -447,6 +452,27 @@ class Image(libpyexiv2.Image):
strVal = str(value)
self.setIptcTag(key, strVal, index)
+ def __getitem__(self, key):
+ tagFamily = key[:4]
+ if tagFamily == 'Exif':
+ try:
+ return self.__exifTagsDict[key]
+ except KeyError:
+ value = self.getExifTagValue(key)
+ self.__exifTagsDict[key] = value
+ return value
+ elif tagFamily == 'Iptc':
+ try:
+ return self.__iptcTagsDict[key]
+ except KeyError:
+ value = self.getIptcTagValue(key)
+ if len(value) == 1:
+ value = value[0]
+ self.__iptcTagsDict[key] = value
+ return value
+ else:
+ raise KeyError('Invalid tag identifier')
+
def _test():
print 'testing library pyexiv2...'
# TODO: various tests