Compare commits
34 Commits
v0.10.1-al
...
v0.12.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
292f3e5ea4 | ||
|
|
e9a4de447c | ||
|
|
42bc929142 | ||
|
|
58f52833d6 | ||
|
|
7cf8dcf22a | ||
|
|
e139fbb2fb | ||
|
|
332cbe3e37 | ||
|
|
e35876a1ba | ||
|
|
693d27c049 | ||
|
|
8742967885 | ||
|
|
a27cf45f95 | ||
|
|
93cc305fa7 | ||
|
|
0d51798384 | ||
|
|
22e466cd0e | ||
|
|
33ef56fd94 | ||
|
|
6b24706851 | ||
|
|
be3d6dee8d | ||
|
|
07c9c31a09 | ||
|
|
9db32a51ca | ||
|
|
5200cd69ce | ||
|
|
0e65ab5452 | ||
|
|
cbdc193b83 | ||
|
|
fb2c12d981 | ||
|
|
81be373505 | ||
|
|
5f1bd5f13d | ||
|
|
7ef472fcb2 | ||
|
|
a58ac149f3 | ||
|
|
32bd4cfb9d | ||
|
|
9b44adff34 | ||
|
|
75c25c8bf5 | ||
|
|
a79472ba0c | ||
|
|
cafb88173f | ||
|
|
af122e9392 | ||
|
|
470585bf8c |
87
README.md
@@ -1,12 +1,17 @@
|
||||
# [OSXPhotos](https://github.com/RhetTbull/osxphotos)
|
||||
# OSXPhotos
|
||||
|
||||
[](https://github.com/python/black)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
|
||||
## What is osxphotos?
|
||||
|
||||
OSXPhotos provides the ability to interact with and query Apple's Photos app library database on Mac OS X.
|
||||
OSXPhotos provides the ability to interact with and query Apple's Photos app library database on Mac OS X. Using this module you can query the Photos database for information about the photos stored in a Photos library--for example, file name, file path, and metadata such as keywords/tags, persons/faces, albums, etc.
|
||||
|
||||
## Supported operating systems
|
||||
|
||||
Only works on Mac OS X. Only tested on Mac OS 10.13 and Photos 3.0. Requires python >= 3.6
|
||||
Only works on Mac OS X. Tested on Mac OS 10.12.6 / Photos 2.0, 10.13.6 / Photos 3.0 and Mac OS 10.14.5, 10.14.6 / Photos 4.0. Requires python >= 3.6
|
||||
|
||||
This module will read Photos databases for any supported version on any supported OS version. E.g. you can read a database created with Photos 4.0 on Mac OS 10.4 on a machine running Mac OS 10.12
|
||||
|
||||
## Installation instructions
|
||||
|
||||
@@ -16,7 +21,52 @@ osxmetadata uses setuptools, thus simply run:
|
||||
|
||||
## Command Line Usage
|
||||
|
||||
This project started as a command line utility, `photosmeta`, available at [photosmeta](https://github.com/RhetTbull/photosmeta) This module converts the photosmeta functionality into a module. Eventually, I plan to rewrite photosmeta using this module and include it as a command line script in this module.
|
||||
This module will install a command line utility called `osxphotos` that allows you to query the Photos database.
|
||||
|
||||
If you only care about the command line tool, I recommend installing with [pipx](https://github.com/pipxproject/pipx)
|
||||
|
||||
After install pipx:
|
||||
`pipx install osxphotos`
|
||||
|
||||
```
|
||||
Usage: osxphotos [OPTIONS] COMMAND [ARGS]...
|
||||
|
||||
Options:
|
||||
--db <Photos database path> Specify database file
|
||||
--json Print output in JSON format
|
||||
-h, --help Show this message and exit.
|
||||
|
||||
Commands:
|
||||
albums print out albums found in the Photos library
|
||||
dump print list of all photos & associated info from the Photos...
|
||||
help print help; for help on commands: help <command>
|
||||
info print out descriptive info of the Photos library database
|
||||
keywords print out keywords found in the Photos library
|
||||
persons print out persons (faces) found in the Photos library
|
||||
query query the Photos database using 1 or more search options
|
||||
```
|
||||
|
||||
To get help on a specific command, use `osxphotos help <command_name>`
|
||||
|
||||
Example: `osxphotos help query`
|
||||
|
||||
```
|
||||
Usage: osxphotos help [OPTIONS]
|
||||
|
||||
query the Photos database using 1 or more search options
|
||||
|
||||
Options:
|
||||
--keyword TEXT search for keyword(s)
|
||||
--person TEXT search for person(s)
|
||||
--album TEXT search for album(s)
|
||||
--uuid TEXT search for UUID(s)
|
||||
--json Print output in JSON format
|
||||
-h, --help Show this message and exit.
|
||||
```
|
||||
|
||||
Example: find all photos with keyword "Kids" and output results to json file named results.json:
|
||||
|
||||
`osxphotos query --keyword Kids --json >results.json`
|
||||
|
||||
## Example uses of the module
|
||||
|
||||
@@ -143,6 +193,23 @@ photosdb.get_photos_library_path()
|
||||
|
||||
Returns the path to the Photos library as a string
|
||||
|
||||
#### ```get_db_path```
|
||||
```python
|
||||
# assumes photosdb is a PhotosDB object (see above)
|
||||
photosdb.get_db_path()
|
||||
```
|
||||
|
||||
Returns the path to the Photos database PhotosDB was initialized with
|
||||
|
||||
#### ```get_db_version```
|
||||
```python
|
||||
# assumes photosdb is a PhotosDB object (see above)
|
||||
photosdb.get_db_version()
|
||||
```
|
||||
|
||||
Returns the version number for Photos library database. You likely won't need this but it's provided in case needed for debugging. PhotosDB will print a warning to `sys.stderr` if you open a database version that has not been tested.
|
||||
|
||||
|
||||
#### ```photos```
|
||||
```python
|
||||
# assumes photosdb is a PhotosDB object (see above)
|
||||
@@ -245,6 +312,9 @@ Returns `True` if the original image file is missing on disk, otherwise `False`.
|
||||
#### `hasadjustments()`
|
||||
Returns `True` if the file has been edited in Photos, otherwise `False`
|
||||
|
||||
#### `to_json()`
|
||||
Returns a JSON representation of all photo info
|
||||
|
||||
Examples:
|
||||
|
||||
```python
|
||||
@@ -266,6 +336,11 @@ for p in photos:
|
||||
)
|
||||
```
|
||||
|
||||
## History
|
||||
|
||||
This project started as a command line utility, `photosmeta`, available at [photosmeta](https://github.com/RhetTbull/photosmeta) This module converts the photosmeta Photos library query functionality into a module.
|
||||
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
This module is very kludgy. It works by creating a copy of the sqlite3 database that Photos uses to store data about the Photos library. The class PhotosDB then queries this database to extract information about the photos such as persons (faces identified in the photos), albums, keywords, etc.
|
||||
@@ -275,7 +350,9 @@ If Apple changes the database format this will likely break.
|
||||
The sqlite3 database used by Photos uses write ahead logging that is updated asynchronously in the background by a Photos helper service. Sometimes the update takes a long time meaning the latest changes made in Photos (e.g. add a keyword) will not show up in the database for sometime. I know of no way around this.
|
||||
|
||||
## Dependencies
|
||||
[PyObjC](https://pythonhosted.org/pyobjc/)
|
||||
- [PyObjC](https://pythonhosted.org/pyobjc/)
|
||||
- [PyYAML](https://pypi.org/project/PyYAML/)
|
||||
- [Click](https://pypi.org/project/click/)
|
||||
|
||||
## Acknowledgements
|
||||
This code was inspired by photo-export by Patrick Fältström see: (https://github.com/patrikhson/photo-export) Copyright (c) 2015 Patrik Fältström paf@frobbit.se
|
||||
|
||||
@@ -3,6 +3,9 @@ import osxphotos
|
||||
|
||||
def main():
|
||||
photosdb = osxphotos.PhotosDB()
|
||||
print(f"db file = {photosdb.get_db_path()}")
|
||||
print(f"db version = {photosdb.get_db_version()}")
|
||||
|
||||
print(photosdb.keywords())
|
||||
print(photosdb.persons())
|
||||
print(photosdb.albums())
|
||||
|
||||
@@ -1,24 +1,40 @@
|
||||
import platform
|
||||
import json
|
||||
import os.path
|
||||
from pathlib import Path
|
||||
from plistlib import load as plistload
|
||||
from datetime import datetime
|
||||
import tempfile
|
||||
import urllib.parse
|
||||
import sys
|
||||
from shutil import copyfile
|
||||
import platform
|
||||
import pprint
|
||||
import sqlite3
|
||||
import sys
|
||||
import tempfile
|
||||
import urllib.parse
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
from plistlib import load as plistload
|
||||
from shutil import copyfile
|
||||
|
||||
import objc
|
||||
import CoreFoundation
|
||||
import objc
|
||||
import yaml
|
||||
from Foundation import *
|
||||
|
||||
from . import _applescript
|
||||
|
||||
# from loguru import logger
|
||||
|
||||
# replace string formatting with fstrings
|
||||
# TODO: standardize _ and __ as leading char for private variables
|
||||
# TODO: fix use of ''' and """
|
||||
# TODO: fix docstrings
|
||||
# TODO: fix versions tested to include 10.14.6
|
||||
|
||||
# which Photos library database versions have been tested
|
||||
# Photos 2.0 (10.12.6) == 2622
|
||||
# Photos 3.0 (10.13.6) == 3301
|
||||
# Photos 4.0 (10.14.5) == 4016
|
||||
# Photos 4.0 (10.4.6) == 4025
|
||||
# TODO: Should this also use compatibleBackToVersion from LiGlobals?
|
||||
_TESTED_DB_VERSIONS = ["4025", "4016", "3301", "2622"]
|
||||
|
||||
# which major version operating systems have been tested
|
||||
_TESTED_OS_VERSIONS = ["12", "13", "14"]
|
||||
|
||||
_debug = False
|
||||
|
||||
@@ -43,10 +59,12 @@ class PhotosDB:
|
||||
system = platform.system()
|
||||
(_, major, _) = _get_os_version()
|
||||
# logger.debug(system, major)
|
||||
if (system != "Darwin") or (major != "12"):
|
||||
if system != "Darwin" or (major not in _TESTED_OS_VERSIONS):
|
||||
print(
|
||||
"WARNING: This module has only been tested with MacOS 10.13: "
|
||||
+ f"{system}, OS version: {major}", file=sys.stderr
|
||||
"WARNING: This module has only been tested with MacOS 10."
|
||||
+ f"[{', '.join(_TESTED_OS_VERSIONS)}]: "
|
||||
+ f"you have {system}, OS version: {major}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
# Dict with information about all photos by uuid
|
||||
@@ -66,7 +84,7 @@ class PhotosDB:
|
||||
# Dict with information about all the volumes/photos by uuid
|
||||
self._dbvolumes = {}
|
||||
|
||||
print(dbfile)
|
||||
# logger.debug(dbfile)
|
||||
if dbfile is None:
|
||||
library_path = self.get_photos_library_path()
|
||||
# logger.debug("library_path: " + library_path)
|
||||
@@ -79,7 +97,7 @@ class PhotosDB:
|
||||
# TODO: replace os.path with pathlib
|
||||
# TODO: clean this up -- we'll already know library_path
|
||||
library_path = os.path.dirname(dbfile)
|
||||
(library_path, tmp) = os.path.split(library_path)
|
||||
(library_path, _) = os.path.split(library_path)
|
||||
masters_path = os.path.join(library_path, "Masters")
|
||||
self._masters_path = masters_path
|
||||
# logger.debug(f"library = {library_path}, masters = {masters_path}")
|
||||
@@ -172,6 +190,14 @@ class PhotosDB:
|
||||
"""
|
||||
)
|
||||
|
||||
def get_db_version(self):
|
||||
# return the database version as stored in LiGlobals table
|
||||
return self.__db_version
|
||||
|
||||
def get_db_path(self):
|
||||
""" return path to the Photos library database PhotosDB was initialized with """
|
||||
return os.path.abspath(self._dbfile)
|
||||
|
||||
def get_photos_library_path(self):
|
||||
# return the path to the Photos library
|
||||
plist_file = Path(
|
||||
@@ -225,13 +251,13 @@ class PhotosDB:
|
||||
# copies the sqlite database file to a temp file
|
||||
# returns the name of the temp file
|
||||
# required because python's sqlite3 implementation can't read a locked file
|
||||
fd, tmp = tempfile.mkstemp(suffix=".db", prefix="photos")
|
||||
_, tmp = tempfile.mkstemp(suffix=".db", prefix="photos")
|
||||
# logger.debug("copying " + fname + " to " + tmp)
|
||||
try:
|
||||
copyfile(fname, tmp)
|
||||
except:
|
||||
print("copying " + fname + " to " + tmp, file=sys.stderr)
|
||||
sys.exit()
|
||||
print("Error copying " + fname + " to " + tmp, file=sys.stderr)
|
||||
raise Exception
|
||||
return tmp
|
||||
|
||||
def _open_sql_file(self, file):
|
||||
@@ -261,6 +287,20 @@ class PhotosDB:
|
||||
(conn, c) = self._open_sql_file(tmp_db)
|
||||
# logger.debug("Have connection with database")
|
||||
|
||||
# get database version
|
||||
c.execute(
|
||||
"SELECT value from LiGlobals where LiGlobals.keyPath is 'libraryVersion'"
|
||||
)
|
||||
for ver in c:
|
||||
self.__db_version = ver[0]
|
||||
break # TODO: is there a more pythonic way to do get the first element from cursor?
|
||||
|
||||
if self.__db_version not in _TESTED_DB_VERSIONS:
|
||||
print(
|
||||
f"WARNING: Only tested on database versions [{', '.join(_TESTED_DB_VERSIONS)}]"
|
||||
+ f" You have database version={self.__db_version} which has not been tested"
|
||||
)
|
||||
|
||||
# Look for all combinations of persons and pictures
|
||||
# logger.debug("Getting information about persons")
|
||||
|
||||
@@ -400,7 +440,10 @@ class PhotosDB:
|
||||
self._dbphotos[uuid]["lastmodifieddate"] = datetime.fromtimestamp(
|
||||
row[5] + td
|
||||
)
|
||||
self._dbphotos[uuid]["imageDate"] = datetime.fromtimestamp(row[5] + td)
|
||||
|
||||
self._dbphotos[uuid]["imageDate"] = datetime.fromtimestamp(
|
||||
row[5] + td
|
||||
) # - row[9], timezone.utc)
|
||||
self._dbphotos[uuid]["mainRating"] = row[6]
|
||||
self._dbphotos[uuid]["hasAdjustments"] = row[7]
|
||||
self._dbphotos[uuid]["hasKeywords"] = row[8]
|
||||
@@ -411,17 +454,17 @@ class PhotosDB:
|
||||
self._dbphotos[uuid]["name"] = row[13]
|
||||
self._dbphotos[uuid]["isMissing"] = row[14]
|
||||
# logger.debug(
|
||||
# "Fetching data for photo %d %s %s %s %s %s: %s"
|
||||
# % (
|
||||
# i,
|
||||
# uuid,
|
||||
# self._dbphotos[uuid]["masterUuid"],
|
||||
# self._dbphotos[uuid]["volumeId"],
|
||||
# self._dbphotos[uuid]["filename"],
|
||||
# self._dbphotos[uuid]["extendedDescription"],
|
||||
# self._dbphotos[uuid]["imageDate"],
|
||||
# )
|
||||
# )
|
||||
# "Fetching data for photo %d %s %s %s %s %s: %s"
|
||||
# % (
|
||||
# i,
|
||||
# uuid,
|
||||
# self._dbphotos[uuid]["masterUuid"],
|
||||
# self._dbphotos[uuid]["volumeId"],
|
||||
# self._dbphotos[uuid]["filename"],
|
||||
# self._dbphotos[uuid]["extendedDescription"],
|
||||
# self._dbphotos[uuid]["imageDate"],
|
||||
# )
|
||||
# )
|
||||
|
||||
# close_pbar_status()
|
||||
conn.close()
|
||||
@@ -495,7 +538,7 @@ class PhotosDB:
|
||||
"""
|
||||
|
||||
def photos(self, keywords=[], uuid=[], persons=[], albums=[]):
|
||||
#TODO: remove the logger code then dangling else: pass statements
|
||||
# TODO: remove the logger code then dangling else: pass statements
|
||||
photos_sets = [] # list of photo sets to perform intersection of
|
||||
if not keywords and not uuid and not persons and not albums:
|
||||
# return all the photos
|
||||
@@ -554,6 +597,9 @@ class PhotosDB:
|
||||
photoinfo.append(info)
|
||||
return photoinfo
|
||||
|
||||
def __repr__(self):
|
||||
return f"osxphotos.PhotosDB(dbfile='{self.get_db_path()}')"
|
||||
|
||||
|
||||
"""
|
||||
Info about a specific photo, contains all the details we know about the photo
|
||||
@@ -571,20 +617,16 @@ class PhotoInfo:
|
||||
return self.__info["filename"]
|
||||
|
||||
def date(self):
|
||||
return self.__info["imageDate"]
|
||||
""" image creation date as timezone aware datetime object """
|
||||
imagedate = self.__info["imageDate"]
|
||||
delta = timedelta(seconds=self.__info["imageTimeZoneOffsetSeconds"])
|
||||
tz = timezone(delta)
|
||||
imagedate_utc = imagedate.astimezone(tz=tz)
|
||||
return imagedate_utc
|
||||
|
||||
""" returns true if photo is missing from disk (which means it's not been downloaded from iCloud)
|
||||
NOTE: the photos.db database uses an asynchrounous write-ahead log so changes in Photos
|
||||
do not immediately get written to disk. In particular, I've noticed that downloading
|
||||
an image from the cloud does not force the database to be updated until something else
|
||||
e.g. an edit, keyword, etc. occurs forcing a database synch
|
||||
The exact process / timing is a mystery to be but be aware that if some photos were recently
|
||||
downloaded from cloud to local storate their status in the database might still show
|
||||
isMissing = 1
|
||||
"""
|
||||
|
||||
def ismissing(self):
|
||||
return self.__info["isMissing"]
|
||||
def tzoffset(self):
|
||||
""" timezone offset from UTC in seconds """
|
||||
return self.__info["imageTimeZoneOffsetSeconds"]
|
||||
|
||||
def path(self):
|
||||
photopath = ""
|
||||
@@ -597,7 +639,7 @@ class PhotoInfo:
|
||||
|
||||
if self.__info["isMissing"] == 1:
|
||||
# logger.warning(
|
||||
# f"Skipping photo, not yet downloaded from iCloud: {photopath}"
|
||||
# f"Skipping photo, not yet downloaded from iCloud: {photopath}"
|
||||
# )
|
||||
# logger.debug(self.__info)
|
||||
photopath = None # path would be meaningless until downloaded
|
||||
@@ -624,11 +666,56 @@ class PhotoInfo:
|
||||
return self.__uuid
|
||||
|
||||
def ismissing(self):
|
||||
""" returns true if photo is missing from disk (which means it's not been downloaded from iCloud)
|
||||
NOTE: the photos.db database uses an asynchrounous write-ahead log so changes in Photos
|
||||
do not immediately get written to disk. In particular, I've noticed that downloading
|
||||
an image from the cloud does not force the database to be updated until something else
|
||||
e.g. an edit, keyword, etc. occurs forcing a database synch
|
||||
The exact process / timing is a mystery to be but be aware that if some photos were recently
|
||||
downloaded from cloud to local storate their status in the database might still show
|
||||
isMissing = 1
|
||||
"""
|
||||
return True if self.__info["isMissing"] == 1 else False
|
||||
|
||||
def hasadjustments(self):
|
||||
return True if self.__info["hasAdjustments"] == 1 else False
|
||||
|
||||
def __repr__(self):
|
||||
return f"osxphotos.PhotoInfo(db={self.__db}, uuid='{self.__uuid}', info={self.__info})"
|
||||
|
||||
def __str__(self):
|
||||
info = {
|
||||
"uuid": self.uuid(),
|
||||
"filename": self.filename(),
|
||||
"date": str(self.date()),
|
||||
"description": self.description(),
|
||||
"name": self.name(),
|
||||
"keywords": self.keywords(),
|
||||
"albums": self.albums(),
|
||||
"persons": self.persons(),
|
||||
"path": self.path(),
|
||||
"ismissing": self.ismissing(),
|
||||
"hasadjustments": self.hasadjustments(),
|
||||
}
|
||||
return yaml.dump(info, sort_keys=False)
|
||||
|
||||
def to_json(self):
|
||||
""" return JSON representation """
|
||||
pic = {
|
||||
"uuid": self.uuid(),
|
||||
"filename": self.filename(),
|
||||
"date": str(self.date()),
|
||||
"description": self.description(),
|
||||
"name": self.name(),
|
||||
"keywords": self.keywords(),
|
||||
"albums": self.albums(),
|
||||
"persons": self.persons(),
|
||||
"path": self.path(),
|
||||
"ismissing": self.ismissing(),
|
||||
"hasadjustments": self.hasadjustments(),
|
||||
}
|
||||
return json.dumps(pic)
|
||||
|
||||
# compare two PhotoInfo objects for equality
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, self.__class__):
|
||||
|
||||
200
osxphotos/cmd_line.py
Normal file
@@ -0,0 +1,200 @@
|
||||
import csv
|
||||
import json
|
||||
import sys
|
||||
|
||||
import click
|
||||
import yaml
|
||||
|
||||
import osxphotos
|
||||
|
||||
|
||||
class CLI_Obj:
|
||||
def __init__(self, db=None, json=False):
|
||||
self.photosdb = osxphotos.PhotosDB(dbfile=db)
|
||||
self.json = json
|
||||
|
||||
|
||||
CTX_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||
|
||||
|
||||
@click.group(context_settings=CTX_SETTINGS)
|
||||
@click.option(
|
||||
"--db",
|
||||
required=False,
|
||||
metavar="<Photos database path>",
|
||||
default=None,
|
||||
help="Specify database file",
|
||||
)
|
||||
@click.option(
|
||||
"--json",
|
||||
required=False,
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Print output in JSON format",
|
||||
)
|
||||
@click.pass_context
|
||||
def cli(ctx, db, json):
|
||||
ctx.obj = CLI_Obj(db=db, json=json)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.pass_obj
|
||||
def keywords(cli_obj):
|
||||
""" print out keywords found in the Photos library"""
|
||||
keywords = {"keywords": cli_obj.photosdb.keywords_as_dict()}
|
||||
if cli_obj.json:
|
||||
print(json.dumps(keywords))
|
||||
else:
|
||||
print(yaml.dump(keywords, sort_keys=False))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.pass_obj
|
||||
def albums(cli_obj):
|
||||
""" print out albums found in the Photos library """
|
||||
albums = {"albums": cli_obj.photosdb.albums_as_dict()}
|
||||
if cli_obj.json:
|
||||
print(json.dumps(albums))
|
||||
else:
|
||||
print(yaml.dump(albums, sort_keys=False))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.pass_obj
|
||||
def persons(cli_obj):
|
||||
""" print out persons (faces) found in the Photos library """
|
||||
persons = {"persons": cli_obj.photosdb.persons_as_dict()}
|
||||
if cli_obj.json:
|
||||
print(json.dumps(persons))
|
||||
else:
|
||||
print(yaml.dump(persons, sort_keys=False))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.pass_obj
|
||||
def info(cli_obj):
|
||||
""" print out descriptive info of the Photos library database """
|
||||
pdb = cli_obj.photosdb
|
||||
info = {}
|
||||
info["database_path"] = pdb.get_db_path()
|
||||
info["database_version"] = pdb.get_db_version()
|
||||
|
||||
photos = pdb.photos()
|
||||
info["photo_count"] = len(photos)
|
||||
|
||||
keywords = pdb.keywords_as_dict()
|
||||
info["keywords_count"] = len(keywords)
|
||||
info["keywords"] = keywords
|
||||
|
||||
albums = pdb.albums_as_dict()
|
||||
info["albums_count"] = len(albums)
|
||||
info["albums"] = albums
|
||||
|
||||
persons = pdb.persons_as_dict()
|
||||
info["persons_count"] = len(persons)
|
||||
info["persons"] = persons
|
||||
|
||||
if cli_obj.json:
|
||||
print(json.dumps(info))
|
||||
else:
|
||||
print(yaml.dump(info, sort_keys=False))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.pass_obj
|
||||
def dump(cli_obj):
|
||||
""" print list of all photos & associated info from the Photos library """
|
||||
pdb = cli_obj.photosdb
|
||||
photos = pdb.photos()
|
||||
print_photo_info(photos, cli_obj.json)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option("--keyword", default=None, multiple=True, help="search for keyword(s)")
|
||||
@click.option("--person", default=None, multiple=True, help="search for person(s)")
|
||||
@click.option("--album", default=None, multiple=True, help="search for album(s)")
|
||||
@click.option("--uuid", default=None, multiple=True, help="search for UUID(s)")
|
||||
@click.option(
|
||||
"--json",
|
||||
required=False,
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Print output in JSON format",
|
||||
)
|
||||
@click.pass_obj
|
||||
@click.pass_context
|
||||
def query(ctx, cli_obj, keyword, person, album, uuid, json):
|
||||
""" query the Photos database using 1 or more search options """
|
||||
|
||||
# if no query terms, show help and return
|
||||
if not keyword and not person and not album and not uuid:
|
||||
print(cli.commands["query"].get_help(ctx))
|
||||
return
|
||||
else:
|
||||
photos = cli_obj.photosdb.photos(
|
||||
keywords=keyword, persons=person, albums=album, uuid=uuid
|
||||
)
|
||||
print_photo_info(photos, cli_obj.json or json)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("topic", default=None, required=False, nargs=1)
|
||||
@click.pass_context
|
||||
def help(ctx, topic, **kw):
|
||||
""" print help; for help on commands: help <command> """
|
||||
if topic is None:
|
||||
print(ctx.parent.get_help())
|
||||
else:
|
||||
print(cli.commands[topic].get_help(ctx))
|
||||
|
||||
|
||||
def print_photo_info(photos, json=False):
|
||||
if json:
|
||||
dump = []
|
||||
for p in photos:
|
||||
dump.append(p.to_json())
|
||||
print(f"[{', '.join(dump)}]")
|
||||
else:
|
||||
# dump as CSV
|
||||
csv_writer = csv.writer(
|
||||
sys.stdout, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL
|
||||
)
|
||||
dump = []
|
||||
# add headers
|
||||
dump.append(
|
||||
[
|
||||
"uuid",
|
||||
"filename",
|
||||
"date",
|
||||
"description",
|
||||
"name",
|
||||
"keywords",
|
||||
"albums",
|
||||
"persons",
|
||||
"path",
|
||||
"ismissing",
|
||||
"hasadjustments",
|
||||
]
|
||||
)
|
||||
for p in photos:
|
||||
dump.append(
|
||||
[
|
||||
p.uuid(),
|
||||
p.filename(),
|
||||
str(p.date()),
|
||||
p.description(),
|
||||
p.name(),
|
||||
", ".join(p.keywords()),
|
||||
", ".join(p.albums()),
|
||||
", ".join(p.persons()),
|
||||
p.path(),
|
||||
p.ismissing(),
|
||||
p.hasadjustments(),
|
||||
]
|
||||
)
|
||||
for row in dump:
|
||||
csv_writer.writerow(row)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
126
requirements.txt
@@ -1,4 +1,122 @@
|
||||
# pip install -r requirements.txt
|
||||
|
||||
pyobjc-core
|
||||
pyobjc
|
||||
ansimarkup==1.4.0
|
||||
astroid==2.2.5
|
||||
atomicwrites==1.3.0
|
||||
attrs==19.1.0
|
||||
better-exceptions-fork==0.2.1.post6
|
||||
certifi==2019.3.9
|
||||
Click==7.0
|
||||
colorama==0.4.1
|
||||
importlib-metadata==0.18
|
||||
isort==4.3.20
|
||||
lazy-object-proxy==1.4.1
|
||||
mccabe==0.6.1
|
||||
more-itertools==7.2.0
|
||||
packaging==19.0
|
||||
pluggy==0.12.0
|
||||
py==1.8.0
|
||||
Pygments==2.4.2
|
||||
pylint==2.3.1
|
||||
pyobjc==5.2
|
||||
pyobjc-core==5.2
|
||||
pyobjc-framework-Accounts==5.2
|
||||
pyobjc-framework-AddressBook==5.2
|
||||
pyobjc-framework-AdSupport==5.2
|
||||
pyobjc-framework-AppleScriptKit==5.2
|
||||
pyobjc-framework-AppleScriptObjC==5.2
|
||||
pyobjc-framework-ApplicationServices==5.2
|
||||
pyobjc-framework-Automator==5.2
|
||||
pyobjc-framework-AVFoundation==5.2
|
||||
pyobjc-framework-AVKit==5.2
|
||||
pyobjc-framework-BusinessChat==5.2
|
||||
pyobjc-framework-CalendarStore==5.2
|
||||
pyobjc-framework-CFNetwork==5.2
|
||||
pyobjc-framework-CloudKit==5.2
|
||||
pyobjc-framework-Cocoa==5.2
|
||||
pyobjc-framework-Collaboration==5.2
|
||||
pyobjc-framework-ColorSync==5.2
|
||||
pyobjc-framework-Contacts==5.2
|
||||
pyobjc-framework-ContactsUI==5.2
|
||||
pyobjc-framework-CoreAudio==5.2
|
||||
pyobjc-framework-CoreAudioKit==5.2
|
||||
pyobjc-framework-CoreBluetooth==5.2
|
||||
pyobjc-framework-CoreData==5.2
|
||||
pyobjc-framework-CoreLocation==5.2
|
||||
pyobjc-framework-CoreMedia==5.2
|
||||
pyobjc-framework-CoreMediaIO==5.2
|
||||
pyobjc-framework-CoreML==5.2
|
||||
pyobjc-framework-CoreServices==5.2
|
||||
pyobjc-framework-CoreSpotlight==5.2
|
||||
pyobjc-framework-CoreText==5.2
|
||||
pyobjc-framework-CoreWLAN==5.2
|
||||
pyobjc-framework-CryptoTokenKit==5.2
|
||||
pyobjc-framework-DictionaryServices==5.2
|
||||
pyobjc-framework-DiscRecording==5.2
|
||||
pyobjc-framework-DiscRecordingUI==5.2
|
||||
pyobjc-framework-DiskArbitration==5.2
|
||||
pyobjc-framework-DVDPlayback==5.2
|
||||
pyobjc-framework-EventKit==5.2
|
||||
pyobjc-framework-ExceptionHandling==5.2
|
||||
pyobjc-framework-ExternalAccessory==5.2
|
||||
pyobjc-framework-FinderSync==5.2
|
||||
pyobjc-framework-FSEvents==5.2
|
||||
pyobjc-framework-GameCenter==5.2
|
||||
pyobjc-framework-GameController==5.2
|
||||
pyobjc-framework-GameKit==5.2
|
||||
pyobjc-framework-GameplayKit==5.2
|
||||
pyobjc-framework-ImageCaptureCore==5.2
|
||||
pyobjc-framework-IMServicePlugIn==5.2
|
||||
pyobjc-framework-InputMethodKit==5.2
|
||||
pyobjc-framework-InstallerPlugins==5.2
|
||||
pyobjc-framework-InstantMessage==5.2
|
||||
pyobjc-framework-Intents==5.2
|
||||
pyobjc-framework-IOSurface==5.2
|
||||
pyobjc-framework-iTunesLibrary==5.2
|
||||
pyobjc-framework-LatentSemanticMapping==5.2
|
||||
pyobjc-framework-LaunchServices==5.2
|
||||
pyobjc-framework-libdispatch==5.2
|
||||
pyobjc-framework-LocalAuthentication==5.2
|
||||
pyobjc-framework-MapKit==5.2
|
||||
pyobjc-framework-MediaAccessibility==5.2
|
||||
pyobjc-framework-MediaLibrary==5.2
|
||||
pyobjc-framework-MediaPlayer==5.2
|
||||
pyobjc-framework-MediaToolbox==5.2
|
||||
pyobjc-framework-ModelIO==5.2
|
||||
pyobjc-framework-MultipeerConnectivity==5.2
|
||||
pyobjc-framework-NaturalLanguage==5.2
|
||||
pyobjc-framework-NetFS==5.2
|
||||
pyobjc-framework-Network==5.2
|
||||
pyobjc-framework-NetworkExtension==5.2
|
||||
pyobjc-framework-NotificationCenter==5.2
|
||||
pyobjc-framework-OpenDirectory==5.2
|
||||
pyobjc-framework-OSAKit==5.2
|
||||
pyobjc-framework-Photos==5.2
|
||||
pyobjc-framework-PhotosUI==5.2
|
||||
pyobjc-framework-PreferencePanes==5.2
|
||||
pyobjc-framework-PubSub==5.2
|
||||
pyobjc-framework-QTKit==5.2
|
||||
pyobjc-framework-Quartz==5.2
|
||||
pyobjc-framework-SafariServices==5.2
|
||||
pyobjc-framework-SceneKit==5.2
|
||||
pyobjc-framework-ScreenSaver==5.2
|
||||
pyobjc-framework-ScriptingBridge==5.2
|
||||
pyobjc-framework-SearchKit==5.2
|
||||
pyobjc-framework-Security==5.2
|
||||
pyobjc-framework-SecurityFoundation==5.2
|
||||
pyobjc-framework-SecurityInterface==5.2
|
||||
pyobjc-framework-ServiceManagement==5.2
|
||||
pyobjc-framework-Social==5.2
|
||||
pyobjc-framework-SpriteKit==5.2
|
||||
pyobjc-framework-StoreKit==5.2
|
||||
pyobjc-framework-SyncServices==5.2
|
||||
pyobjc-framework-SystemConfiguration==5.2
|
||||
pyobjc-framework-UserNotifications==5.2
|
||||
pyobjc-framework-VideoSubscriberAccount==5.2
|
||||
pyobjc-framework-VideoToolbox==5.2
|
||||
pyobjc-framework-Vision==5.2
|
||||
pyobjc-framework-WebKit==5.2
|
||||
pyparsing==2.4.1.1
|
||||
PyYAML==5.1.2
|
||||
six==1.12.0
|
||||
wcwidth==0.1.7
|
||||
wrapt==1.11.1
|
||||
zipp==0.5.2
|
||||
|
||||
10
setup.py
@@ -38,7 +38,7 @@ with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
|
||||
|
||||
setup(
|
||||
name="osxphotos",
|
||||
version="0.10.1",
|
||||
version="0.12.2",
|
||||
description="Manipulate (read-only) Apple's Photos app library on Mac OS X",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
@@ -58,8 +58,8 @@ setup(
|
||||
"Programming Language :: Python :: 3.6",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
],
|
||||
install_requires=["pyobjc",],
|
||||
# entry_points = {
|
||||
# 'console_scripts' : ['osxmetadata=osxmetadata.cmd_line:main'],
|
||||
# }
|
||||
install_requires=["pyobjc","Click","pyyaml",],
|
||||
entry_points = {
|
||||
'console_scripts' : ['osxphotos=osxphotos.cmd_line:cli'],
|
||||
}
|
||||
)
|
||||
|
||||
|
After Width: | Height: | Size: 541 KiB |
|
After Width: | Height: | Size: 528 KiB |
|
After Width: | Height: | Size: 574 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 500 KiB |
|
After Width: | Height: | Size: 450 KiB |
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>DatabaseMinorVersion</key>
|
||||
<integer>1</integer>
|
||||
<key>DatabaseVersion</key>
|
||||
<integer>112</integer>
|
||||
<key>LastOpenMode</key>
|
||||
<integer>2</integer>
|
||||
<key>LibrarySchemaVersion</key>
|
||||
<integer>2622</integer>
|
||||
<key>MetaSchemaVersion</key>
|
||||
<integer>2</integer>
|
||||
<key>createDate</key>
|
||||
<date>2019-08-24T02:50:48Z</date>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
tests/Test-10.12.6.photoslibrary/database/RKAlbum_name.skindex
Normal file
BIN
tests/Test-10.12.6.photoslibrary/database/RKMemory_title.skindex
Normal file
BIN
tests/Test-10.12.6.photoslibrary/database/metaSchema.db
Normal file
BIN
tests/Test-10.12.6.photoslibrary/database/photos.db
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LithiumMessageTracer</key>
|
||||
<dict>
|
||||
<key>LastReportedDate</key>
|
||||
<date>2019-08-24T02:50:48Z</date>
|
||||
</dict>
|
||||
<key>PXPeopleScreenUnlocked</key>
|
||||
<true/>
|
||||
<key>Photos</key>
|
||||
<dict>
|
||||
<key>IPXWorkspaceControllerPhotosHasContentKey</key>
|
||||
<true/>
|
||||
<key>IPXWorkspaceControllerZoomLevelsKey</key>
|
||||
<dict>
|
||||
<key>kZoomLevelIdentifierAlbums</key>
|
||||
<integer>7</integer>
|
||||
<key>kZoomLevelIdentifierVersions</key>
|
||||
<integer>7</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
|
||||
<date>2019-08-24T02:51:33Z</date>
|
||||
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
|
||||
<date>2019-08-24T13:19:30Z</date>
|
||||
</dict>
|
||||
</plist>
|
||||
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 460 KiB |
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PLLanguageAndLocaleKey</key>
|
||||
<string>en-US:en_US</string>
|
||||
<key>PLLastGeoProviderIdKey</key>
|
||||
<string>7618</string>
|
||||
<key>PLLastLocationInfoFormatVer</key>
|
||||
<integer>12</integer>
|
||||
<key>PLLastRevGeoForcedProviderOutOfDateCheckVersionKey</key>
|
||||
<integer>1</integer>
|
||||
<key>PLLastRevGeoVerFileFetchDateKey</key>
|
||||
<date>2019-08-24T02:51:30Z</date>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LastHistoryRowId</key>
|
||||
<integer>414</integer>
|
||||
<key>LibraryBuildTag</key>
|
||||
<string>E3E46F2A-7168-4973-AB3E-5848F80BFC7D</string>
|
||||
<key>LibrarySchemaVersion</key>
|
||||
<integer>2622</integer>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>FileVersion</key>
|
||||
<integer>11</integer>
|
||||
<key>Source</key>
|
||||
<dict>
|
||||
<key>35230</key>
|
||||
<dict>
|
||||
<key>CountryMinVersions</key>
|
||||
<dict>
|
||||
<key>OTHER</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>CurrentVersion</key>
|
||||
<integer>1</integer>
|
||||
<key>NoResultErrorIsSuccess</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>57879</key>
|
||||
<dict>
|
||||
<key>CountryMinVersions</key>
|
||||
<dict>
|
||||
<key>OTHER</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>CurrentVersion</key>
|
||||
<integer>1</integer>
|
||||
<key>NoResultErrorIsSuccess</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>7618</key>
|
||||
<dict>
|
||||
<key>AddCountyIfNeeded</key>
|
||||
<true/>
|
||||
<key>CountryMinVersions</key>
|
||||
<dict>
|
||||
<key>OTHER</key>
|
||||
<integer>10</integer>
|
||||
</dict>
|
||||
<key>CurrentVersion</key>
|
||||
<integer>10</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 214 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 157 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 260 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 272 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 276 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 330 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 297 KiB |
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>DatabaseMinorVersion</key>
|
||||
<integer>1</integer>
|
||||
<key>DatabaseVersion</key>
|
||||
<integer>112</integer>
|
||||
<key>HistoricalMarker</key>
|
||||
<dict>
|
||||
<key>LastHistoryRowId</key>
|
||||
<integer>403</integer>
|
||||
<key>LibraryBuildTag</key>
|
||||
<string>E3E46F2A-7168-4973-AB3E-5848F80BFC7D</string>
|
||||
<key>LibrarySchemaVersion</key>
|
||||
<integer>2622</integer>
|
||||
</dict>
|
||||
<key>LibrarySchemaVersion</key>
|
||||
<integer>2622</integer>
|
||||
<key>MetaSchemaVersion</key>
|
||||
<integer>2</integer>
|
||||
<key>SnapshotComplete</key>
|
||||
<true/>
|
||||
<key>SnapshotCompletedDate</key>
|
||||
<date>2019-08-24T02:50:48Z</date>
|
||||
<key>SnapshotTables</key>
|
||||
<dict/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
After Width: | Height: | Size: 1.2 MiB |
@@ -3,8 +3,8 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
|
||||
<date>2019-07-26T20:15:18Z</date>
|
||||
<date>2019-07-28T01:23:52Z</date>
|
||||
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
|
||||
<date>2019-07-26T20:15:18Z</date>
|
||||
<date>2019-07-28T01:23:52Z</date>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict/>
|
||||
<dict>
|
||||
<key>SuggestedMeIdentifier</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LithiumMessageTracer</key>
|
||||
<dict>
|
||||
<key>LastReportedDate</key>
|
||||
<date>2019-07-27T12:01:15Z</date>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LastHistoryRowId</key>
|
||||
<integer>545</integer>
|
||||
<integer>615</integer>
|
||||
<key>LibraryBuildTag</key>
|
||||
<string>BEA5F0E8-BA6B-4462-8F73-3E53BBE4C943</string>
|
||||
<key>LibrarySchemaVersion</key>
|
||||
|
||||
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 182 KiB |