aboutsummaryrefslogtreecommitdiffstats
path: root/bsie/reader/exif.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsie/reader/exif.py')
-rw-r--r--bsie/reader/exif.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/bsie/reader/exif.py b/bsie/reader/exif.py
index 2d0428b..7ec7574 100644
--- a/bsie/reader/exif.py
+++ b/bsie/reader/exif.py
@@ -17,6 +17,7 @@ MATCH_RULE = 'mime=image/jpeg'
# exports
__all__: typing.Sequence[str] = (
'Exif',
+ 'Iptc',
)
@@ -41,4 +42,24 @@ class Exif(base.Reader):
except (TypeError, OSError, RuntimeError) as err:
raise errors.ReaderError(path) from err
+
+class Iptc(base.Reader):
+ """Use pyexiv2 to read iptc metadata from image files."""
+
+ def __init__(self):
+ self._match = filematcher.parse(MATCH_RULE)
+
+ def __call__(self, path: str) -> dict:
+ # perform quick checks first
+ if not self._match(path):
+ raise errors.UnsupportedFileFormatError(path)
+
+ try:
+ # open the file
+ img = pyexiv2.Image(path)
+ # read metadata
+ return img.read_iptc()
+ except (TypeError, OSError, RuntimeError) as err:
+ raise errors.ReaderError(path) from err
+
## EOF ##