From 4b02641481606dce49dbbbd5ddbb0215296371c0 Mon Sep 17 00:00:00 2001 From: gryf Date: Fri, 30 Sep 2022 18:20:45 +0200 Subject: [PATCH] Added EXIF tag handling for images. --- pycatalog/scan.py | 18 ++++++++++++++++-- setup.cfg | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pycatalog/scan.py b/pycatalog/scan.py index 2c77d6e..bdea2f8 100644 --- a/pycatalog/scan.py +++ b/pycatalog/scan.py @@ -10,6 +10,7 @@ import re from datetime import datetime import mimetypes +import exifread from pycatalog.dbobjects import File, TYPE from pycatalog import dbcommon from pycatalog.logger import get_logger @@ -216,8 +217,21 @@ class Scan(object): return def _image(self, fobj, filepath): - # exif? - return + """Read exif if exists, add it to description""" + with open(filepath, 'rb') as obj: + exif = exifread.process_file(obj) + if not exif: + return + + data = [] + # longest key + 2, since we need a colon and a space after it + longest_key = max([len(k) for k in exif]) + 2 + for key in exif: + if 'thumbnail' in key.lower() and isinstance(exif[key], bytes): + data.append(f"{key + ':' :<{longest_key}}thumbnail present") + continue + data.append(f"{key + ':' :<{longest_key}}{exif[key]}") + fobj.description = "\n".join(data) def _video(self, fobj, filepath): """ diff --git a/setup.cfg b/setup.cfg index 4c3204c..4f8eebc 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,7 +34,7 @@ packages = [options] install_requires = - pillow + exifread sqlalchemy [bdist_wheel]