Add tag_exif_camera_lens.py utility.

master
voussoir 2022-08-13 18:16:57 -07:00
parent f420367d55
commit fedd8e00a7
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
from voussoirkit import imagetools
from voussoirkit import vlogging
vlogging.basic_config(vlogging.INFO)
import etiquette
P = etiquette.photodb.PhotoDB()
with P.transaction:
try:
CAMERA = P.get_tag('camera')
except etiquette.exceptions.NoSuchTag:
CAMERA = P.new_tag('camera')
try:
LENS = P.get_tag('lens')
except etiquette.exceptions.NoSuchTag:
LENS = P.new_tag('lens')
for photo in P.search(extension=['jpeg', 'jpg'], yield_albums=False):
if not photo.real_path.exists:
continue
exif = imagetools.exifread(photo.real_path)
camera_make = exif.get('Image Make')
camera_model = exif.get('Image Model')
camera_make = camera_make.values if camera_make else ''
camera_model = camera_model.values if camera_model else ''
camera = ' '.join([camera_make, camera_model]).strip().replace('.', '')
lens = exif.get('EXIF LensModel')
lens = (lens.values if lens else '').replace('.', '')
if camera:
try:
camera_tag = P.get_tag(camera)
except etiquette.exceptions.NoSuchTag:
camera_tag = P.new_tag(camera)
CAMERA.add_child(camera_tag)
photo.add_tag(camera_tag)
if lens:
try:
lens_tag = P.get_tag(lens)
except etiquette.exceptions.NoSuchTag:
lens_tag = P.new_tag(lens)
LENS.add_child(lens_tag)
photo.add_tag(lens_tag)