Fixed albums for burst images, closes #401, #403, #404

This commit is contained in:
Rhet Turnbull
2021-03-27 08:11:33 -07:00
parent d77eba12b2
commit a941f66d62
8 changed files with 169 additions and 14 deletions

View File

@@ -1,3 +1,3 @@
""" version info """
__version__ = "0.41.4"
__version__ = "0.41.5"

View File

@@ -1408,6 +1408,9 @@ def export(
is_reference=is_reference,
in_album=in_album,
not_in_album=not_in_album,
burst_photos=export_bursts,
# skip missing bursts if using --download-missing by itself as AppleScript otherwise causes errors
missing_bursts=(download_missing and use_photokit) or not download_missing,
)
if photos:
@@ -1416,13 +1419,6 @@ def export(
previous_uuids = {uuid: 1 for uuid in export_db.get_previous_uuids()}
photos = [p for p in photos if p.uuid not in previous_uuids]
if export_bursts:
# add the burst_photos to the export set
photos_burst = [p for p in photos if p.burst]
for burst in photos_burst:
burst_set = [p for p in burst.burst_photos if not p.ismissing]
photos.extend(burst_set)
num_photos = len(photos)
# TODO: photos or photo appears several times, pull into a separate function
photo_str = "photos" if num_photos > 1 else "photo"
@@ -2019,6 +2015,8 @@ def _query(
is_reference=False,
in_album=False,
not_in_album=False,
burst_photos=None,
missing_bursts=None,
):
"""Run a query against PhotosDB to extract the photos based on user supply criteria used by query and export commands
@@ -2262,6 +2260,27 @@ def _query(
if to_time:
photos = [p for p in photos if p.date.time() <= to_time]
if burst_photos:
# add the burst_photos to the export set
photos_burst = [p for p in photos if p.burst]
for burst in photos_burst:
if missing_bursts:
# include burst photos that are missing
photos.extend(burst.burst_photos)
else:
# don't include missing burst images (these can't be downloaded with AppleScript)
photos.extend([p for p in burst.burst_photos if not p.ismissing])
# remove duplicates as each burst photo in the set that's selected would
# result in the entire set being added above
# can't use set() because PhotoInfo not hashable
seen_uuids = {}
for p in photos:
if p.uuid in seen_uuids:
continue
seen_uuids[p.uuid] = p
photos = list(seen_uuids.values())
return photos

View File

@@ -453,9 +453,24 @@ class PhotoInfo:
)
return self._albums
@property
def burst_albums(self):
"""If photo is non-selected burst photo, list of albums any other images in the same burst set are contained in, otherwise returns self.albums"""
if self.burst_selected or not self.burst:
return self.albums
try:
return self._burst_albums
except AttributeError:
burst_albums = []
for photo in self.burst_photos:
burst_albums.extend(photo.albums)
self._burst_albums = list(set(burst_albums))
return self._burst_albums
@property
def album_info(self):
""" list of AlbumInfo objects representing albums the photos is contained in """
""" list of AlbumInfo objects representing albums the photo is contained in """
try:
return self._album_info
except AttributeError:
@@ -465,6 +480,21 @@ class PhotoInfo:
]
return self._album_info
@property
def burst_album_info(self):
""" If photo is a non-selected burst photo, returns list of AlbumInfo objects representing albums any other photos in the same burst set are contained in, otherwise returns self.album_info """
if self.burst_selected or not self.burst:
return self.album_info
try:
return self._burst_album_info
except AttributeError:
burst_album_info = []
for photo in self.burst_photos:
burst_album_info.extend(photo.album_info)
self._burst_album_info = list(set(burst_album_info))
return self._burst_album_info
@property
def import_info(self):
""" ImportInfo object representing import session for the photo or None if no import session """
@@ -680,6 +710,11 @@ class PhotoInfo:
""" Returns True if photo is part of a Burst photo set, otherwise False """
return self._info["burst"]
@property
def burst_selected(self):
""" Returns True if photo is a burst photo and has been selected from the burst set by the user, otherwise False """
return self._info["burst_key"]
@property
def burst_photos(self):
"""If photo is a burst photo, returns list of PhotoInfo objects

View File

@@ -840,7 +840,7 @@ class PhotoTemplate:
""" return list of values for a multi-valued template field """
values = []
if field == "album":
values = self.photo.albums
values = self.photo.burst_albums if self.photo.burst else self.photo.albums
elif field == "keyword":
values = self.photo.keywords
elif field == "person":
@@ -854,7 +854,11 @@ class PhotoTemplate:
elif field == "folder_album":
values = []
# photos must be in an album to be in a folder
for album in self.photo.album_info:
if self.photo.burst:
album_info = self.photo.burst_album_info
else:
album_info = self.photo.album_info
for album in album_info:
if album.folder_names:
# album in folder
if dirname: