Added --export-raw to CLI export
This commit is contained in:
parent
f398e9116f
commit
7d55844390
@ -889,6 +889,13 @@ def query(
|
||||
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. ",
|
||||
)
|
||||
@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(
|
||||
"--original-name",
|
||||
is_flag=True,
|
||||
@ -976,6 +983,7 @@ def export(
|
||||
export_edited,
|
||||
export_bursts,
|
||||
export_live,
|
||||
export_raw,
|
||||
original_name,
|
||||
sidecar,
|
||||
only_photos,
|
||||
@ -1151,6 +1159,7 @@ def export(
|
||||
exiftool,
|
||||
directory,
|
||||
no_extended_attributes,
|
||||
export_raw,
|
||||
)
|
||||
else:
|
||||
for p in photos:
|
||||
@ -1168,6 +1177,7 @@ def export(
|
||||
exiftool,
|
||||
directory,
|
||||
no_extended_attributes,
|
||||
export_raw,
|
||||
)
|
||||
if export_paths:
|
||||
click.echo(f"Exported {p.filename} to {export_paths}")
|
||||
@ -1553,6 +1563,7 @@ def export_photo(
|
||||
exiftool,
|
||||
directory,
|
||||
no_extended_attributes,
|
||||
export_raw,
|
||||
):
|
||||
""" Helper function for export that does the actual export
|
||||
photo: PhotoInfo object
|
||||
@ -1568,6 +1579,7 @@ def export_photo(
|
||||
exiftool: use exiftool to write EXIF metadata directly to exported photo
|
||||
directory: template used to determine output directory
|
||||
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
|
||||
"""
|
||||
|
||||
@ -1646,6 +1658,7 @@ def export_photo(
|
||||
sidecar_json=sidecar_json,
|
||||
sidecar_xmp=sidecar_xmp,
|
||||
live_photo=export_live,
|
||||
raw_photo=export_raw,
|
||||
overwrite=overwrite,
|
||||
use_photos_export=use_photos_export,
|
||||
exiftool=exiftool,
|
||||
|
||||
@ -254,7 +254,7 @@ class PhotoInfo:
|
||||
# data on how Photos stores and retrieves RAW images, this seems to be working
|
||||
|
||||
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
|
||||
|
||||
if self._info["isMissing"] == 1:
|
||||
@ -589,7 +589,7 @@ class PhotoInfo:
|
||||
def has_raw(self):
|
||||
""" returns True if photo has an associated RAW image, otherwise False """
|
||||
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 self._info["has_raw"]
|
||||
@ -607,6 +607,7 @@ class PhotoInfo:
|
||||
*filename,
|
||||
edited=False,
|
||||
live_photo=False,
|
||||
raw_photo=False,
|
||||
overwrite=False,
|
||||
increment=True,
|
||||
sidecar_json=False,
|
||||
@ -628,6 +629,7 @@ class PhotoInfo:
|
||||
edited: (boolean, default=False); if True will export the edited version of the photo
|
||||
(or raise exception if no edited version)
|
||||
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
|
||||
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
|
||||
@ -777,6 +779,20 @@ class PhotoInfo:
|
||||
exported_files.append(str(live_name))
|
||||
else:
|
||||
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:
|
||||
# use_photo_export
|
||||
exported = None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user