Handle blank persons in Photos 5

This commit is contained in:
Rhet Turnbull
2019-12-07 20:57:23 -08:00
parent 591336673a
commit da320e4f56
3 changed files with 23 additions and 14 deletions

View File

@@ -12,10 +12,9 @@ from plistlib import load as plistload
from pprint import pformat from pprint import pformat
from shutil import copyfile from shutil import copyfile
import yaml
import CoreFoundation import CoreFoundation
import objc import objc
import yaml
from Foundation import * from Foundation import *
# from . import _applescript # from . import _applescript
@@ -46,6 +45,9 @@ _PHOTOS_5_VERSION = "6000"
# which major version operating systems have been tested # which major version operating systems have been tested
_TESTED_OS_VERSIONS = ["12", "13", "14", "15"] _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 # set _DEBUG = True to enable debug output
_DEBUG = False _DEBUG = False
@@ -776,14 +778,19 @@ class PhotosDB:
"AND ZGENERICASSET.ZTRASHEDSTATE = 0 AND ZGENERICASSET.ZKIND = 0 " "AND ZGENERICASSET.ZTRASHEDSTATE = 0 AND ZGENERICASSET.ZKIND = 0 "
) )
for person in c: for person in c:
person_name = None
if person[0] is None: if person[0] is None:
continue continue
if person[0] == "":
person_name = _UNKNOWN_PERSON
else:
person_name = person[0]
if not person[1] in self._dbfaces_uuid: if not person[1] in self._dbfaces_uuid:
self._dbfaces_uuid[person[1]] = [] self._dbfaces_uuid[person[1]] = []
if not person[0] in self._dbfaces_person: if not person_name in self._dbfaces_person:
self._dbfaces_person[person[0]] = [] self._dbfaces_person[person_name] = []
self._dbfaces_uuid[person[1]].append(person[0]) self._dbfaces_uuid[person[1]].append(person_name)
self._dbfaces_person[person[0]].append(person[1]) self._dbfaces_person[person_name].append(person[1])
i = i + 1 i = i + 1
logging.debug(f"Finished walking through persons") logging.debug(f"Finished walking through persons")
logging.debug(pformat(self._dbfaces_person)) logging.debug(pformat(self._dbfaces_person))

View File

@@ -1,4 +1,4 @@
""" version info """ """ version info """
__version__ = "0.14.17" __version__ = "0.14.18"

View File

@@ -102,14 +102,16 @@ def info(cli_obj):
info["albums"] = albums info["albums"] = albums
persons = pdb.persons_as_dict() persons = pdb.persons_as_dict()
# handle empty person names (added by Photos 5.0+ when face detected but not identified) # handle empty person names (added by Photos 5.0+ when face detected but not identified)
noperson = "UNKNOWN" # TODO: remove this
if "" in persons: # noperson = "UNKNOWN"
if noperson in persons: # if "" in persons:
persons[noperson].append(persons[""]) # if noperson in persons:
else: # persons[noperson].append(persons[""])
persons[noperson] = persons[""] # else:
persons.pop("", None) # persons[noperson] = persons[""]
# persons.pop("", None)
info["persons_count"] = len(persons) info["persons_count"] = len(persons)
info["persons"] = persons info["persons"] = persons