-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented signature, #1389 for sync and exportdb * Fix for linux * Fix for linux * Add test for #1389
- Loading branch information
Showing
9 changed files
with
259 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Compute unique signature for photos""" | ||
|
||
from __future__ import annotations | ||
|
||
import datetime | ||
import os | ||
|
||
from .photoinfo import PhotoInfo | ||
from .photoinfo_file import PhotoInfoFromDict, PhotoInfoFromFile | ||
from .platform import is_macos | ||
|
||
if is_macos: | ||
from .fingerprint import fingerprint | ||
|
||
|
||
def photo_signature( | ||
photo: PhotoInfo | PhotoInfoFromFile | dict | str | os.PathLike, | ||
exiftool: str | None = None, | ||
) -> str: | ||
"""Compute photo signature for a PhotoInfo, a PhotoInfo dict, or file path""" | ||
if isinstance(photo, dict): | ||
photo = PhotoInfoFromDict(photo) | ||
elif not isinstance(photo, PhotoInfo): | ||
photo = PhotoInfoFromFile(photo, exiftool=exiftool) | ||
|
||
if photo.shared: | ||
return _shared_photo_signature(photo) | ||
|
||
if photo.fingerprint: | ||
return f"{photo.original_filename.lower()}:{photo.fingerprint}" | ||
|
||
if photo.path and is_macos: | ||
return f"{photo.original_filename.lower()}:{fingerprint(photo.path)}" | ||
|
||
return f"{photo.original_filename.lower()}:{photo.original_filesize}" | ||
|
||
|
||
def _shared_photo_signature( | ||
photo: PhotoInfo | PhotoInfoFromFile | PhotoInfoFromDict, | ||
) -> str: | ||
"""return a key for matching a shared photo between libraries""" | ||
date = photo.date | ||
if isinstance(date, datetime.datetime): | ||
date = date.isoformat() | ||
return ( | ||
f"{photo.cloud_owner_hashed_id}:" | ||
f"{photo.original_height}:" | ||
f"{photo.original_width}:" | ||
f"{photo.isphoto}:" | ||
f"{photo.ismovie}:" | ||
f"{date}" | ||
) |
Oops, something went wrong.