#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""11 试片旁白准备：解析 11_cat_script.md（sNN: 文本 格式）→ synth/subs。
不拼片、不传。字幕严格照讲稿原文（超18字段也保留，花酱排镜头时自行处理）。
按 11_cat_pronunciation_precheck.md：s06/s16 逗号→句号（仅录音输入，字幕不动）。
"""
import io, json, os, re

HERE = r"D:/Download/muse_exchange"
SRC = os.path.join(HERE, "11_cat_script.md")
lines = io.open(SRC, encoding="utf-8").read().splitlines()
start = lines.index("## 讲稿（25 段）") + 1
body = []
for l in lines[start:]:
    if l.startswith("## "):
        break
    m = re.match(r"^s(\d+):\s*(.*)$", l.strip())
    if m:
        body.append((int(m.group(1)), m.group(2)))
assert len(body) == 25 and [i for i, _ in body] == list(range(1, 26)), "段号不连续"

# 录音输入改写：按预检单 s06/s16 逗号→句号；字幕不动
TTS_FIX = {
    6: "猫一离地。耳朵里的平衡器马上知道哪边是下。",
    16: "一九八七年。纽约一家动物医院统计了一百三十二只坠楼的猫。",
}
synth = []
for i, t in body:
    x = TTS_FIX.get(i, t)
    assert '"' not in x and "“" not in x and "”" not in x, "引号"
    assert "——" not in x, "破折号"
    assert not re.search(r"[0-9]", x), "阿拉伯数字 s%02d" % i
    synth.append(x)

io.open(os.path.join(HERE, "sci11_synth.txt"), "w", encoding="utf-8", newline="\n").write("\n".join(synth) + "\n")
json.dump({"episode": "科学·11", "count": 25,
           "subs": [{"idx": i, "text": t} for i, t in body]},
          io.open(os.path.join(HERE, "sci11_subs.json"), "w", encoding="utf-8"),
          ensure_ascii=False, indent=2)
print("OK synth=25 lines subs=25")
for i in (6, 16):
    print("  FIX s%02d: %s" % (i, synth[i - 1]))
