Adding fix to recover narration.json
This commit is contained in:
+25
-2
@@ -625,12 +625,35 @@ def parse_narration(
|
||||
default_filters = config.default_filters if config else {}
|
||||
|
||||
narration = {}
|
||||
_narr_video_exts = {".mov", ".mp4", ".webm", ".avi", ".mkv", ".m4v"}
|
||||
for segment_id, segment_data in data.items():
|
||||
if "source_file" not in segment_data:
|
||||
if not segment_data.get("source_file"):
|
||||
# source_file can drift out of an entry (case/sync churn between
|
||||
# machines). Recover the way import/prune/trim do: find the raw
|
||||
# recording whose stem matches the segment id, case-insensitively.
|
||||
recovered = None
|
||||
for sub in ("raw_mov", "processed"):
|
||||
sub_dir = narration_dir / sub
|
||||
if not sub_dir.is_dir():
|
||||
continue
|
||||
for f in sorted(sub_dir.iterdir()):
|
||||
if (
|
||||
f.is_file()
|
||||
and f.suffix.lower() in _narr_video_exts
|
||||
and f.stem.lower() == segment_id.lower()
|
||||
):
|
||||
recovered = f"{sub}/{f.name}"
|
||||
break
|
||||
if recovered:
|
||||
break
|
||||
if recovered is None:
|
||||
raise ParseError(
|
||||
f"Narration segment '{segment_id}' missing required field 'source_file'",
|
||||
f"Narration segment '{segment_id}' missing required field 'source_file' "
|
||||
f"and no matching recording was found in raw_mov/ or processed/. "
|
||||
f"Add a 'source_file' or run 'import' to repair narration.json.",
|
||||
narration_path,
|
||||
)
|
||||
segment_data = {**segment_data, "source_file": recovered}
|
||||
|
||||
# Resolve filter - can be a list or a string reference to default_filters
|
||||
filter_value = segment_data.get("filter", [])
|
||||
|
||||
Reference in New Issue
Block a user