diff --git a/osxphotos/cli.py b/osxphotos/cli.py index a76c944b..d8b5fc7a 100644 --- a/osxphotos/cli.py +++ b/osxphotos/cli.py @@ -3043,53 +3043,24 @@ def export_photo_to_directory( """Export photo to directory dest_path""" results = ExportResults() - # TODO: can be updated to let export do all the missing logic - if export_original: - if missing and not preview_if_missing: - space = " " if not verbose else "" - verbose_( - 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 - 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)) - return results - elif not edited: - verbose_(f"Skipping original version of {photo.original_filename}") + + # don't try to export photos in the trash if they're missing + photo_path = photo.path if export_original else photo.path_edited + if photo.intrash and not photo_path and not preview_if_missing: + # skip deleted files if they're missing + # as AppleScript/PhotoKit cannot export deleted photos + verbose_( + f"Skipping missing deleted photo {photo.original_filename} ({photo.uuid})" + ) + results.missing.append(str(pathlib.Path(dest_path) / 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)) - return results 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 while tries <= retry: tries += 1 diff --git a/osxphotos/photoexporter.py b/osxphotos/photoexporter.py index ae8ee60d..6df21a8c 100644 --- a/osxphotos/photoexporter.py +++ b/osxphotos/photoexporter.py @@ -449,71 +449,95 @@ class PhotoExporter: dest, 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 - if ( - export_original - and options.live_photo - and self.photo.live_photo - and staged_files.original_live - ): + if export_original and options.live_photo and self.photo.live_photo: live_name = dest.parent / f"{dest.stem}.mov" - src_live = staged_files.original_live - all_results += self._export_photo( - src_live, - live_name, - # don't try to convert the live photo - options=dataclasses.replace(options, convert_to_jpeg=False), - ) + if staged_files.original_live: + src_live = staged_files.original_live + all_results += self._export_photo( + src_live, + live_name, + # don't try to convert the live photo + 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 ( - export_edited - and options.live_photo - and self.photo.live_photo - and staged_files.edited_live - ): + if export_edited and options.live_photo and self.photo.live_photo: live_name = dest.parent / f"{dest.stem}.mov" - src_live = staged_files.edited_live - all_results += self._export_photo( - src_live, - live_name, - # don't try to convert the live photo - options=dataclasses.replace(options, convert_to_jpeg=False), - ) + if staged_files.edited_live: + src_live = staged_files.edited_live + all_results += self._export_photo( + src_live, + live_name, + # don't try to convert the live photo + 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 - if options.raw_photo and self.photo.has_raw and staged_files.raw: - raw_path = pathlib.Path(staged_files.raw) - raw_ext = raw_path.suffix - raw_name = dest.parent / f"{dest.stem}{raw_ext}" - all_results += self._export_photo( - raw_path, - raw_name, - options=options, - ) + if options.raw_photo and self.photo.has_raw: + if staged_files.raw: + raw_path = pathlib.Path(staged_files.raw) + raw_ext = raw_path.suffix + raw_name = dest.parent / f"{dest.stem}{raw_ext}" + all_results += self._export_photo( + raw_path, + raw_name, + 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 - if options.preview and staged_files.preview: - # Photos keeps multiple different derivatives and path_derivatives returns list of them - # first derivative is the largest so export that one - preview_path = pathlib.Path(staged_files.preview) - preview_ext = preview_path.suffix - preview_name = ( - dest.parent / f"{dest.stem}{options.preview_suffix}{preview_ext}" - ) - # if original is missing, the filename won't have been incremented so - # need to check here to make sure there aren't duplicate preview files in - # the export directory - preview_name = ( - preview_name - if options.overwrite or options.update - else pathlib.Path(increment_filename(preview_name)) - ) - all_results += self._export_photo( - preview_path, - preview_name, - options=options, - ) + if options.preview: + if staged_files.preview: + # Photos keeps multiple different derivatives and path_derivatives returns list of them + # first derivative is the largest so export that one + preview_path = pathlib.Path(staged_files.preview) + preview_ext = preview_path.suffix + preview_name = ( + dest.parent / f"{dest.stem}{options.preview_suffix}{preview_ext}" + ) + # if original is missing, the filename won't have been incremented so + # need to check here to make sure there aren't duplicate preview files in + # the export directory + preview_name = ( + preview_name + if options.overwrite or options.update + else pathlib.Path(increment_filename(preview_name)) + ) + all_results += self._export_photo( + preview_path, + preview_name, + 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) diff --git a/tests/search_info_test_data_10_15_7.json b/tests/search_info_test_data_10_15_7.json index c8c1e62f..c8468bba 100644 --- a/tests/search_info_test_data_10_15_7.json +++ b/tests/search_info_test_data_10_15_7.json @@ -1 +1 @@ -{"UUID_SEARCH_INFO": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": {"labels": ["Cloudy", "Ocean", "Water Body", "Water", "Sky", "Sunset Sunrise", "Outdoor", "Land", "Beach"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "July", "year": "2017", "holidays": ["Independence Day"], "activities": ["Travel", "Celebration", "Holiday", "Trip"], "season": "Summer", "venues": [], "venue_types": [], "media_types": []}, "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": {"labels": ["Clothing", "People", "Adult"], "place_names": [], "streets": ["Beach Blvd S"], "neighborhoods": ["Washington", "Beach Boulevard"], "city": "Orange County Area", "locality_names": ["Huntington Beach"], "state": "California", "state_abbreviation": "", "country": "United States", "bodies_of_water": [], "month": "February", "year": "2021", "holidays": [], "activities": ["Dining", "Lunch"], "season": "Winter", "venues": [], "venue_types": [], "media_types": []}, "A1C36260-92CD-47E2-927A-35DAF16D7882": {"labels": ["Car", "Adult", "Cloudy", "Retriever", "People", "Land", "Grass", "Dog", "Outdoor", "Sky", "Animal", "Mammal", "Canine", "Machine", "Vehicle", "Automobile", "Plant", "Shrub"], "place_names": [], "streets": ["Orange Grove Rd"], "neighborhoods": [], "city": "Orange", "locality_names": ["Hillsborough"], "state": "Piedmont Region", "state_abbreviation": "NC", "country": "United States", "bodies_of_water": [], "month": "June", "year": "2019", "holidays": [], "activities": ["Trip", "Travel"], "season": "Summer", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_NORMALIZED": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": {"labels": ["cloudy", "ocean", "water body", "water", "sky", "sunset sunrise", "outdoor", "land", "beach"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "july", "year": "2017", "holidays": ["independence day"], "activities": ["travel", "celebration", "holiday", "trip"], "season": "summer", "venues": [], "venue_types": [], "media_types": []}, "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": {"labels": ["clothing", "people", "adult"], "place_names": [], "streets": ["beach blvd s"], "neighborhoods": ["washington", "beach boulevard"], "city": "orange county area", "locality_names": ["huntington beach"], "state": "california", "state_abbreviation": "", "country": "united states", "bodies_of_water": [], "month": "february", "year": "2021", "holidays": [], "activities": ["dining", "lunch"], "season": "winter", "venues": [], "venue_types": [], "media_types": []}, "A1C36260-92CD-47E2-927A-35DAF16D7882": {"labels": ["car", "adult", "cloudy", "retriever", "people", "land", "grass", "dog", "outdoor", "sky", "animal", "mammal", "canine", "machine", "vehicle", "automobile", "plant", "shrub"], "place_names": [], "streets": ["orange grove rd"], "neighborhoods": [], "city": "orange", "locality_names": ["hillsborough"], "state": "piedmont region", "state_abbreviation": "nc", "country": "united states", "bodies_of_water": [], "month": "june", "year": "2019", "holidays": [], "activities": ["trip", "travel"], "season": "summer", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_ALL": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": ["Cloudy", "Ocean", "Water Body", "Water", "Sky", "Sunset Sunrise", "Outdoor", "Land", "Beach", "Independence Day", "Travel", "Celebration", "Holiday", "Trip", "July", "2017", "Summer"], "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": ["Clothing", "People", "Adult", "Beach Blvd S", "Washington", "Beach Boulevard", "Huntington Beach", "Dining", "Lunch", "Orange County Area", "California", "United States", "February", "2021", "Winter"], "A1C36260-92CD-47E2-927A-35DAF16D7882": ["Car", "Adult", "Cloudy", "Retriever", "People", "Land", "Grass", "Dog", "Outdoor", "Sky", "Animal", "Mammal", "Canine", "Machine", "Vehicle", "Automobile", "Plant", "Shrub", "Orange Grove Rd", "Hillsborough", "Trip", "Travel", "Orange", "Piedmont Region", "NC", "United States", "June", "2019", "Summer"]}, "UUID_SEARCH_INFO_ALL_NORMALIZED": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": ["cloudy", "ocean", "water body", "water", "sky", "sunset sunrise", "outdoor", "land", "beach", "independence day", "travel", "celebration", "holiday", "trip", "july", "2017", "summer"], "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": ["clothing", "people", "adult", "beach blvd s", "washington", "beach boulevard", "huntington beach", "dining", "lunch", "orange county area", "california", "united states", "february", "2021", "winter"], "A1C36260-92CD-47E2-927A-35DAF16D7882": ["car", "adult", "cloudy", "retriever", "people", "land", "grass", "dog", "outdoor", "sky", "animal", "mammal", "canine", "machine", "vehicle", "automobile", "plant", "shrub", "orange grove rd", "hillsborough", "trip", "travel", "orange", "piedmont region", "nc", "united states", "june", "2019", "summer"]}} +{"UUID_SEARCH_INFO": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": {"labels": ["Cloudy", "Land", "Beach", "Water Body", "Ocean", "Sunset Sunrise", "Outdoor", "Sky", "Water"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "July", "year": "2017", "holidays": ["Independence Day"], "activities": ["Travel", "Celebration", "Holiday", "Trip"], "season": "Summer", "venues": [], "venue_types": [], "media_types": []}, "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": {"labels": ["Adult", "People", "Clothing"], "place_names": [], "streets": ["Beach Blvd S"], "neighborhoods": ["Washington", "Beach Boulevard"], "city": "Orange County Area", "locality_names": ["Huntington Beach"], "state": "California", "state_abbreviation": "", "country": "United States", "bodies_of_water": [], "month": "February", "year": "2021", "holidays": [], "activities": ["Dining", "Lunch"], "season": "Winter", "venues": [], "venue_types": [], "media_types": []}, "A1C36260-92CD-47E2-927A-35DAF16D7882": {"labels": ["Car", "People", "Adult", "Sky", "Cloudy", "Dog", "Retriever", "Mammal", "Canine", "Automobile", "Shrub", "Plant", "Grass", "Machine", "Vehicle", "Outdoor", "Land", "Animal"], "place_names": [], "streets": ["Orange Grove Rd"], "neighborhoods": [], "city": "Orange County", "locality_names": ["Hillsborough"], "state": "Piedmont Region", "state_abbreviation": "NC", "country": "United States", "bodies_of_water": [], "month": "June", "year": "2019", "holidays": [], "activities": ["Trip", "Travel"], "season": "Summer", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_NORMALIZED": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": {"labels": ["cloudy", "land", "beach", "water body", "ocean", "sunset sunrise", "outdoor", "sky", "water"], "place_names": [], "streets": [], "neighborhoods": [], "city": "", "locality_names": [], "state": "", "state_abbreviation": "", "country": "", "bodies_of_water": [], "month": "july", "year": "2017", "holidays": ["independence day"], "activities": ["travel", "celebration", "holiday", "trip"], "season": "summer", "venues": [], "venue_types": [], "media_types": []}, "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": {"labels": ["adult", "people", "clothing"], "place_names": [], "streets": ["beach blvd s"], "neighborhoods": ["washington", "beach boulevard"], "city": "orange county area", "locality_names": ["huntington beach"], "state": "california", "state_abbreviation": "", "country": "united states", "bodies_of_water": [], "month": "february", "year": "2021", "holidays": [], "activities": ["dining", "lunch"], "season": "winter", "venues": [], "venue_types": [], "media_types": []}, "A1C36260-92CD-47E2-927A-35DAF16D7882": {"labels": ["car", "people", "adult", "sky", "cloudy", "dog", "retriever", "mammal", "canine", "automobile", "shrub", "plant", "grass", "machine", "vehicle", "outdoor", "land", "animal"], "place_names": [], "streets": ["orange grove rd"], "neighborhoods": [], "city": "orange county", "locality_names": ["hillsborough"], "state": "piedmont region", "state_abbreviation": "nc", "country": "united states", "bodies_of_water": [], "month": "june", "year": "2019", "holidays": [], "activities": ["trip", "travel"], "season": "summer", "venues": [], "venue_types": [], "media_types": []}}, "UUID_SEARCH_INFO_ALL": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": ["Cloudy", "Land", "Beach", "Water Body", "Ocean", "Sunset Sunrise", "Outdoor", "Sky", "Water", "Independence Day", "Travel", "Celebration", "Holiday", "Trip", "July", "2017", "Summer"], "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": ["Adult", "People", "Clothing", "Beach Blvd S", "Washington", "Beach Boulevard", "Huntington Beach", "Dining", "Lunch", "Orange County Area", "California", "United States", "February", "2021", "Winter"], "A1C36260-92CD-47E2-927A-35DAF16D7882": ["Car", "People", "Adult", "Sky", "Cloudy", "Dog", "Retriever", "Mammal", "Canine", "Automobile", "Shrub", "Plant", "Grass", "Machine", "Vehicle", "Outdoor", "Land", "Animal", "Orange Grove Rd", "Hillsborough", "Trip", "Travel", "Orange County", "Piedmont Region", "NC", "United States", "June", "2019", "Summer"]}, "UUID_SEARCH_INFO_ALL_NORMALIZED": {"DC09F4D8-6173-452D-AC15-725C8D7C185E": ["cloudy", "land", "beach", "water body", "ocean", "sunset sunrise", "outdoor", "sky", "water", "independence day", "travel", "celebration", "holiday", "trip", "july", "2017", "summer"], "AFECD4AB-937C-46AF-A79B-9C9A38AA42B1": ["adult", "people", "clothing", "beach blvd s", "washington", "beach boulevard", "huntington beach", "dining", "lunch", "orange county area", "california", "united states", "february", "2021", "winter"], "A1C36260-92CD-47E2-927A-35DAF16D7882": ["car", "people", "adult", "sky", "cloudy", "dog", "retriever", "mammal", "canine", "automobile", "shrub", "plant", "grass", "machine", "vehicle", "outdoor", "land", "animal", "orange grove rd", "hillsborough", "trip", "travel", "orange county", "piedmont region", "nc", "united states", "june", "2019", "summer"]}}