Added date_added, #439

This commit is contained in:
Rhet Turnbull
2021-05-05 06:50:41 -07:00
parent 442b542794
commit 0f41588701
3 changed files with 28 additions and 3 deletions

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.42.15"
__version__ = "0.42.16"

View File

@@ -488,7 +488,7 @@ class PhotoInfo:
try:
return self._burst_album_info
except AttributeError:
burst_album_info = list(self.album_info)
burst_album_info = list(self.album_info)
for photo in self.burst_photos:
if photo.burst_key:
burst_album_info.extend(photo.album_info)
@@ -604,6 +604,21 @@ class PhotoInfo:
else:
return None
@property
def date_added(self):
""" Date photo was added to the database """
if self._db._db_version <= _PHOTOS_4_VERSION:
return None
added_date = self._info["added_date"]
if added_date:
seconds = self._info["imageTimeZoneOffsetSeconds"] or 0
delta = timedelta(seconds=seconds)
tz = timezone(delta)
return added_date.astimezone(tz=tz)
else:
return None
@property
def location(self):
""" returns (latitude, longitude) as float in degrees or None """

View File

@@ -1020,6 +1020,9 @@ class PhotosDB:
tz = timezone(timedelta(0))
self._dbphotos[uuid]["imageDate"] = imagedate.astimezone(tz=tz)
# haven't figured out added_date for Photos 4
self._dbphotos[uuid]["added_date"] = None
self._dbphotos[uuid]["mainRating"] = row[6]
self._dbphotos[uuid]["hasAdjustments"] = row[7]
self._dbphotos[uuid]["hasKeywords"] = row[8]
@@ -1867,7 +1870,8 @@ class PhotosDB:
{asset_table}.ZADJUSTMENTTIMESTAMP,
{asset_table}.ZVISIBILITYSTATE,
{asset_table}.ZTRASHEDDATE,
{asset_table}.ZSAVEDASSETTYPE
{asset_table}.ZSAVEDASSETTYPE,
{asset_table}.ZADDEDDATE
FROM {asset_table}
JOIN ZADDITIONALASSETATTRIBUTES ON ZADDITIONALASSETATTRIBUTES.ZASSET = {asset_table}.Z_PK
ORDER BY {asset_table}.ZUUID """
@@ -1915,6 +1919,7 @@ class PhotosDB:
# 38 ZGENERICASSET.ZVISIBILITYSTATE -- 0 if visible, 2 if not (e.g. a burst image)
# 39 ZGENERICASSET.ZTRASHEDDATE -- date item placed in the trash or null if not in trash
# 40 ZGENERICASSET.ZSAVEDASSETTYPE -- how item imported
# 41 ZGENERICASSET.ZADDEDDATE -- date item added to the library
for row in c:
uuid = row[0]
@@ -2094,6 +2099,11 @@ class PhotosDB:
info["saved_asset_type"] = row[40]
info["isreference"] = row[40] == 10
try:
info["added_date"] = datetime.fromtimestamp(row[41] + TIME_DELTA)
except (ValueError, TypeError):
info["added_date"] = datetime(1970, 1, 1)
# initialize import session info which will be filled in later
# not every photo has an import session so initialize all records now
info["import_session"] = None