Support positional data file with description metadata

This commit is contained in:
hbrain 2026-05-25 17:52:17 +00:00
parent dfa98d03a0
commit 37efb3cef1

View file

@ -47,6 +47,7 @@ class MovieData:
title: str = "" title: str = ""
date: str = "" date: str = ""
place: str = "" place: str = ""
description: str = ""
captions: dict[str, str] | None = None captions: dict[str, str] | None = None
@ -521,38 +522,50 @@ def parse_data_file(path: Path | None) -> MovieData:
if not path or not path.exists(): if not path or not path.exists():
return MovieData(captions={}) return MovieData(captions={})
lines = [line.strip() for line in path.read_text(encoding="utf-8", errors="replace").splitlines()] raw_lines = [line.rstrip() for line in path.read_text(encoding="utf-8", errors="replace").splitlines()]
lines = [line for line in lines if line and not line.startswith("#")]
data = MovieData(captions={}) data = MovieData(captions={})
plain: list[str] = [] header: list[str] = []
description: list[str] = []
in_description = False
for line in lines: for raw in raw_lines:
line = raw.strip()
if line.startswith("#"):
continue
if not line:
if header or in_description:
in_description = True
if description:
description.append("")
continue
if ":" in line: if ":" in line:
key, value = line.split(":", 1) key, value = line.split(":", 1)
key = key.strip() key = key.strip()
value = value.strip() value = value.strip()
low = key.lower() if key:
if low in {"title", "name"}:
data.title = value
elif low in {"date", "dates", "when"}:
data.date = value
elif low in {"place", "location", "where"}:
data.place = value
elif Path(key).suffix.lower() in IMAGE_EXTS | VIDEO_EXTS:
data.captions[key] = value data.captions[key] = value
continue
if in_description:
description.append(line)
else: else:
plain.append(line) header.append(line)
else:
plain.append(line)
# Simple mode: first three non-key lines are title/location/date. # New simple mode:
if plain: # title
data.title = data.title or plain[0] # location
if len(plain) > 1: # date
data.place = data.place or plain[1] #
if len(plain) > 2: # description
data.date = data.date or plain[2] #
# Any key:value line anywhere is a per-file caption.
# Location and/or date may be omitted by placing the blank line earlier.
if header:
data.title = header[0]
if len(header) > 1:
data.place = header[1]
if len(header) > 2:
data.date = header[2]
data.description = "\n".join(description).strip()
return data return data
@ -888,6 +901,8 @@ def build_video(
"location": data.place, "location": data.place,
"place": data.place, "place": data.place,
"com.apple.quicktime.location.name": data.place, "com.apple.quicktime.location.name": data.place,
"description": data.description,
"synopsis": data.description,
"artist": "Bubulescu.Org", "artist": "Bubulescu.Org",
"comment": "Created with movmaker", "comment": "Created with movmaker",
"creation_time": creation_date.isoformat(), "creation_time": creation_date.isoformat(),