feat: hide flagged scientific review captions

This commit is contained in:
2026-08-25 17:16:55 +08:00
parent fb5a4017f6
commit 257d7e1759
5 changed files with 44 additions and 6 deletions
@@ -1001,7 +1001,8 @@ def _ass_layout(manifest: dict[str, Any]) -> dict[str, int]:
def _render_ass(
manifest: dict[str, Any], translations: dict[str, str], font: str
manifest: dict[str, Any], translations: dict[str, str], font: str,
suppressed_segment_ids: set[str] | None = None,
) -> str:
font = _validate_font(font)
cue_by_id = _cue_map(manifest)
@@ -1035,6 +1036,10 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
target_language = str(manifest.get("target_language") or DEFAULT_TARGET_LANGUAGE)
dialogue: list[str] = []
for segment in _render_segments(manifest):
if suppressed_segment_ids and any(
segment_id in suppressed_segment_ids for segment_id in segment["cue_ids"]
):
continue
source_exact = _segment_source_text(segment, cue_by_id)
target_exact = normalize_target_caption(
_display_translation(manifest, segment, translations), target_language
@@ -1070,7 +1075,8 @@ def _target_srt_name(manifest: dict[str, Any]) -> str:
def _expected_outputs(
manifest: dict[str, Any], translations: dict[str, str], font: str
manifest: dict[str, Any], translations: dict[str, str], font: str,
suppressed_segment_ids: set[str] | None = None,
) -> dict[str, bytes]:
cue_by_id = _cue_map(manifest)
layout = _ass_layout(manifest)
@@ -1079,6 +1085,10 @@ def _expected_outputs(
target_entries: list[tuple[int, int, str]] = []
bilingual_entries: list[tuple[int, int, str]] = []
for segment in _render_segments(manifest):
if suppressed_segment_ids and any(
segment_id in suppressed_segment_ids for segment_id in segment["cue_ids"]
):
continue
source_exact = _segment_source_text(segment, cue_by_id)
source_chunks = wrap_layout_chunks(source_exact, layout["source_columns"])
if "".join(source_chunks) != source_exact:
@@ -1099,7 +1109,9 @@ def _expected_outputs(
"source.srt": _render_srt(source_entries).encode("utf-8"),
_target_srt_name(manifest): _render_srt(target_entries).encode("utf-8"),
"bilingual.srt": _render_srt(bilingual_entries).encode("utf-8"),
"bilingual.ass": _render_ass(manifest, translations, font).encode("utf-8"),
"bilingual.ass": _render_ass(
manifest, translations, font, suppressed_segment_ids
).encode("utf-8"),
}
@@ -1155,6 +1167,9 @@ def _scientific_review_binding(
counts = value.get("counts")
if not isinstance(counts, dict) or counts.get("total") != len(translations):
raise PipelineError("scientific review report segment count is invalid")
suppressed = value.get("suppressed_segment_ids", [])
if not isinstance(suppressed, list) or not all(isinstance(segment_id, str) for segment_id in suppressed):
raise PipelineError("scientific review suppression list is malformed")
return {
"report_path": str(review_report),
"report_sha256": _sha256_bytes(review_report.read_bytes()),
@@ -1162,6 +1177,7 @@ def _scientific_review_binding(
"human_expert_reviewed": False,
"counts": counts,
"disclosure": value.get("disclosure"),
"suppressed_segment_ids": suppressed,
}
@@ -1211,7 +1227,21 @@ def render(
scientific_review = _scientific_review_binding(
scientific_review_report, manifest_path, translations_dir, translations
)
expected = _expected_outputs(manifest, translations, font)
suppressed_cue_ids = None
if scientific_review:
suppressed_review_ids = set(scientific_review.get("suppressed_segment_ids", []))
suppressed_cue_ids = {
cue_id
for translation_segment in manifest["segments"]
if translation_segment["id"] in suppressed_review_ids
for cue_id in translation_segment["cue_ids"]
}
expected = _expected_outputs(
manifest,
translations,
font,
suppressed_cue_ids,
)
output_dir.mkdir(parents=True, exist_ok=True)
for name, data in expected.items():
_atomic_write(output_dir / name, data)