From dd20b8d8ac3b16d3b72a26b97dcc620b11e3a7c0 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 14 Mar 2020 13:40:15 -0700 Subject: [PATCH] Fixed download-missing to only download when actually missing --- osxphotos/__main__.py | 18 +++++++++++++----- osxphotos/_version.py | 2 +- osxphotos/photoinfo.py | 3 +++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index 95006c8d..0dbf9f43 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -1330,6 +1330,11 @@ def export_photo( if "xmp" in sidecar: sidecar_xmp = True + # if download_missing and the photo is missing or path doesn't exist, + # try to download with Photos + use_photos_export = download_missing and ( + photo.ismissing or not os.path.exists(photo.path) + ) photo_path = photo.export( dest, filename, @@ -1337,14 +1342,19 @@ def export_photo( sidecar_xmp=sidecar_xmp, live_photo=export_live, overwrite=overwrite, - use_photos_export=download_missing, + use_photos_export=use_photos_export, exiftool=exiftool, ) # if export-edited, also export the edited version # verify the photo has adjustments and valid path to avoid raising an exception if export_edited and photo.hasadjustments: - if download_missing or photo.path_edited is not None: + # if download_missing and the photo is missing or path doesn't exist, + # try to download with Photos + use_photos_export = download_missing and photo.path_edited is None + if not download_missing and photo.path_edited is None: + click.echo(f"Skipping missing edited photo for {filename}") + else: edited_name = pathlib.Path(filename) edited_name = f"{edited_name.stem}_edited{edited_name.suffix}" if verbose: @@ -1356,11 +1366,9 @@ def export_photo( sidecar_xmp=sidecar_xmp, overwrite=overwrite, edited=True, - use_photos_export=download_missing, + use_photos_export=use_photos_export, exiftool=exiftool, ) - else: - click.echo(f"Skipping missing edited photo for {filename}") return photo_path diff --git a/osxphotos/_version.py b/osxphotos/_version.py index c67506b5..d72f474f 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.22.17" +__version__ = "0.22.19" diff --git a/osxphotos/photoinfo.py b/osxphotos/photoinfo.py index 39835440..387a3b6f 100644 --- a/osxphotos/photoinfo.py +++ b/osxphotos/photoinfo.py @@ -524,6 +524,8 @@ class PhotoInfo: # list of all files exported during this call to export exported_files = [] + logging.debug(f"dest ={dest}.filename={filename}") + # check arguments and get destination path and filename (if provided) if filename and len(filename) > 2: raise TypeError( @@ -561,6 +563,7 @@ class PhotoInfo: # check destination path dest = pathlib.Path(dest) filename = pathlib.Path(filename) + logging.debug(f"dest ={dest}.filename={filename}") dest = dest / filename # check to see if file exists and if so, add (1), (2), etc until we find one that works