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.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/bsie/reader/exif.py b/bsie/reader/exif.py
new file mode 100644
index 0000000..e087bec
--- /dev/null
+++ b/bsie/reader/exif.py
@@ -0,0 +1,49 @@
+"""
+
+Part of the bsie module.
+A copy of the license is provided with the project.
+Author: Matthias Baumgartner, 2022
+"""
+# 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 as err:
+ raise errors.ReaderError(path) from err
+
+## EOF ##