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

Import photo metadata from Apple Photos into SQLite #1

Open
simonw opened this issue Apr 18, 2020 · 8 comments
Open

Import photo metadata from Apple Photos into SQLite #1

simonw opened this issue Apr 18, 2020 · 8 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@simonw
Copy link
Contributor

simonw commented Apr 18, 2020

Faces, albums, locations, that kind of thing.

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

I'm going to use osxphotos for this.

Since I've already got code to upload photos and insert them into a table based on their sha256 hash, my first go at this will be to import data using the tool and foreign-key it to the sha256 hash in the existing table.

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

Command will be this:

$ photos-to-sqlite apple-photos photos.db

This will populate a apple_photos table with the data imported by the osxphotos library, plus the calculated sha256.

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

For locations: I'll add place_x columns for all of these:

(Pdb) photo.place.address._asdict()
{'street': None, 'sub_locality': None, 'city': 'Loreto', 'sub_administrative_area': 'Loreto', 'state_province': 'BCS', 'postal_code': None, 'country': 'Mexico', 'iso_country_code': 'MX'}

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

To get the taken date in UTC:

from datetime import timezone
(Pdb) photo.date.astimezone(timezone.utc).isoformat()
'2018-02-13T20:21:31.620000+00:00'
(Pdb) photo.date.astimezone(timezone.utc).isoformat().split(".")
['2018-02-13T20:21:31', '620000+00:00']
(Pdb) photo.date.astimezone(timezone.utc).isoformat().split(".")[0]
'2018-02-13T20:21:31'
(Pdb) photo.date.astimezone(timezone.utc).isoformat().split(".")[0] + "+00:00"
'2018-02-13T20:21:31+00:00'

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

Albums have UUIDs:

(Pdb) photo.album_info[0].__dict__
{'_uuid': '17816791-ABF3-447B-942C-9FA8065EEBBA', '_db': osxphotos.PhotosDB(dbfile='/Users/simon/Pictures/Photos Library.photoslibrary/database/photos.db'), '_title': 'Geotaggable Photos geotagged'}

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

Record burst_uuid as a column:

(Pdb) with_bursts[0]._info["burstUUID"]
'703FAA23-57BF-40B4-8A33-D9CEB143391B'

@simonw
Copy link
Contributor Author

simonw commented May 3, 2020

Reading this source code is really useful for figuring out how to store a photo in a DB table: https://github.com/RhetTbull/osxphotos/blob/7444b6d173918a3ad2a07aefce5ecf054786c787/osxphotos/photoinfo.py

@simonw
Copy link
Contributor Author

simonw commented May 4, 2020

Needs documentation.

@simonw simonw added documentation Improvements or additions to documentation enhancement New feature or request labels May 4, 2020
simonw added a commit that referenced this issue May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant