Support positional data file with description metadata
This commit is contained in:
parent
dfa98d03a0
commit
37efb3cef1
1 changed files with 38 additions and 23 deletions
61
movmaker.py
61
movmaker.py
|
|
@ -47,6 +47,7 @@ class MovieData:
|
|||
title: str = ""
|
||||
date: str = ""
|
||||
place: str = ""
|
||||
description: str = ""
|
||||
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():
|
||||
return MovieData(captions={})
|
||||
|
||||
lines = [line.strip() for line in path.read_text(encoding="utf-8", errors="replace").splitlines()]
|
||||
lines = [line for line in lines if line and not line.startswith("#")]
|
||||
|
||||
raw_lines = [line.rstrip() for line in path.read_text(encoding="utf-8", errors="replace").splitlines()]
|
||||
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:
|
||||
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 Path(key).suffix.lower() in IMAGE_EXTS | VIDEO_EXTS:
|
||||
if key:
|
||||
data.captions[key] = value
|
||||
else:
|
||||
plain.append(line)
|
||||
continue
|
||||
if in_description:
|
||||
description.append(line)
|
||||
else:
|
||||
plain.append(line)
|
||||
header.append(line)
|
||||
|
||||
# Simple mode: first three non-key lines are title/location/date.
|
||||
if plain:
|
||||
data.title = data.title or plain[0]
|
||||
if len(plain) > 1:
|
||||
data.place = data.place or plain[1]
|
||||
if len(plain) > 2:
|
||||
data.date = data.date or plain[2]
|
||||
# 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()
|
||||
|
||||
return data
|
||||
|
||||
|
|
@ -888,6 +901,8 @@ def build_video(
|
|||
"location": data.place,
|
||||
"place": data.place,
|
||||
"com.apple.quicktime.location.name": data.place,
|
||||
"description": data.description,
|
||||
"synopsis": data.description,
|
||||
"artist": "Bubulescu.Org",
|
||||
"comment": "Created with movmaker",
|
||||
"creation_time": creation_date.isoformat(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue