diff options
-rw-r--r-- | src/pyexiv2.py | 26 | ||||
-rw-r--r-- | todo | 1 |
2 files changed, 27 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 @@ -1,6 +1,7 @@ todo list - Allow access to the tag values using the dictionary syntax (read values on the fly when needed, lazy instantiation) -> operator overloading with __getitem__() and __setitem__() +- Also allow the deletion of items in the same way - Cache already queried values (see dictionary on previous line) - Disable the get...() and set...() methods (by making them private) -> metadata is accessible only through the dictionnary metaphor - Rewrite the exiv2 command-line tool and the test binaries in Python and (Python) scripts to run the same tests that are run to test exiv2 |