social-photos/image_processing.py

23 lines
738 B
Python
Raw Normal View History

2023-11-04 22:29:00 +00:00
import pyexiv2
def get_image_data(path: str):
print(f"Reading metadata: {path}")
2023-11-04 22:29:00 +00:00
img = pyexiv2.Image(path)
xmp = img.read_xmp()
create_date = xmp.get('Xmp.xmp.CreateDate', 'N/A')
title = xmp.get('Xmp.dc.title', 'N/A')
description = xmp.get('Xmp.dc.description', 'N/A')
tags = xmp.get('Xmp.dc.subject', 'N/A')
description_parts = description['lang="x-default"'].split('|')
main_description = description_parts[0].strip()
alt_text = description_parts[1].strip()
image_data = {
'path': path,
'create': create_date + "Z",
'title': title['lang="x-default"'],
'description': main_description,
'alt': alt_text,
'tags': tags
}
return image_data