diff --git a/osxphotos/photoinfo.py b/osxphotos/photoinfo.py index b0060b37..61519eab 100644 --- a/osxphotos/photoinfo.py +++ b/osxphotos/photoinfo.py @@ -437,6 +437,7 @@ class PhotoInfo: if self.live_photo and not self.ismissing: filename = pathlib.Path(self.path) photopath = filename.parent.joinpath(f"{filename.stem}_3.mov") + photopath = str(photopath) if not os.path.isfile(photopath): # In testing, I've seen occasional missing movie for live photo # these appear to be valid -- e.g. video component not yet downloaded from iCloud @@ -680,7 +681,9 @@ class PhotoInfo: """ string representation of PhotoInfo object """ date_iso = self.date.isoformat() - date_modified_iso = self.date_modified.isoformat() if self.date_modified else None + date_modified_iso = ( + self.date_modified.isoformat() if self.date_modified else None + ) info = { "uuid": self.uuid, @@ -717,7 +720,9 @@ class PhotoInfo: def json(self): """ return JSON representation """ - date_modified_iso = self.date_modified.isoformat() if self.date_modified else None + date_modified_iso = ( + self.date_modified.isoformat() if self.date_modified else None + ) pic = { "uuid": self.uuid, diff --git a/osxphotos/photosdb.py b/osxphotos/photosdb.py index 197e7fa2..20751b83 100644 --- a/osxphotos/photosdb.py +++ b/osxphotos/photosdb.py @@ -532,9 +532,17 @@ class PhotosDB: self._dbphotos[uuid]["modelID"] = row[1] self._dbphotos[uuid]["masterUuid"] = row[2] self._dbphotos[uuid]["filename"] = row[3] - self._dbphotos[uuid]["lastmodifieddate"] = ( - datetime.fromtimestamp(row[4] + td) if row[4] is not None else None - ) + + # There are sometimes negative values for lastmodifieddate in the database + # I don't know what these mean but they will raise exception in datetime if + # not accounted for + if row[4] is not None and row[4] >= 0: + self._dbphotos[uuid]["lastmodifieddate"] = datetime.fromtimestamp( + row[4] + td + ) + else: + self._dbphotos[uuid]["lastmodifieddate"] = None + self._dbphotos[uuid]["imageDate"] = datetime.fromtimestamp(row[5] + td) self._dbphotos[uuid]["mainRating"] = row[6] self._dbphotos[uuid]["hasAdjustments"] = row[7] @@ -998,9 +1006,15 @@ class PhotosDB: info["masterUuid"] = None info["masterFingerprint"] = row[1] info["name"] = row[2] - info["lastmodifieddate"] = ( - datetime.fromtimestamp(row[4] + td) if row[4] is not None else None - ) + + # There are sometimes negative values for lastmodifieddate in the database + # I don't know what these mean but they will raise exception in datetime if + # not accounted for + if row[4] is not None and row[4] >= 0: + info["lastmodifieddate"] = datetime.fromtimestamp(row[4] + td) + else: + info["lastmodifieddate"] = None + info["imageDate"] = datetime.fromtimestamp(row[5] + td) info["imageTimeZoneOffsetSeconds"] = row[6] info["hidden"] = row[9]