From da320e4f5671a669c6130d226d130c45f6834432 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 7 Dec 2019 20:57:23 -0800 Subject: [PATCH] Handle blank persons in Photos 5 --- osxphotos/__init__.py | 19 +++++++++++++------ osxphotos/_version.py | 2 +- osxphotos/cmd_line.py | 16 +++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/osxphotos/__init__.py b/osxphotos/__init__.py index 310e22ae..53906c60 100644 --- a/osxphotos/__init__.py +++ b/osxphotos/__init__.py @@ -12,10 +12,9 @@ from plistlib import load as plistload from pprint import pformat from shutil import copyfile -import yaml - import CoreFoundation import objc +import yaml from Foundation import * # from . import _applescript @@ -46,6 +45,9 @@ _PHOTOS_5_VERSION = "6000" # which major version operating systems have been tested _TESTED_OS_VERSIONS = ["12", "13", "14", "15"] +# Photos 5 has persons who are empty string if unidentified face +_UNKNOWN_PERSON = "_UNKNOWN_" + # set _DEBUG = True to enable debug output _DEBUG = False @@ -776,14 +778,19 @@ class PhotosDB: "AND ZGENERICASSET.ZTRASHEDSTATE = 0 AND ZGENERICASSET.ZKIND = 0 " ) for person in c: + person_name = None if person[0] is None: continue + if person[0] == "": + person_name = _UNKNOWN_PERSON + else: + person_name = person[0] if not person[1] in self._dbfaces_uuid: self._dbfaces_uuid[person[1]] = [] - if not person[0] in self._dbfaces_person: - self._dbfaces_person[person[0]] = [] - self._dbfaces_uuid[person[1]].append(person[0]) - self._dbfaces_person[person[0]].append(person[1]) + if not person_name in self._dbfaces_person: + self._dbfaces_person[person_name] = [] + self._dbfaces_uuid[person[1]].append(person_name) + self._dbfaces_person[person_name].append(person[1]) i = i + 1 logging.debug(f"Finished walking through persons") logging.debug(pformat(self._dbfaces_person)) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 95117c58..9e8894a1 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,4 +1,4 @@ """ version info """ -__version__ = "0.14.17" +__version__ = "0.14.18" diff --git a/osxphotos/cmd_line.py b/osxphotos/cmd_line.py index a96ecc4d..af931a9e 100644 --- a/osxphotos/cmd_line.py +++ b/osxphotos/cmd_line.py @@ -102,14 +102,16 @@ def info(cli_obj): info["albums"] = albums persons = pdb.persons_as_dict() + # handle empty person names (added by Photos 5.0+ when face detected but not identified) - noperson = "UNKNOWN" - if "" in persons: - if noperson in persons: - persons[noperson].append(persons[""]) - else: - persons[noperson] = persons[""] - persons.pop("", None) + # TODO: remove this + # noperson = "UNKNOWN" + # if "" in persons: + # if noperson in persons: + # persons[noperson].append(persons[""]) + # else: + # persons[noperson] = persons[""] + # persons.pop("", None) info["persons_count"] = len(persons) info["persons"] = persons