Refactored fix for #627
This commit is contained in:
@@ -3043,53 +3043,24 @@ def export_photo_to_directory(
|
|||||||
"""Export photo to directory dest_path"""
|
"""Export photo to directory dest_path"""
|
||||||
|
|
||||||
results = ExportResults()
|
results = ExportResults()
|
||||||
# TODO: can be updated to let export do all the missing logic
|
|
||||||
if export_original:
|
# don't try to export photos in the trash if they're missing
|
||||||
if missing and not preview_if_missing:
|
photo_path = photo.path if export_original else photo.path_edited
|
||||||
space = " " if not verbose else ""
|
if photo.intrash and not photo_path and not preview_if_missing:
|
||||||
verbose_(
|
# skip deleted files if they're missing
|
||||||
f"{space}Skipping missing photo {photo.original_filename} ({photo.uuid})"
|
|
||||||
)
|
|
||||||
results.missing.append(str(pathlib.Path(dest_path) / filename))
|
|
||||||
elif (
|
|
||||||
photo.intrash
|
|
||||||
and (not photo.path or (download_missing or use_photos_export))
|
|
||||||
and not preview_if_missing
|
|
||||||
):
|
|
||||||
# skip deleted files if they're missing or using use_photos_export
|
|
||||||
# as AppleScript/PhotoKit cannot export deleted photos
|
# as AppleScript/PhotoKit cannot export deleted photos
|
||||||
space = " " if not verbose else ""
|
|
||||||
verbose_(
|
verbose_(
|
||||||
f"{space}Skipping missing deleted photo {photo.original_filename} ({photo.uuid})"
|
f"Skipping missing deleted photo {photo.original_filename} ({photo.uuid})"
|
||||||
)
|
|
||||||
results.missing.append(str(pathlib.Path(dest_path) / filename))
|
|
||||||
return results
|
|
||||||
elif not edited:
|
|
||||||
verbose_(f"Skipping original version of {photo.original_filename}")
|
|
||||||
return results
|
|
||||||
else:
|
|
||||||
# exporting the edited version
|
|
||||||
if missing and not preview_if_missing:
|
|
||||||
space = " " if not verbose else ""
|
|
||||||
verbose_(f"{space}Skipping missing edited photo for {filename}")
|
|
||||||
results.missing.append(str(pathlib.Path(dest_path) / filename))
|
|
||||||
return results
|
|
||||||
elif (
|
|
||||||
photo.intrash
|
|
||||||
and (not photo.path_edited or (download_missing or use_photos_export))
|
|
||||||
and not preview_if_missing
|
|
||||||
):
|
|
||||||
# skip deleted files if they're missing or using use_photos_export
|
|
||||||
# as AppleScript/PhotoKit cannot export deleted photos
|
|
||||||
space = " " if not verbose else ""
|
|
||||||
verbose_(
|
|
||||||
f"{space}Skipping missing deleted photo {photo.original_filename} ({photo.uuid})"
|
|
||||||
)
|
)
|
||||||
results.missing.append(str(pathlib.Path(dest_path) / filename))
|
results.missing.append(str(pathlib.Path(dest_path) / filename))
|
||||||
return results
|
return results
|
||||||
|
|
||||||
render_options = RenderOptions(export_dir=export_dir, dest_path=dest_path)
|
render_options = RenderOptions(export_dir=export_dir, dest_path=dest_path)
|
||||||
|
|
||||||
|
if not export_original and not edited:
|
||||||
|
verbose_(f"Skipping original version of {photo.original_filename}")
|
||||||
|
return results
|
||||||
|
|
||||||
tries = 0
|
tries = 0
|
||||||
while tries <= retry:
|
while tries <= retry:
|
||||||
tries += 1
|
tries += 1
|
||||||
|
|||||||
@@ -449,15 +449,16 @@ class PhotoExporter:
|
|||||||
dest,
|
dest,
|
||||||
options=options,
|
options=options,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
verbose(
|
||||||
|
f"Skipping missing {'edited' if options.edited else 'original'} photo {self.photo.original_filename} ({self.photo.uuid})"
|
||||||
|
)
|
||||||
|
all_results.missing.append(dest)
|
||||||
|
|
||||||
# copy live photo associated .mov if requested
|
# copy live photo associated .mov if requested
|
||||||
if (
|
if export_original and options.live_photo and self.photo.live_photo:
|
||||||
export_original
|
|
||||||
and options.live_photo
|
|
||||||
and self.photo.live_photo
|
|
||||||
and staged_files.original_live
|
|
||||||
):
|
|
||||||
live_name = dest.parent / f"{dest.stem}.mov"
|
live_name = dest.parent / f"{dest.stem}.mov"
|
||||||
|
if staged_files.original_live:
|
||||||
src_live = staged_files.original_live
|
src_live = staged_files.original_live
|
||||||
all_results += self._export_photo(
|
all_results += self._export_photo(
|
||||||
src_live,
|
src_live,
|
||||||
@@ -465,14 +466,15 @@ class PhotoExporter:
|
|||||||
# don't try to convert the live photo
|
# don't try to convert the live photo
|
||||||
options=dataclasses.replace(options, convert_to_jpeg=False),
|
options=dataclasses.replace(options, convert_to_jpeg=False),
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
verbose(
|
||||||
|
f"Skipping missing live photo for {self.photo.original_filename} ({self.photo.uuid})"
|
||||||
|
)
|
||||||
|
all_results.missing.append(live_name)
|
||||||
|
|
||||||
if (
|
if export_edited and options.live_photo and self.photo.live_photo:
|
||||||
export_edited
|
|
||||||
and options.live_photo
|
|
||||||
and self.photo.live_photo
|
|
||||||
and staged_files.edited_live
|
|
||||||
):
|
|
||||||
live_name = dest.parent / f"{dest.stem}.mov"
|
live_name = dest.parent / f"{dest.stem}.mov"
|
||||||
|
if staged_files.edited_live:
|
||||||
src_live = staged_files.edited_live
|
src_live = staged_files.edited_live
|
||||||
all_results += self._export_photo(
|
all_results += self._export_photo(
|
||||||
src_live,
|
src_live,
|
||||||
@@ -480,9 +482,15 @@ class PhotoExporter:
|
|||||||
# don't try to convert the live photo
|
# don't try to convert the live photo
|
||||||
options=dataclasses.replace(options, convert_to_jpeg=False),
|
options=dataclasses.replace(options, convert_to_jpeg=False),
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
verbose(
|
||||||
|
f"Skipping missing edited live photo for {self.photo.original_filename} ({self.photo.uuid})"
|
||||||
|
)
|
||||||
|
all_results.missing.append(live_name)
|
||||||
|
|
||||||
# copy associated RAW image if requested
|
# copy associated RAW image if requested
|
||||||
if options.raw_photo and self.photo.has_raw and staged_files.raw:
|
if options.raw_photo and self.photo.has_raw:
|
||||||
|
if staged_files.raw:
|
||||||
raw_path = pathlib.Path(staged_files.raw)
|
raw_path = pathlib.Path(staged_files.raw)
|
||||||
raw_ext = raw_path.suffix
|
raw_ext = raw_path.suffix
|
||||||
raw_name = dest.parent / f"{dest.stem}{raw_ext}"
|
raw_name = dest.parent / f"{dest.stem}{raw_ext}"
|
||||||
@@ -491,9 +499,18 @@ class PhotoExporter:
|
|||||||
raw_name,
|
raw_name,
|
||||||
options=options,
|
options=options,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
# guess at most likely raw name
|
||||||
|
raw_ext = get_preferred_uti_extension(self.photo.uti_raw) or "raw"
|
||||||
|
raw_name = dest.parent / f"{dest.stem}.{raw_ext}"
|
||||||
|
all_results.missing.append(raw_name)
|
||||||
|
verbose(
|
||||||
|
f"Skipping missing raw photo for {self.photo.original_filename} ({self.photo.uuid})"
|
||||||
|
)
|
||||||
|
|
||||||
# copy preview image if requested
|
# copy preview image if requested
|
||||||
if options.preview and staged_files.preview:
|
if options.preview:
|
||||||
|
if staged_files.preview:
|
||||||
# Photos keeps multiple different derivatives and path_derivatives returns list of them
|
# Photos keeps multiple different derivatives and path_derivatives returns list of them
|
||||||
# first derivative is the largest so export that one
|
# first derivative is the largest so export that one
|
||||||
preview_path = pathlib.Path(staged_files.preview)
|
preview_path = pathlib.Path(staged_files.preview)
|
||||||
@@ -514,6 +531,13 @@ class PhotoExporter:
|
|||||||
preview_name,
|
preview_name,
|
||||||
options=options,
|
options=options,
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
# don't know what actual preview suffix would be but most likely jpeg
|
||||||
|
preview_name = dest.parent / f"{dest.stem}{options.preview_suffix}.jpeg"
|
||||||
|
all_results.missing.append(preview_name)
|
||||||
|
verbose(
|
||||||
|
f"Skipping missing preview photo for {self.photo.original_filename} ({self.photo.uuid})"
|
||||||
|
)
|
||||||
|
|
||||||
all_results += self._write_sidecar_files(dest=dest, options=options)
|
all_results += self._write_sidecar_files(dest=dest, options=options)
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user