diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-03-05 19:22:58 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-03-05 19:22:58 +0100 |
commit | a35b33f4f1ddcf6f1bb8ab0f41b87bf2b847f11d (patch) | |
tree | fb220da28bb7248ebf37ce09af5de88f2c1aaad4 /bsie/reader/exif.py | |
parent | 7582c280ad5324a2f0427999911c7e7abc14a6ab (diff) | |
parent | af81318ae9311fd0b0e16949cef3cfaf7996970b (diff) | |
download | bsie-a35b33f4f1ddcf6f1bb8ab0f41b87bf2b847f11d.tar.gz bsie-a35b33f4f1ddcf6f1bb8ab0f41b87bf2b847f11d.tar.bz2 bsie-a35b33f4f1ddcf6f1bb8ab0f41b87bf2b847f11d.zip |
Diffstat (limited to 'bsie/reader/exif.py')
-rw-r--r-- | bsie/reader/exif.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bsie/reader/exif.py b/bsie/reader/exif.py new file mode 100644 index 0000000..2d0428b --- /dev/null +++ b/bsie/reader/exif.py @@ -0,0 +1,44 @@ + +# standard imports +import typing + +# external imports +import pyexiv2 + +# bsie imports +from bsie.utils import errors, filematcher + +# inner-module imports +from . import base + +# constants +MATCH_RULE = 'mime=image/jpeg' + +# exports +__all__: typing.Sequence[str] = ( + 'Exif', + ) + + +## code ## + +class Exif(base.Reader): + """Use pyexiv2 to read exif 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_exif() + except (TypeError, OSError, RuntimeError) as err: + raise errors.ReaderError(path) from err + +## EOF ## |