Improve photo organization controls and reference completion

This commit is contained in:
ajp_anton committed 2026-10-06 19:27:32 +00:00
1 parent ad2b15994f
commit e3633b8e1a
6 files changed
+316 -41

No files matched your search

+32 -5
View File
@@ -42,10 +42,11 @@ class UserChoices:
group_min_size: int
process_pto_files: bool
infer_missing_timestamps: bool
group_files: bool = True
@property
def group_photos(self) -> bool:
return self.organize_files and self.group_min_size >= 2
return self.organize_files and self.group_files and self.group_min_size >= 2
@property
def move_to_working_dir(self) -> bool:
@@ -114,7 +115,9 @@ def filename_timestamp_stem(stem: str, timestamp: datetime, mode: str) -> str:
def plan_names(records: list[MediaRecord], choices: UserChoices) -> None:
by_stem = _unique_records_by_stem(records)
for record in records:
record.new_stem = record.rename_skip_reason = None
record.new_stem = record.final_name = record.rename_skip_reason = None
if choices.rename_mode == "none":
continue
if record.adjusted_time is None:
record.new_stem = _camera_range_stem(record, by_stem)
record.rename_skip_reason = None if record.new_stem else "missing timestamp"
@@ -227,6 +230,31 @@ def plan_targets(records: list[MediaRecord], choices: UserChoices) -> None:
record.target_path = directory / name
if record.sidecar:
record.target_sidecar = directory / f"{Path(name).stem}M01.XML"
_make_targets_unique(records)
def _make_targets_unique(records: list[MediaRecord]) -> None:
used: set[tuple[Path, str]] = set()
ordered = sorted(
records,
key=lambda record: (
record.target_path != record.path,
group_sort_key(record),
),
)
for record in ordered:
assert record.target_path is not None
target = record.target_path
index = 0
while (target.parent.resolve(), target.name.lower()) in used:
index += 1
target = record.target_path.with_name(
f"{record.target_path.stem}-{index}{record.target_path.suffix}"
)
used.add((target.parent.resolve(), target.name.lower()))
record.target_path = target
if record.sidecar:
record.target_sidecar = target.with_name(f"{target.stem}M01.XML")
def normalize_reference(value: str) -> str:
@@ -370,9 +398,8 @@ def prepare_plan(records: list[MediaRecord], choices: UserChoices, references: l
apply_time_offset(records, choices.time_offset)
burst_groups = detect_photo_groups(records, choices.group_min_size) if choices.group_photos else []
groups = merge_record_groups(records, [*burst_groups, *(reference.records for reference in references if choices.process_pto_files)])
if groups:
assign_groups(records, groups)
if choices.organize_files:
assign_groups(records, groups)
if choices.group_photos:
infer_group_subseconds(burst_groups)
plan_names(records, choices)
if groups: