-
Notifications
You must be signed in to change notification settings - Fork 106
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
Fix key_from_photo in sync, move fingerprinting code to a common function #1389
Comments
Oh wow, this would be so cool! I don't know much about Github and how this stuff works. Is this the kind of thing that at the bottom of a long wishlist or a the top of a short honeydo list? :) |
Obviously not meaning to try to push you or anything, I just genuinely have no idea how this works. If it were something you were planning to tackle I would certainly wait for it. Again happy to offer a token of appreciation in whatever way I can. I wish I could help code it.... |
For this particular one, it's probably top of the list. No promises on timeframe but maybe a week or two. |
Oh wow! Amazing!
…On Fri, Feb 23, 2024 at 10:00 PM Rhet Turnbull ***@***.***> wrote:
For this particular one, it's probably top of the list. No promises on
timeframe but maybe a week or two.
—
Reply to this email directly, view it on GitHub
<#1389 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AR6K5LOSOWFF63ZUUXOG6GTYVFJWBAVCNFSM6AAAAABB3KRKPCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRSGIZDQNZVHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
See also #939 which would need this |
To implement this, create a new comparison function or class that given a
|
The following osxphotos features need the ability to compare two photos (either an asset in the database and a file on disk or two database assets that might be in two different databases) and determine if they are the same file.
The easiest way to do this would be the use the
Given above, osxphotos needs a unique signature/fingerprint function that can be used across at least the The current implementation is: The for photo in photosdb.photos():
photosdb_fingerprint[
f"{photo.original_filename}:{photo.fingerprint}"
] = photo.uuid
photosdb_cloud_guid[
f"{photo.original_filename}:{photo.cloud_guid}"
] = photo.uuid
photosdb_name_size[
f"{photo.original_filename}:{photo.original_filesize}"
] = photo.uuid
if photo.shared:
photosdb_shared[_shared_photo_key(photo)] = photo.uuid and the def _shared_photo_key(photo: PhotoInfo | dict[str, Any]) -> str:
"""return a key for matching a shared photo between libraries"""
photoinfo = photo.asdict() if isinstance(photo, PhotoInfo) else photo
date = photoinfo.get("date")
if isinstance(date, datetime.datetime):
date = date.isoformat()
return (
f"{photoinfo.get('cloud_owner_hashed_id')}:"
f"{photoinfo.get('original_height')}:"
f"{photoinfo.get('original_width')}:"
f"{photoinfo.get('isphoto')}:"
f"{photoinfo.get('ismovie')}:"
f"{date}"
) The def key_from_photo(photo: PhotoInfo) -> str:
"""Return key for photo used to correlate photos between libraries"""
return f"{photo.fingerprint}:{photo.original_filename}" The Note: returns empty list if no possible duplicates found
"""
# first check by fingerprint
# Photos stores fingerprint for photos but not videos
if results := self.photos_by_fingerprint(fingerprint(filepath), in_trash):
return results
# if not fingerprint matches, could still be a match based on filename/size
# this is not 100% perfect but close enough to find likely duplicates
filename = pathlib.Path(filepath).name
size = pathlib.Path(filepath).stat().st_size
if results := self.photos_by_filename_size(filename, size, in_trash):
return results
return [] For the Given all the above constraints, the approach used for If photo has fingerprint, use
I tested my personal library of 30,000 photos and found 4 cases where On Ventura it appears that Videos do have a fingerprint so this may be moot. I'll check Sonoma as well. |
It appears Ventura 13.5+ does compute a fingerprint for every asset that's imported to the library. In my library there 28 images without fingerprint and all were syndicated / not saved to the library. This vastly simplifies things for Ventura+ because we can rely on fingerprint alone. |
See #1386
Several osxphotos commands need to match photos between libraries. For example:
osxphotos sync
osxphotos import
to find duplicatesosxphotos exportdb --migrate-photos-library
The code to do so is slightly different in each case. Create a common
fingerprinting
function that given a PhotoInfo object or a JSON dump of one, returns the right fingerprint. (Need a better name thanfingerprint
as this specifically means the fingerprint stored in the database.The text was updated successfully, but these errors were encountered: