Skip to content

Commit

Permalink
dont write sidecar file during dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
chkuendig committed Jan 14, 2025
1 parent 72fa8a5 commit 9cebe15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def download_photo_(counter: Counter, photo: PhotoAsset) -> bool:
logger.info("Downloaded %s", truncated_path)

if xmp_sidecar:
generate_xmp_file(logger, download_path, photo._asset_record)
generate_xmp_file(logger, download_path, photo._asset_record, dry_run)

# Also download the live photo if present
if not skip_live_photos:
Expand Down
9 changes: 5 additions & 4 deletions src/icloudpd/xmp_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class XMPMetadata(NamedTuple):


def generate_xmp_file(
logger: logging.Logger, download_path: str, asset_record: dict[str, Any]
logger: logging.Logger, download_path: str, asset_record: dict[str, Any], dry_run: bool
) -> None:
sidecar_path: str = download_path + ".xmp"
can_write_file: bool = True
Expand Down Expand Up @@ -68,9 +68,10 @@ def generate_xmp_file(
if can_write_file:
xmp_metadata: XMPMetadata = build_metadata(asset_record)
xml_doc: ElementTree.Element = generate_xml(xmp_metadata)
# Write the XML to the file
with open(sidecar_path, "wb") as f:
f.write(ElementTree.tostring(xml_doc, encoding="utf-8", xml_declaration=True))
if not dry_run:
# Write the XML to the file
with open(sidecar_path, "wb") as f:
f.write(ElementTree.tostring(xml_doc, encoding="utf-8", xml_declaration=True))


def build_metadata(asset_record: dict[str, Any]) -> XMPMetadata:
Expand Down

0 comments on commit 9cebe15

Please sign in to comment.