Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement minimal EXIF/IPTC tag support #32

Closed

Conversation

sebastiaan-lampo
Copy link
Contributor

Use PIL's TAGS to deal with EXIF. Use iptcinfo3 to deal with IPTC tags. Allows to use these as fallback options for copyright
and caption of photos. As a sample use-case reads captions from the photos and the album copyright can be determined from the copyright of the photos in it. Will not change the default behaviour without adding the setting tag_map, exif or iptc to the configuration file. If the copyright use-case is not desired, drop the changes to the album.py file in their entirety.

To make it work more easily, without constant try except clauses for every setting possible, the Settings object now returns None when accessing a property that is not set instead of throwing an AttributeError. I left this fundamental change to the codebase as a separate commit but not changing this behaviour will require a re-write of some code in this pull request.

This feature is the baseline for integrating with #31 to output EXIF/IPTC tags into the front matter of every photo.

Use PIL's TAGS to deal with EXIF. Use
iptcinfo3 to deal with IPTC tags. Allows to
use these as fallback options for copyright
and caption of photos.

As a sample use-case also implements the
fallback for the photo album to be determined
from the set of photos in it.

Will not change the default behaviour without
adding the setting tag_map, exif or iptc to
the configuration file.
Returns None instead of raising AttributeError when accessing
a setting that is not defined.
Comment on lines -230 to +260
photo = Photo(
album_name=album.name,
original_path=photo_path,
name=p["name"],
alt=p["alt"],
caption=caption,
copyright=album.copyright,
)
all_photos.append(photo)
try:
photo = Photo(
album_name=album.name,
original_path=photo_path,
name=p["name"],
alt=p["alt"],
caption=caption,
copyright=album._copyright,
)
all_photos.append(photo)
except PermissionError:
pass
except UnidentifiedImageError:
pass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't technically part of the IPTC/EXIF implementation. I wanted to have the album.yml file in the same folder as the photos which threw a bunch of errors otherwise. Now it skips directories (PermissionError) and non-photos (UnidentifiedImageError).

Remove unused imports
Add iptcinfo3 to the project requirements
Tidy up some wording
@GjjvdBurg
Copy link
Owner

Thanks a lot for these PRs @sebastiaan-lampo! I'll try to make sure to take a detailed look at them as soon as possible.

@sebastiaan-lampo
Copy link
Contributor Author

If you like both features Gertjan then I can replace these PR's with another one in which I've merged both branches and implemented combined both features. I didn't just want to assume that you consider them good broad use cases.

self._iptc = None

# process load image to ensure it's a valid image.
self.original_image
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the resiliency for deleted photos you had in the current master. This now results in a FileNotFoundError that isn't caught in the Photo() call of _load_albums. See also sebastiaan-lampo#3

More worrying to me is that this is called for every photo in every album on every action unless a specific album is specified. That could severely impact performance.

I may have been too eager with this feature and can't recommend merging this PR into master anymore. Would love to get your feedback though.

Copy link
Contributor Author

@sebastiaan-lampo sebastiaan-lampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gertjan, I may have been too eager with this feature and can't recommend merging this PR into master anymore. I discovered one bug that my code introduces: https://github.com/GjjvdBurg/HugoPhotoSwipe/pull/32/files#r579884886

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants