1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 11:30:19 +01:00

Added EXIF tag handling for images.

This commit is contained in:
2022-09-30 18:20:45 +02:00
parent 51e3bfa441
commit 4b02641481
2 changed files with 17 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ import re
from datetime import datetime from datetime import datetime
import mimetypes import mimetypes
import exifread
from pycatalog.dbobjects import File, TYPE from pycatalog.dbobjects import File, TYPE
from pycatalog import dbcommon from pycatalog import dbcommon
from pycatalog.logger import get_logger from pycatalog.logger import get_logger
@@ -216,8 +217,21 @@ class Scan(object):
return return
def _image(self, fobj, filepath): def _image(self, fobj, filepath):
# exif? """Read exif if exists, add it to description"""
return 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): def _video(self, fobj, filepath):
""" """

View File

@@ -34,7 +34,7 @@ packages =
[options] [options]
install_requires = install_requires =
pillow exifread
sqlalchemy sqlalchemy
[bdist_wheel] [bdist_wheel]