Partial fix for issue #247 on Mojave

This commit is contained in:
Rhet Turnbull 2020-10-31 21:04:44 -07:00
parent 13df6a2395
commit 6ac311199e
8 changed files with 62 additions and 16 deletions

View File

@ -70,7 +70,11 @@ class PhotoInfo:
@property
def filename(self):
""" filename of the picture """
if self._db._db_version <= _PHOTOS_4_VERSION and self.has_raw and self.raw_original:
if (
self._db._db_version <= _PHOTOS_4_VERSION
and self.has_raw
and self.raw_original
):
# return the JPEG version as that's what Photos 5+ does
return self._info["raw_pair_info"]["filename"]
else:
@ -80,7 +84,11 @@ class PhotoInfo:
def original_filename(self):
""" original filename of the picture
Photos 5 mangles filenames upon import """
if self._db._db_version <= _PHOTOS_4_VERSION and self.has_raw and self.raw_original:
if (
self._db._db_version <= _PHOTOS_4_VERSION
and self.has_raw
and self.raw_original
):
# return the JPEG version as that's what Photos 5+ does
return self._info["raw_pair_info"]["originalFilename"]
else:
@ -95,12 +103,20 @@ class PhotoInfo:
def date_modified(self):
""" image modification date as timezone aware datetime object
or None if no modification date set """
imagedate = self._info["lastmodifieddate"]
if imagedate:
seconds = self._info["imageTimeZoneOffsetSeconds"] or 0
delta = timedelta(seconds=seconds)
tz = timezone(delta)
return imagedate.astimezone(tz=tz)
# Photos <= 4 provides no way to get date of adjustment and will update
# lastmodifieddate anytime photo database record is updated (e.g. adding tags)
# only report lastmodified date for Photos <=4 if photo is edited;
# even in this case, the date could be incorrect
if self.hasadjustments or self._db._db_version > _PHOTOS_4_VERSION:
imagedate = self._info["lastmodifieddate"]
if imagedate:
seconds = self._info["imageTimeZoneOffsetSeconds"] or 0
delta = timedelta(seconds=seconds)
tz = timezone(delta)
return imagedate.astimezone(tz=tz)
else:
return None
else:
return None
@ -282,7 +298,7 @@ class PhotoInfo:
# could be elsewhere--I haven't figured out this logic yet
# first see if it's in 00
photopath = os.path.join(
library, "resources", "media", "version", folder_id, "00", filename,
library, "resources", "media", "version", folder_id, "00", filename
)
if not os.path.isfile(photopath):
@ -841,7 +857,7 @@ class PhotoInfo:
inplace_sep=inplace_sep,
filename=filename,
dirname=dirname,
replacement=replacement
replacement=replacement,
)
@property
@ -1026,6 +1042,7 @@ class PhotoInfo:
def json(self):
""" Return JSON representation """
def default(o):
if isinstance(o, (datetime.date, datetime.datetime)):
return o.isoformat()

View File

@ -3,8 +3,8 @@
<plist version="1.0">
<dict>
<key>PhotoAnalysisGraphLastBackgroundGraphRebuildJobDate</key>
<date>2020-10-09T16:14:42Z</date>
<date>2020-11-01T02:34:49Z</date>
<key>PhotoAnalysisGraphLastBackgroundMemoryGenerationJobDate</key>
<date>2020-10-10T05:21:03Z</date>
<date>2020-11-01T02:34:49Z</date>
</dict>
</plist>

View File

@ -11,6 +11,6 @@
<key>PLLastRevGeoForcedProviderOutOfDateCheckVersionKey</key>
<integer>1</integer>
<key>PLLastRevGeoVerFileFetchDateKey</key>
<date>2020-10-04T23:43:17Z</date>
<date>2020-11-01T02:34:46Z</date>
</dict>
</plist>

View File

@ -24,7 +24,7 @@
<key>SnapshotCompletedDate</key>
<date>2019-07-27T13:16:43Z</date>
<key>SnapshotLastValidated</key>
<date>2020-10-10T05:22:36Z</date>
<date>2020-11-01T02:34:46Z</date>
<key>SnapshotTables</key>
<dict/>
</dict>

View File

@ -1,6 +1,10 @@
""" Test basic methods for Mojave 10.14.6 """
import datetime
from collections import namedtuple
import pytest
from collections import namedtuple
from osxphotos._constants import _UNKNOWN_PERSON
PHOTOS_DB = "./tests/Test-10.14.6.photoslibrary/database/photos.db"
@ -535,6 +539,31 @@ def test_date_modified_invalid(photosdb):
assert p.date_modified is None
def test_date_modified(photosdb):
""" Test date modified for photo that has been edited """
photos = photosdb.photos(uuid=[UUID_DICT["has_adjustments"]])
p = photos[0]
assert p.date_modified == datetime.datetime(
2019,
11,
27,
1,
30,
16,
681150,
tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=72000)),
)
def test_date_modified_none(photosdb):
""" Test date modified for a photo that hasn't been edited """
photos = photosdb.photos(uuid=[UUID_DICT["no_adjustments"]])
p = photos[0]
assert p.date_modified is None
def test_uti(photosdb):
for uuid, utis in UUID_UTI_DICT.items():
photo = photosdb.get_photo(uuid)