From 63fe1d017e2fad8181e3ff47185b974304957d56 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Wed, 5 Apr 2023 17:16:14 +0200 Subject: IPTC tag extraction --- bsie/reader/exif.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'bsie/reader/exif.py') 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 ## -- cgit v1.2.3