Added --export-raw to CLI export

This commit is contained in:
Rhet Turnbull
2020-04-16 23:10:33 -07:00
parent f398e9116f
commit 7d55844390
2 changed files with 31 additions and 2 deletions

View File

@@ -889,6 +889,13 @@ def query(
help="If a photo is a live photo export the associated live video component." help="If a photo is a live photo export the associated live video component."
" Live video will have same name as photo but with .mov extension. ", " Live video will have same name as photo but with .mov extension. ",
) )
@click.option(
"--export-raw",
is_flag=True,
help="If a photo was imported in RAW format with associated jpeg, also export the "
"RAW photo in addition to the jpeg. (By default, Photos treats the jpeg as the "
"original image.)",
)
@click.option( @click.option(
"--original-name", "--original-name",
is_flag=True, is_flag=True,
@@ -976,6 +983,7 @@ def export(
export_edited, export_edited,
export_bursts, export_bursts,
export_live, export_live,
export_raw,
original_name, original_name,
sidecar, sidecar,
only_photos, only_photos,
@@ -1151,6 +1159,7 @@ def export(
exiftool, exiftool,
directory, directory,
no_extended_attributes, no_extended_attributes,
export_raw,
) )
else: else:
for p in photos: for p in photos:
@@ -1168,6 +1177,7 @@ def export(
exiftool, exiftool,
directory, directory,
no_extended_attributes, no_extended_attributes,
export_raw,
) )
if export_paths: if export_paths:
click.echo(f"Exported {p.filename} to {export_paths}") click.echo(f"Exported {p.filename} to {export_paths}")
@@ -1553,6 +1563,7 @@ def export_photo(
exiftool, exiftool,
directory, directory,
no_extended_attributes, no_extended_attributes,
export_raw,
): ):
""" Helper function for export that does the actual export """ Helper function for export that does the actual export
photo: PhotoInfo object photo: PhotoInfo object
@@ -1568,6 +1579,7 @@ def export_photo(
exiftool: use exiftool to write EXIF metadata directly to exported photo exiftool: use exiftool to write EXIF metadata directly to exported photo
directory: template used to determine output directory directory: template used to determine output directory
no_extended_attributes: boolean; if True, exports photo without preserving extended attributes no_extended_attributes: boolean; if True, exports photo without preserving extended attributes
export_raw: boolean; if True exports RAW image associate with the photo
returns list of path(s) of exported photo or None if photo was missing returns list of path(s) of exported photo or None if photo was missing
""" """
@@ -1646,6 +1658,7 @@ def export_photo(
sidecar_json=sidecar_json, sidecar_json=sidecar_json,
sidecar_xmp=sidecar_xmp, sidecar_xmp=sidecar_xmp,
live_photo=export_live, live_photo=export_live,
raw_photo=export_raw,
overwrite=overwrite, overwrite=overwrite,
use_photos_export=use_photos_export, use_photos_export=use_photos_export,
exiftool=exiftool, exiftool=exiftool,

View File

@@ -254,7 +254,7 @@ class PhotoInfo:
# data on how Photos stores and retrieves RAW images, this seems to be working # data on how Photos stores and retrieves RAW images, this seems to be working
if self._db._db_version < _PHOTOS_5_VERSION: if self._db._db_version < _PHOTOS_5_VERSION:
logging.warning("Not yet implemented for Photos version < 5") logging.warning("RAW support not yet implemented for Photos version < 5")
return None return None
if self._info["isMissing"] == 1: if self._info["isMissing"] == 1:
@@ -589,7 +589,7 @@ class PhotoInfo:
def has_raw(self): def has_raw(self):
""" returns True if photo has an associated RAW image, otherwise False """ """ returns True if photo has an associated RAW image, otherwise False """
if self._db._db_version < _PHOTOS_5_VERSION: if self._db._db_version < _PHOTOS_5_VERSION:
logging.warning("Not yet implemented for Photos version < 5") logging.warning("RAW support not yet implemented for Photos version < 5")
return None return None
return self._info["has_raw"] return self._info["has_raw"]
@@ -607,6 +607,7 @@ class PhotoInfo:
*filename, *filename,
edited=False, edited=False,
live_photo=False, live_photo=False,
raw_photo=False,
overwrite=False, overwrite=False,
increment=True, increment=True,
sidecar_json=False, sidecar_json=False,
@@ -628,6 +629,7 @@ class PhotoInfo:
edited: (boolean, default=False); if True will export the edited version of the photo edited: (boolean, default=False); if True will export the edited version of the photo
(or raise exception if no edited version) (or raise exception if no edited version)
live_photo: (boolean, default=False); if True, will also export the associted .mov for live photos live_photo: (boolean, default=False); if True, will also export the associted .mov for live photos
raw_photo: (boolean, default=False); if True, will also export the associted RAW photo
overwrite: (boolean, default=False); if True will overwrite files if they alreay exist overwrite: (boolean, default=False); if True will overwrite files if they alreay exist
increment: (boolean, default=True); if True, will increment file name until a non-existant name is found increment: (boolean, default=True); if True, will increment file name until a non-existant name is found
if overwrite=False and increment=False, export will fail if destination file already exists if overwrite=False and increment=False, export will fail if destination file already exists
@@ -777,6 +779,20 @@ class PhotoInfo:
exported_files.append(str(live_name)) exported_files.append(str(live_name))
else: else:
logging.warning(f"Skipping missing live movie for {filename}") logging.warning(f"Skipping missing live movie for {filename}")
# copy associated RAW image if requested
if raw_photo and self.has_raw:
raw_path = pathlib.Path(self.path_raw)
raw_ext = raw_path.suffix
raw_name = dest.parent / f"{dest.stem}{raw_ext}"
if raw_path is not None:
logging.debug(
f"Exporting RAW photo of {filename} as {raw_name.name}"
)
_copy_file(str(raw_path), str(raw_name), norsrc=no_xattr)
exported_files.append(str(raw_name))
else:
logging.warning(f"Skipping missing RAW photo for {filename}")
else: else:
# use_photo_export # use_photo_export
exported = None exported = None