Skip to content

Commit

Permalink
Fixed increment to increase with each photo
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Jan 18, 2025
1 parent 7c991f8 commit 96f1758
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions examples/increment_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Incrementally adjust the time of photos by a fixed amount."""
"""Incrementally adjust the time of photos by a fixed amount, incrementing the time for each photo."""

from __future__ import annotations

Expand Down Expand Up @@ -27,7 +27,12 @@ def increment(time_delta, dry_run, album_name, **kwargs):
osxphotos run increment_time.py --time-delta 10 MyAlbum
will increment the time of all photos in the album "MyAlbum" by 10 seconds.
will increment the time of each photo in the album "MyAlbum" by 10 seconds
starting with the first photo in the album. The time delta will be added to
the time of each photo in the album in the order they are sorted in the album.
Thus the first photo will be incremented by 10 seconds, the second photo by 20 seconds,
and so on.
Photos will be processed using the current sort order for the album.
"""
Expand All @@ -48,13 +53,15 @@ def increment(time_delta, dry_run, album_name, **kwargs):
return

echo(f"Adjusting {len(photos)} photo(s) by {time_delta} seconds")
offset = datetime.timedelta(seconds=time_delta)
for photo in photos:
try:
photo_ = photoscript.Photo(photo.uuid)
except Exception as e:
echo(f"Error accessing photo {photo.uuid}: {e}")
continue
new_date = photo_.date + datetime.timedelta(seconds=time_delta)
new_date = photo_.date + offset
offset = offset + datetime.timedelta(seconds=time_delta)
echo(
f"Adjusting {photo.original_filename} ({photo.uuid}) from {photo_.date} to {new_date}"
)
Expand Down

0 comments on commit 96f1758

Please sign in to comment.