From 86cb85b56d94b498345171cbcc1c3ed310ac601c Mon Sep 17 00:00:00 2001 From: hbrain Date: Mon, 25 May 2026 18:51:49 +0000 Subject: [PATCH] Parse all data file entries as key-value --- movmaker.py | 57 +++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/movmaker.py b/movmaker.py index 865fd6c..4c8f029 100755 --- a/movmaker.py +++ b/movmaker.py @@ -522,50 +522,25 @@ def parse_data_file(path: Path | None) -> MovieData: if not path or not path.exists(): return MovieData(captions={}) - raw_lines = [line.rstrip() for line in path.read_text(encoding="utf-8", errors="replace").splitlines()] data = MovieData(captions={}) - header: list[str] = [] - description: list[str] = [] - in_description = False - - for raw in raw_lines: + for raw in path.read_text(encoding="utf-8", errors="replace").splitlines(): line = raw.strip() - if line.startswith("#"): + if not line or line.startswith("#") or ":" not in line: continue - if not line: - if header or in_description: - in_description = True - if description: - description.append("") - continue - if ":" in line: - key, value = line.split(":", 1) - key = key.strip() - value = value.strip() - if key: - data.captions[key] = value - continue - if in_description: - description.append(line) - else: - header.append(line) - - # New simple mode: - # title - # location - # date - # - # description - # - # 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() + key, value = line.split(":", 1) + key = key.strip() + value = value.strip() + low = key.lower() + 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 low in {"description", "desc", "synopsis"}: + data.description = value + elif key: + data.captions[key] = value return data