Support multiline description blocks

This commit is contained in:
hbrain 2026-05-26 07:58:11 +00:00
parent fa6349b15e
commit 0e7f309bd8

View file

@ -523,9 +523,13 @@ def parse_data_file(path: Path | None) -> MovieData:
return MovieData(captions={}) return MovieData(captions={})
data = MovieData(captions={}) data = MovieData(captions={})
for line_no, raw in enumerate(path.read_text(encoding="utf-8", errors="replace").splitlines(), start=1): lines = path.read_text(encoding="utf-8", errors="replace").splitlines()
line = raw.strip() i = 0
while i < len(lines):
line_no = i + 1
line = lines[i].strip()
if not line or line.startswith("#"): if not line or line.startswith("#"):
i += 1
continue continue
if ":" not in line: if ":" not in line:
raise SystemExit(f"Invalid data file syntax in {path} line {line_no}: every entry must be key: value") raise SystemExit(f"Invalid data file syntax in {path} line {line_no}: every entry must be key: value")
@ -533,6 +537,21 @@ def parse_data_file(path: Path | None) -> MovieData:
key = key.strip() key = key.strip()
value = value.strip() value = value.strip()
low = key.lower() low = key.lower()
if value == "|" and low in {"description", "desc", "synopsis"}:
block: list[str] = []
i += 1
while i < len(lines):
raw = lines[i]
if raw.strip() and not raw.startswith((" ", "\t")):
break
if raw.startswith(" "):
raw = raw[2:]
elif raw.startswith((" ", "\t")):
raw = raw[1:]
block.append(raw.rstrip())
i += 1
data.description = "\n".join(block).strip()
continue
if low in {"title", "name"}: if low in {"title", "name"}:
data.title = value data.title = value
elif low in {"date", "dates", "when"}: elif low in {"date", "dates", "when"}:
@ -543,6 +562,7 @@ def parse_data_file(path: Path | None) -> MovieData:
data.description = value data.description = value
elif key: elif key:
data.captions[key] = value data.captions[key] = value
i += 1
return data return data